]> wirehaze git hosting - stm32f411ceu6.git/commitdiff

wirehaze git hosting

blink blink
authorphfr24 <phfr24@inf.ufpr.br>
Sun, 21 Jun 2026 04:07:39 +0000 (01:07 -0300)
committerphfr24 <phfr24@inf.ufpr.br>
Sun, 21 Jun 2026 04:07:39 +0000 (01:07 -0300)
.gitignore [new file with mode: 0644]
kernel.c [new file with mode: 0644]
kernel.ld [new file with mode: 0644]
notes.txt

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..f0e8432
--- /dev/null
@@ -0,0 +1,4 @@
+kernel.elf
+kernel.bin
+*.o
+.*.swp
diff --git a/kernel.c b/kernel.c
new file mode 100644 (file)
index 0000000..28d576d
--- /dev/null
+++ b/kernel.c
@@ -0,0 +1,53 @@
+extern unsigned int _sram_end;
+extern unsigned int _data_vma_start;
+extern unsigned int _data_vma_end;
+extern unsigned int _data_lma_start;
+extern unsigned int _bss_vma_start;
+extern unsigned int _bss_vma_end;
+
+#define RCC_AHB1 ((volatile unsigned int * const) 0x40023830)
+#define GPIOC_MODER ((volatile unsigned int * const) 0x40020800)
+#define GPIOC_ODR ((volatile unsigned int * const) 0x40020814)
+
+static void
+delay (void)
+{
+  volatile unsigned int i;
+  for (i = 0; i < 500000; i++);
+}
+
+static void
+reset_handler (void)
+{
+  unsigned int *src, *dst;
+
+  /* relocate .data to sram  */
+  src = &_data_lma_start;
+  dst = &_data_vma_start;
+
+  while (dst < &_data_vma_end)
+    *(dst++) = *(src++);
+
+  /* initialize .bss  */
+  dst = &_bss_vma_start;
+
+  while (dst < &_bss_vma_end)
+    *(dst++) = 0;
+
+  /* blink blink  */
+  *RCC_AHB1 |= (1u << 2);
+  *GPIOC_MODER &= ~(3u << 26);
+  *GPIOC_MODER |= (1u << 26);
+
+  while (1)
+    {
+      *GPIOC_ODR ^= (1u << 13);
+      delay ();
+    }
+}
+
+__attribute__ ((section (".vtbl"), used))
+static unsigned long const vector_table[] = {
+  (unsigned long) &_sram_end,
+  (unsigned long) reset_handler,
+};
diff --git a/kernel.ld b/kernel.ld
new file mode 100644 (file)
index 0000000..92a94c4
--- /dev/null
+++ b/kernel.ld
@@ -0,0 +1,49 @@
+MEMORY
+{
+  flash (rx) : ORIGIN = 0x08000000, LENGTH = 512K
+  sram (rw) : ORIGIN = 0x20000000, LENGTH = 128K
+}
+
+_flash_start = ORIGIN(flash);
+_flash_end = ORIGIN(flash) + LENGTH(flash);
+
+_sram_start = ORIGIN(sram);
+_sram_end = ORIGIN(sram) + LENGTH(sram);
+
+SECTIONS
+{
+  .vtbl :
+    {
+      *(.vtbl)
+      . = 0x400;
+    } >flash
+  .text :
+    {
+      *(.text*)
+    } >flash
+  .rodata :
+    {
+      . = ALIGN(4);
+      *(.rodata*)
+      . = ALIGN(4);
+    } >flash
+  .data :
+    {
+      . = ALIGN(4);
+      *(.data*)
+      . = ALIGN(4);
+    } >sram AT>flash
+  .bss :
+    {
+      . = ALIGN(4);
+      *(.bss*)
+      . = ALIGN(4);
+    } >sram
+}
+
+_data_vma_start = ADDR(.data);
+_data_vma_end = ADDR(.data) + SIZEOF(.data);
+_data_lma_start = LOADADDR(.data);
+
+_bss_vma_start = ADDR(.bss);
+_bss_vma_end = ADDR(.bss) + SIZEOF(.bss);
index d9140c0267acd9dc9e407bfe7a4602a70a705244..a6cd67eec53ee8e76e5745fe8753344ede8b05b7 100644 (file)
--- a/notes.txt
+++ b/notes.txt
@@ -1,3 +1 @@
-[ ] linker script
 [ ] test -Os / -Oz optimization flags
-[ ] deep dive into GNU toolkit documentation