2009-04-23 11:14 AM
RTOS port and dual stacks
2011-05-17 04:10 AM
I am working on porting an RTOS to this ARM processor. I've got it working but it is not making use of the dual stack feature that the ARM offers, as the processor I am porting from does not use a dual stack. I simply am using the main stack pointer for everything. The manuals that I have read only hint at the implementation and benefits of the dual stack system (main & process stacks). Does anyone know where I can get more information on the benefits or how to implement a system that makes use of both stacks?
2011-05-17 04:10 AM
Hello, the use of the dedicated stack for exceptions is very important in order to save RAM IMO. Without a dedicated stack you would have to reserve enough space for interrupts processing on each thread/task stack.
The STM32 allows to precess nested interrupts so the RAM required for each thread would be in the order of hundreds bytes for each thread depending on how many priority level you use. Much better have a separated stack for exceptions processing only. Giovanni --- ChibiOS/RT2011-05-17 04:10 AM
That makes sense about the RAM usage savings.
I think I may have found what I was looking for at freertos.org. They have open source code and a port for this STM32F processor. I can look/step through that source code and hopefully figure out how they implement the dual stack system.2011-05-17 04:10 AM
I use freeRTOS w/ the STM32 as well, I wasn't aware of the dual stack support in it though. Let me know what you find out.
2011-05-17 04:10 AM
yeah, ok...
I was confused how to use the dual stack system because with the rtos I use, there is not an exception stack. In an exception everything is pushed onto the current thread's stack. Then the task swap happens at the end of the ISR but before returning from the interrupt. So, I didn't understand how to use the exception stack because if the task swap happens before returning from the interrupt then you have a bunch of stuff still left on the exception stack with no way to recover it. So, stepping through the freertos I was able to see that when a task swap is requested inside an exception they set PendSV. That way, the current exception (or exceptions, if nested) will return thus emptying the exception stack completely. Then the PendSV Handler is serviced and does a task swap. at least, i think that's how it works. So, yes, the freertos port makes use of the main and process stacks.