cancel
Showing results for 
Search instead for 
Did you mean: 

custom bootloader problem on STM32F405

ZTale.1
Associate II

hello

i am working on a custom bootloader or STM32F405.

the Flash process is done correctly by the Bootloader, i checked the content of the flash.

the problem happens when the bootloader jumps to the application firmware which is located at adress 0x0800C000, the program goes to the Hard_fault handler function:

0693W00000aHet4QAC.jpg 

this is what i am using to jump from the bootloader :

0693W00000aHetPQAS.jpg 

thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ZTale.1
Associate II

hi

Finally i found the problem , the last byte of the BIN file was not programmed as shown in picture :

0693W00000aHf6VQAS.jpg 

it is a stupid error, as i checked the content of the flash.

thanks a lot for the help Tesla and Gbm

View solution in original post

10 REPLIES 10

Step the transition

Know what numbers it is loading

Make sure the SP / PC aren't something unworkable like 0xFFFFFFFF

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ZTale.1
Associate II

hi thanks Tesla,

this is the last instruction before doing the jump to main :

0693W00000aHeyJQAS.jpg 

this is also the flas memory part so you can see the R0 adress content :

0693W00000aHeyOQAS.jpg

gbm
Lead III
  1. Check the content of two words at 0x0800c000.
  2. Make sure that VTOR is loaded with the app base address 0x0800c000 by the bootloader or your app.
  3. The cast in line 224 is suspicious. It's safer to skip it - it's not really needed.

This isn't the main() routine, if you follow this it will go to the scatter loader to initialize the BSS (copying/clearing RAM), and finally enter main().

You should be able to breakpoint in main()

The HardFault Handler should be able to unpack the processor state and instruction that faults.

See previous examples.

If it is calling the HardFault Handler on the loader side, it suggests SCB->VTOR is not set properly in SystemInit(), SCB->VTOR should be set to 0x0800C000 now.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ZTale.1
Associate II

hi GBM, thanks or the answer

i checkd VTOR and it is loaded with 0x0800c000.

this is the content of 0x0800c000 in flash memory :

0693W00000aHezvQAC.jpg

the hardfault handler is called on the application side.

gbm
Lead III

Try to replace lines 224..226 with:

      ( (void (*)(void)) *(uint32_t *)(APP_BASE + 4) )();

ZTale.1
Associate II

i replaced the lines 224..226  and same problem.

The control transfer seems to be occurring, Hard faulting deeper into the execution of the app, supposedly before main()

The the clocks are already up, I'd probably not repeat that in the app.

Watch for other interrupting sources the boot loader has running, ie SysTick, TIM, USART as these will now point to uninitialized structures on the app side, and the scatter load will wipe out whatever the loader had set up in RAM.

https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..