cancel
Showing results for 
Search instead for 
Did you mean: 

where to find STM32 context switch code

dieter 123
Associate III
Posted on June 16, 2017 at 15:24

Hi

when an interrupt kicks in, th current context (core registers , pc and so on are saved). Where in a cube generated project, would I find the context save and restore part? Which registers need to be saved? How many cycles does it need?

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on June 16, 2017 at 16:43

The core saves the registers it needs and this matches the ABI for calling C functions, so not special handling is required to use C functions as interrupt handlers. The value of LR passed to the function, is a magic value which upon return tells the core to recover the original context.

Nominally PC, XPSR, R0, R1, R2, R3, R12 and LR

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2
Posted on June 16, 2017 at 16:39

The core does this, review documentation for the Cortex-Mx part in question. Either the ARM TRM or books by Joseph Yiu

https://community.arm.com/processors/b/blog/posts/a-beginner-s-guide-on-interrupt-latency---and-interrupt-latency-of-the-arm-cortex--m-processors

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 16, 2017 at 16:43

The core saves the registers it needs and this matches the ABI for calling C functions, so not special handling is required to use C functions as interrupt handlers. The value of LR passed to the function, is a magic value which upon return tells the core to recover the original context.

Nominally PC, XPSR, R0, R1, R2, R3, R12 and LR

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..