AnsweredAssumed Answered

Developing custom boot-loader for STM32F103

Question asked by maddox.rich on Sep 8, 2015
Latest reply on Sep 9, 2015 by maddox.rich
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 handler
Reset_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
                ENDP
Application     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       .
                ENDP
HardFault_Handler\
                PROC
                EXPORT  HardFault_Handler          [WEAK]
                B       Boot_Loader
                ENDP

The 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?
Thanks
rich

Outcomes