The ARM Cortex specification includes ‘SysTick’ (System Tick Timer), a dedicated system timer that is intended to be used as a time base for an RTOS. While, technically, it would be possible to use any periodic interrupt timer, I’m also using 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 use it directly?
So I decided to introduce an extra property:
If SysTick is set to "yes" (default), it directly uses the SysTick of the ARM core, and there's 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:
- No need 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 you run 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 anymore. In that case, you can simply remove it by hand from the source file.
Stack Overflow Checking
FreeRTOS has a feature to check for a stack overflow at the time of a context switch which is incredibly helpful. Still, sometimes I want to disable this for performance. So far I was able to do this by 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 use 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 for low power tickless idle mode to use a different timer than SysTick. So there is still room for improvement.