Skip to content

Development

Lorenzo Pistone edited this page Jan 27, 2025 · 1 revision

The firmware uses the Arduino framework, but it also uses FreeRTOS, as provided by the Arduino platform itself for this board. Here I list a couple of important implementation details that should be known to the developers of this project.

Time slicing with FreeRTOS on Arduino

Arduino gives us a FreeRTOS environment, but critically, the time slicing feature (configUSE_TIME_SLICING=1) is turned off. This is most likely because the Arduino people did not want their users to face the significant complexities of a real multitasking environment with preemption, since the whole Arduino platform is in origin single-threaded.

This project however is quite complex in the number of moving parts (sensors, wifi, lcd, an user interface over a constrained LCD...). So it was an early decision in the development to configure and use time slicing via FreeRTOS.

Framework and library compatibility with time slicing has been confirmed with all the relevant interfaces and APIs used. Additional notes:

  • the Arduino framework, as well as the standard C/C++ library, has been made preemption-safe for the scope of the project:
    • all malloc/new functionality is serialized
    • all global objects (such as the Serial object, or wifi/modem related objects) are made safe by wrapping them in a FreeRTOS per-object mutex
    • all assert functions are implemented as backtrace logging on the serial console; a failed assert in a FreeRTOS task does not hang the entire board, but just that single task
  • all serial communication is safe for preemption
  • the wifi bridge library, being essentially serial, is safe
  • the capacitive buttons library is inherently safe, as all the work is done in hardware and communication happens over interrupts

Known issues with FreeRTOS

The port of FreeRTOS to the board is broken in regard to the tickless idle functionality. It is not clear why the Arduino folks used a custom FreeRTOS implementation rather than the upstream one. However, if one enables tickless idle, then sleep timers appear to run ten times faster (likely due to spurious wake ups due to other interfering interrupts from the graphics library). As of today there is no solution but to disable the tickless idle.

There is no way to reduce the heap space of the Arduino framework. That currently holds 8KB of RAM, which is a lot. All FreeRTOS allocations are static, and no FreeRTOS heap is allocated. Stack overflow debugging is enabled.

Clone this wiki locally