Skip to main content
dieter 123
Associate III
June 16, 2017
Solved

where to find STM32 context switch code

  • June 16, 2017
  • 2 replies
  • 1121 views
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?

    This topic has been closed for replies.
    Best answer by Tesla DeLorean
    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

    2 replies

    Tesla DeLorean
    Guru
    June 16, 2017
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    June 16, 2017
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..