I’ve narrowed it down a bit further. To me, it seems like one of the “dsb” calls clears the register. I’ve modified the code like this, disabling interrupt processing after sleeping:
using this code, “test5258” contains the value “0” → cleared. When i patch the hex file and replace the last “isb” call with a 4 byte “nop”, the register contains the correct value.
At this point, I don’t think this is a FreeRTOS problem. I think I will post a question in the arm community forum…
Since the issue is related to r7 register and based on:
it makes wonder if frame pointer is at play here. Can you please check if you are using -fno-omit-frame-pointer compiler flag and somehow r7 is getting corrupted between function calls.
Probably a long shot, but there is an STM32 erratum “Wrong instruction fetches from flash memory upon wakeup from Sleep or Stop mode when debug in low-power mode is enabled” that I ran into a while back with symptoms just like yours. The MCU was executing wrong instructions in the first 8 machine instructions after waking from sleep. It might affect your MCU too. Which specific MCU are you using? Feel free to PM me.
Thanks, had a look at this. It’s for STM32F4xx, and noted “The issue affects only debug mode and has no effect on real applications.”. We’re using a STM32F302 and the problem also occurs without the debugger connected, so I would rule this out.