2015-09-08 01:27 PM
I am developing a custom bootloader for the STM32F103. The general plan is that there are two Micro-vision projects - one for the application (0x08040000) and one for the boot-loader (0x08000000). In general this concept works when there is a valid application in flash. My problem is when there is no application in flash...
My idea was to use the hard-fault exception as a clue that there is no code loaded to the application space. On boot, the bootloader simply jumps to the application start. If there is a hard-fault, simply jump back to the bootloader...eg; Reset handlerReset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT __main IMPORT SystemInit ;rrm test of branching to application code vs bootloader code LDR R0, =0x2000FFFC ;load R0 with the address at shared memory LDR R1, =0x00000001 ;key to run bootloader LDR R2, [R0, #0] ;load R2 with the contents of the address in R0 STR R0, [R0, #0] ;Invalidate CMP R2, R1 BEQ Boot_Loader ;Application signals to run Bootloader B Application ;Normal operation - just jump to app Boot_Loader LDR R0, =0x08000000 LDR SP,[R0, #0] LDR R0,[R0, #4] LDR R0, =SystemInit BLX R0 LDR R0, =__main BX R0 ENDPApplication PROC ;jump to application LDR R0, =0x08040000 ; Application Base LDR SP,[R0, #0] LDR R0,[R0, #4] BX R0 ENDP;rrm end test; Dummy Exception Handlers (infinite loops which can be modified)NMI_Handler PROC EXPORT NMI_Handler [WEAK] B . ENDPHardFault_Handler\ PROC EXPORT HardFault_Handler [WEAK] B Boot_Loader ENDPThe problem I have run into is that when the hard-fault occurs, the bootloader runs but interrupts do not get executed. The vector table offset is correct and I can see with the debugger that they are enabled and pending but don't execute...???Clearly there is something that the hard-fault is doing to the system and I need to reset something to get back to where I was...I have verified that if I simply go directly to the bootloader without attempting an application jump, the bootloader runs correctly (interrupts work)Any ideas?Thanksrich2015-09-08 01:55 PM
Perhaps it's because the processor is running in a different context? It's faulted and you need to unravel that, not just jump to some other code. If you just want it to Reset, using NVIC_SystemReset() would seem like a more viable path.
2015-09-09 07:36 AM