From: phfr24 Date: Sun, 21 Jun 2026 04:07:39 +0000 (-0300) Subject: blink blink X-Git-Url: https://git.wirehaze.ovh/stm32f411ceu6.git/commitdiff_plain/ca2267d42b6d9e1c8b147aa7685ed91592bfd964?ds=sidebyside blink blink --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0e8432 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +kernel.elf +kernel.bin +*.o +.*.swp diff --git a/kernel.c b/kernel.c new file mode 100644 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 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); diff --git a/notes.txt b/notes.txt index d9140c0..a6cd67e 100644 --- a/notes.txt +++ b/notes.txt @@ -1,3 +1 @@ -[ ] linker script [ ] test -Os / -Oz optimization flags -[ ] deep dive into GNU toolkit documentation