Home grown OS task function call failures
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
- Labels:
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-09 9:05 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-09 1:08 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-10-11 9:02 AM
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.
