cancel
Showing results for 
Search instead for 
Did you mean: 

R4 register corruption in STM32L562(ARM Cortex M33) when switching from secure to non secure mode in STMCubeIDE

SM.181
Associate

On switching from secure to non-secure mode using a function pointer (with the cmse_nonsecure_call attribute) in STM32L562(ARM Cortex M33), general purpose registers R0-R4, R12 and floating point registers S0-S15 are not restored when back in secure mode.

There is an explanation for R0-R3, R12 and S0-S15 as they are scratch registers. But R4 should recover its value once back in secure mode, but is getting corrupted. Does anyone have an explanation for this please?

Below is the assembler code for the switch from secure to non secure mode.

0693W00000VObetQAD.jpgThe IDE used in STM32CubeIDE v1.8.0 and compiler used is gcc-arm-none-eabi-10-2020-q4-major-win32.

2 REPLIES 2
Jocelyn RICARD
ST Employee

Hello @Community member​ ,

I checked with my current version of CubeIDE (1.10.1) using toolchain GNU Tools for STM32 10.3-2021.10.

I get a code similar to what you have, but the function implementing this call which is a callback in my case puts R4 on the stack and restores it on return.

Isn't is done this way in your case?

Best regards

Jocelyn

SM.181
Associate

Hello,

I resolved the issue by calling the non secure function from another secure function and not directly from the function whose registers which I wanted to be retained. Bit of a workaround, but it worked.