cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L162 not remapping SystemMemory to 0 during bootloader reset

3FTI
Associate II
Posted on October 27, 2016 at 15:19

I have implemented the following code I found on this forum to execute the bootloader with register addresses changed to be for the STM32L162 part. I am developing with IAR tools.

PUBWEAK Reboot_DFU
SECTION .text:CODE:REORDER:NOROOT(2)
Reboot_DFU
LDR R0, =0x40023820 ; RCC_APB2ENR, enable APB2 clock so we can write SYSCFG_MEMRMP register
LDR R1, =0x00000001 ; set Bit 0 SYSCFGEN: System configuration controller clock enable
STR R1, [R0, #0]
LDR R0, =0x40010000 ; SYSCFG_MEMRMP
LDR R1, =0x00000001 ; remap ROM at zero
STR R1, [R0, #0]
LDR R0, =0x00000000 ; should be System Memory since we mapped it to 0
LDR SP, [R0, #0] ; assign main stack pointer
LDR R0, [R0, #4] ; load bootloader address
BX R0

System Memory start address is 0x1FF00000 which I did try hardcoding in to load the SP and bootloader address. When I did it this way I could see the above code being executed, the SP was correct, the bootloader address was correctly loaded but the bootloader didn't execute, instead it simply booted the application. I changed the code to the above where I load the SP and bootloader address from location 0x00000000 which should be remapped to System Memory but when I checked the SP it was for the application (Flash memory). So it appears by the point I am ready to jump to the bootloader the remap of System memory to 0x00000000 has not taken affect although I can see by checkging the register contents of SYSCFG_MEMRMP that MEM_MODE is set to 0x Am I missing any setup steps?
1 REPLY 1
Posted on October 27, 2016 at 17:13

Not a part I'm using, you're in a better position to debug/evaluate, does the mapping work outside the debugger?

Try

LDR R0, =0x1FF00000 ; System Memory
LDR SP, [R0, #0] ; assign main stack pointer
LDR R0, [R0, #4] ; load bootloader address

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