cancel
Showing results for 
Search instead for 
Did you mean: 

Home grown OS task function call failures

JoeJoe
Associate II

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.

4 REPLIES 4

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

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

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.

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

I had not tested it in release mode before this time. It is working great in both modes now. I set the optimizer to -Og. Funny, the manual seems to contradict this. Anyway, moving on. Thanks.