2024-10-08 10:36 AM
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.
2024-10-08 11:11 AM - edited 2024-10-08 11:13 AM
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