2023-02-25 06:53 AM
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:
this is what i am using to jump from the bootloader :
thanks.
Solved! Go to Solution.
2023-02-25 12:04 PM
hi
Finally i found the problem , the last byte of the BIN file was not programmed as shown in picture :
it is a stupid error, as i checked the content of the flash.
thanks a lot for the help Tesla and Gbm
2023-02-25 08:03 AM
Step the transition
Know what numbers it is loading
Make sure the SP / PC aren't something unworkable like 0xFFFFFFFF
2023-02-25 08:59 AM
hi thanks Tesla,
this is the last instruction before doing the jump to main :
this is also the flas memory part so you can see the R0 adress content :
2023-02-25 09:11 AM
2023-02-25 09:16 AM
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.
2023-02-25 09:22 AM
hi GBM, thanks or the answer
i checkd VTOR and it is loaded with 0x0800c000.
this is the content of 0x0800c000 in flash memory :
2023-02-25 09:34 AM
the hardfault handler is called on the application side.
2023-02-25 10:20 AM
Try to replace lines 224..226 with:
( (void (*)(void)) *(uint32_t *)(APP_BASE + 4) )();
2023-02-25 10:37 AM
i replaced the lines 224..226 and same problem.
2023-02-25 11:25 AM
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