Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32


Change application on Reset !

Hi !


I have 2 binary files for 2 different function/application, in bank 1 and 2 (of my STM32L072CZ). On reset I want to change from bank 1 to bank 2 (so change to Application 2). I see that I need to use a magic value in ram and have the reset handler in the loader recognize that and immediately transfer control to the application !

So I add in my .c :

‘’__ATEerror_t AT_Switch(const char *param)
{
AT_PRINTF(“SWITCH”);

  • ((unsigned long *)0x20000270) = 0xFEED0002; // Address RAM STM32L072

NVIC_SystemReset(); // Start APP2
return AT_OK;
}’’

Store a value in RAM (RAM is not cleared over a reset) and call a soft reset !

Does anyone know how to modify the startup .s file in order to make this happen ?

For the moment, I do this but without success :

Reset_Handler:
ldr r0, =_estack
ldr r4, =0x20000000 //load value stored in .c
ldr r5, r4, #0 //charge la valeur a ladresse r4 dans r5 sans offset
str r4, r4, #0 //invalidate
ldr r6, =0xFEED0001 //to compare
ldr r7, =0x08019F40 //APP2_FLASH

mov sp, r0 //set stack pointer
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0

cmp r5, r6 //compare value from .c (store in RAM) to r7
mov sp, r7 //if magic value in RAM = r7, we change sp to APP2_FLASH



b LoopCopyDataInit


Regards

Tunisia

Hi,

Before giving the answer I need to know if each of your applications have its Reset Handler ?

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

Tunisia

In that case, this could be a solution :

SwapApp:
  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 */
  ........

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..

Tunisia

I’ve tested the solution without issues.
So, I will share with you a complete example tomorrow :-)

Thanks Tarek because I didn’t see the issue here..
Tunisia

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 ?

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.

Tunisia

In that case :

SwapApp:
  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 */
  ........

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




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..

Tunisia

yes, each application should int the sp in its own reset Handler
concerning the pc, the jump is granted by bx instruction


I think I miss something with sp... When you said set sp in each reset handler, I’m not sure witch value I have to put in sp !

For the moment in App1 sp is set to 0x20005000 : end of RAM

Not sure to understand the purpose of sp (gonna read some documentation about it (!)