cancel
Showing results for 
Search instead for 
Did you mean: 

problem with startup on stm32f407

avihay eini
Associate
Posted on June 13, 2017 at 14:46

very weird problem ive got here.

im working on a big project which was passed over to me , so im quite new in this field and still studying the project as well. the programs runs, with no problems. i added a function that playes .wav files which are stored as a buffer on flash memory.

when i debug with optimizition level 0, the program crashed to Hard_fault_hendler on startup, it doesnt reach my main func,if i comment out the new function (somewhere in the code) it runs well. but on opt-1,-2,-3 it runs and plays the file well (with the new funtion).

ive checked for memory issues , got enoght to go around!

dont know if that matters but my code runs on CCM memory as RAM memory is saved for buffers allocations.

so, what could the level of optimiztion change in the startup funcionality?

what vlaues can i check?

ive been compering .map file for two days trying to figure out what changed.

im reading the SP register and i can see the line which led me to Hard_fault_hendler

and its found on the 'system_stm32f4xx.c' file from the last line of 'void System_init(void) function.

please try to direct me on this one!

thanks!

#system_stm32f #stm32-startup #sram-ccm #hard-fault-exception #stm-32f407
3 REPLIES 3
Posted on June 13, 2017 at 16:41

> So, what could the level of optimiztion change in the startup funcionality?

Doesn't the nonoptimized code run out of memory? What is the initial value of stack pointer?

> ive been compering .map file for two days trying to figure out what changed.

And what did you find?

> and its found on the 'system_stm32f4xx.c' file from the last line of 'void System_init(void) function.

And what is on that line?

JW

Posted on June 13, 2017 at 17:43

hey thanks for the quick replay!

1. no, i do not exceed the memory size at all regions. as for the initial sp, im not sure im reading it correctly .. from the map file i found this:

opt0:

__initial_sp                             0x10009c00   Data           0  startup_stm32f4xx.o(STACK)

opt-1:

__initial_sp                             0x100098a0   Data           0  startup_stm32f4xx.o(STACK)

2. cant point my finger at any specific finding, i can see how the optimization level saves space, but compering 0 to -1 doesnt save that much.  one thing the  might mean somthing is the 0x00000000 region:

opt 0:

./clib/../cmprslib/zerorunl2.c 0x00000000 Number 0 __dczerorl2.o ABSOLUTE

../clib/microlib/division.c 0x00000000 Number 0 uldiv.o ABSOLUTE

../clib/microlib/division.c 0x00000000 Number 0 uidiv.o ABSOLUTE

../clib/microlib/errno.c 0x00000000 Number 0 errno.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry11b.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry8b.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry2.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry9a.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry9b.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry11a.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry10a.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry10b.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry7a.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry7b.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry5.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry8a.o ABSOLUTE

opt -1:

../clib/../cmprslib/zerorunl2.c 0x00000000 Number 0 __dczerorl2.o ABSOLUTE

../clib/microlib/division.c 0x00000000 Number 0 uidiv.o ABSOLUTE

../clib/microlib/division.c 0x00000000 Number 0 uldiv.o ABSOLUTE

../clib/microlib/errno.c 0x00000000 Number 0 errno.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry7b.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry10b.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry10a.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry5.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry9b.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry2.o ABSOLUTE

../clib/microlib/init/entry.s 0x00000000 Number 0 entry7a.o ABSOLUTE

could the 'entry_x_b.o' files tell me anything?

3. the address i get when watching the SP when i reach the hard fault exception is of this line:

' SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ '

found in 'SystemInit function in 'system_stm32f4xx.c' file.

which is the last line on this function, and i can see that 'SCB->VTOR' gets its value, the program reaches excetion as it exits this func.

i will mentions one more thing , on a previous version of this project (before i got it, and made several changes) this specific function works and the program doesnt crash with opt0.

one change ive made is to move the program to CCM only. so i did it on the previous version and it didnt crash. dont know if that info helps....

thanks again.

Posted on June 14, 2017 at 10:17

3. the address i get when watching the SP when i reach the hard fault exception is of this line:

' SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ '

found in 'SystemInit function in 'system_stm32f4xx.c' file.

Whatever your toolchain/IDE is, it would be helpful to switch to assembly/mixed display, and note the assembler instruction it fails at, and the register contents.