diff --git a/Makefile b/Makefile index d4cdbb9d9..3f05a234b 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ test: test.elf $(GDB) -x test/gdb_script.gdb test.elf test.elf: $(objs) test/runner.o - @$(LD) -T boot/stm32f429_flash.ld $(objs) test/runner.o -o $@ + @$(LD) -T boot/stm32f429.ld $(objs) test/runner.o -o $@ boot.hex: boot.elf @echo "OBJCOPY $@" @@ -33,7 +33,7 @@ boot.bin: boot.elf boot.elf: $(objs) src/freertos_blinky.o @echo "LD $@" - @$(LD) -T boot/stm32f429_flash.ld $(objs) src/freertos_blinky.o -o $@ + @$(LD) -T boot/stm32f429.ld $(objs) src/freertos_blinky.o -o $@ %.o: %.c @echo "CC $@" diff --git a/boot/crt0.c b/boot/crt0.c index d98d136aa..7dfbd0250 100644 --- a/boot/crt0.c +++ b/boot/crt0.c @@ -7,6 +7,8 @@ extern const void * _data_section_start_ram; extern const void * _data_section_end_ram; extern const void * _bss_section_start_ram; extern const void * _bss_section_end_ram; +extern const void * _stack_start; +extern const void * _stack_end; void _start(void); @@ -24,7 +26,7 @@ typedef void(*ISR)(void); ISR InitialisationVector[INITIALISATION_VECTOR_SIZE] __attribute__((section(".isr_vector_table"))) = { - 0x2001FFF0, //FIXME: This is the stack pointer! + (ISR)&_stack_start, _start, 0, 0, diff --git a/boot/stm32f429_flash.ld b/boot/stm32f429.ld similarity index 88% rename from boot/stm32f429_flash.ld rename to boot/stm32f429.ld index 15c437b34..b3015f60e 100644 --- a/boot/stm32f429_flash.ld +++ b/boot/stm32f429.ld @@ -10,8 +10,11 @@ * to be stored in Flash. */ MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 192K - CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 64K + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 192K + /* We're splitting the CCM in two, this way we're sure nothing will use the + * stack space. */ + CCM (rwx) : ORIGIN = 0x10000000, LENGTH = 60K + CCM_STACK (rw) : ORIGIN = 0x1000F000, LENGTH = 4K } SECTIONS { @@ -33,7 +36,6 @@ SECTIONS { *(.isr_vector_table) } >FLASH - .text : { . = ALIGN(4); *(.text) @@ -76,4 +78,12 @@ SECTIONS { *(.bss) _bss_section_end_ram = .; } >RAM + + .ccm : { + . = ALIGN(8); + _stack_end = .; + . = . + LENGTH(CCM_STACK) - 8; + . = ALIGN(8); + _stack_start = .; + } >CCM_STACK }