Change application on Reset ! Posted by thomasfuture on 2018-05-28 14:04 Hi Tarek, Yes, each applications have its Reset Handler, but maybe this is not the way to do this, if you can help me on this it's will be cool. Regards
Posted by tarek bouchkati on 2018-05-28 14:12 In that case, this could be a solution : Copy to clipboardSwapApp: ldr r0, =0x08019F40 bx r0 Reset_Handler: /* boot swap management */ ldr r0, =0x20000270 ldr r1, =0xFEED0001 ldr r2, [r0] cmp r1, r2 bne SwapApp /* end of boot swap management */ ldr sp, =_estack /* set stack pointer */ ........
Posted by thomasfuture on 2018-05-28 15:26 So, if I follow what’s you saids, I don’t need to touch to SP et PC ? I try with your code, but without success, or only half ! When I do a Reset, I switch from App1 to App2 but afterthe program loop in main of App2..
Posted by tarek bouchkati on 2018-05-28 16:08 I've tested the solution without issues. So, I will share with you a complete example tomorrow 😊
Posted by tarek bouchkati on 2018-05-28 22:57 Look, while driving home, I have remembered that STM32L072CZ has dual bank boot capability, so this could be achieved by changing dynamically the the BFB2 option bit. This could be a cutting edge solution ! Back to the first one, the pb could be that we jumbed directly to the App2' main. So, could you verify that 0x08019F40 is really the App2 Reset Handler Address ?
Posted by thomasfuture on 2018-05-29 09:20 App2 address is now 0x08018000 (not 0x08019F40), and 0x08018000 it's first address of bank 1. From .map file : .text.Reset_Handler 0x08023534 0x50 Projects/SW4STM32/startup_stm32l072xx.o 0x08023534 Reset_Handler So we need to jump to 0x08023534, in order to init memory, system and go to main.
Posted by tarek bouchkati on 2018-05-29 12:40 In that case : Copy to clipboardSwapApp: ldr r0, =0x08023534 bx r0 Reset_Handler: /* boot swap management */ ldr r0, =0x20000270 ldr r1, =0xFEED0001 ldr r2, [r0] cmp r1, r2 bne SwapApp /* end of boot swap management */ ldr sp, =_estack /* set stack pointer */ ........
Posted by thomasfuture on 2018-05-29 14:03 In cortex M0+ it's not BNE but BEQ -> Suffix : EQ Flags : Z = 1 Meaning : Equal, last flag setting result was zero. From The STM32L0 Cortex-M0+ instruction set 😊 So made this : /* boot swap management */ ldr r4, =0x20000000 //load address of the value stored in .c ldrb r5, r4 //load in r5 value stored in .c ldr r6, =0xFEED0001 //to compare cmp r5, r6 //compare value from .c (store in RAM) to r6 (fixed value) beq SwapApp //if equal Reboot from App2 /* end of boot swap management */ ldr r0, =_estack mov sp, r0 /* set stack pointer */ /* Copy the data segment initializers from flash to SRAM */ movs r1, #0 b LoopCopyDataInit SwapApp: ldr r0, =0x08023534 bx r0