The ARM Cortex specification includes the ‘SysTick’ (System Tick Timer): a dedicated system timer which is intended to be used as time base for an RTOS. While technically it would be possible to use any periodic interrupt timer, I’m using as well the SysTick for my FreeRTOS ARM ports. And because Processor Expert includes a nice timer interface, I’m using the TimerUnit_LDD:
While this is great for flexibility, it has its price in efficiency. That TimerUnit_LDD adds overhead. So I want to get rid of the TimerUnit_LDD and use a more efficient way.
Direct SysTick Implementation
Instead of using the TimerUnit_LDD, I want to directly use the SysTick. As SysTick is part of the ARM core, the implementation is pretty much the same for every ARM core, so why not using it directly?
So I decided to introduce an extra property:
If that ‘SysTick’ is set to ‘yes’ (default), it directly uses the SysTick of the ARM core, and no need to configure a TimerUnit_LDD:
Inside the port, it directly accesses the SysTick hardware and is not using the TimerUnit_LDD interface.
The positive side effect is:
- Not to worry about aligning the RTOS frequency with the timer frequency.
- No need to select a free timer: it is always using the SysTick.
- Better runtime performance (no need for extra push/pop in interrupt).
- And best of all: it saves 200 bytes of FLASH and 16 bytes of RAM (ARM Cortex M0+). 🙂 🙂
💡 If running into an error message about #include “RTOSTICKLDD1.h” in Events.c, Events.h or Processor Expert: It seems that in some cases Processor Expert does not remove the include, as that file is not needed and not generated any more. In that case, you can simply remove it by hand from the source file.
Stack Overflow Checking
FreeRTOS has the feature to check for a stack overflow at the time of a context switch which is incredible helpful. Still, sometimes I want to disable this for performance. So far I was able to do this with disabling the stack overflow event:
Now it is possible to select ‘none’ directly in the properties:
And in an ARM Cortex-M0+ application with GNU gcc, this saves 52 bytes of FLASH :-).
The above changes are not very big, but making usage of FreeRTOS especially on ARM Cortex better and easier, especially with Processor Expert. What I have additionally in my mind, but not done yet is to SysTick as the performance counter: now a dedicated timer is used. And of for low power tickless idle mode to use a different timer than SysTick. So still room for improvements 🙂
Happy Ticking 🙂