Skip to main content
Visitor II
October 8, 2024
Question

Home grown OS task function call failures

  • October 8, 2024
  • 1 reply
  • 1076 views

I am writing my own context switcher. I have a couple LED blink tasks for testing. It works fine when the tasks don't call any functions. Everything is inline. But when I include some function calls in the tasks and I get a context switch while in one of these functions, upon returning from the function my SP switches from the PSP to the MSP. I am thinking it my have something to do with the pipelines. Not sure. Follow-up questions welcomed.

    This topic has been closed for replies.

    1 reply

    Graduate II
    October 8, 2024

    Sounds more like you're not pushing enough context.

    Unlikely to be a pipeline issue. There's a 99.9999% chance it's a coding issue on your side, so debug with that expectation.

    If you switch in interrupt/callback context, you'd want to be unwinding the NVIC to recover that's priority level. That unwinds via magic LR value thru a call-gate type arrangement at 0xFFFFFFFx addresses. To that end make sure you give it the right stack to work with, don't arbitrarily assume, ie check bit 2, when a magic value.

    Subroutines use LR at the first level, and also dependent on the stack state, pushing LR if they call anything

    JoeJoeAuthor
    Visitor II
    October 9, 2024

    I found the issue, I think. I am still testing. I was debugging and did not have the optimizer set to debug mode. Things are stable so far.

    Super User
    October 9, 2024

    If you mean that the code works fine in debug mode, but not in release (with higher optimization), your implementation is probably not watertight and the error may reappear sooner or later. Here is another simple scheduler implementation for comparison (not saying that that one is definitely bugfree):

    https://www.codeinsideout.com/blog/stm32/task-scheduler/

    hth

    KnarfB