R4 register corruption in STM32L562(ARM Cortex M33) when switching from secure to non secure mode in STMCubeIDE
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.
The IDE used in STM32CubeIDE v1.8.0 and compiler used is gcc-arm-none-eabi-10-2020-q4-major-win32.
