4 Benefits of Using FreeRTOS on AVR® Microcontrollers

The AVR® microcontrollers support FreeRTOS. An example made for the ATmega4809 microcontroller is available in Atmel | START (http://start.atmel.com/#examples/atmega4809/freertos). Some older examples are available from the FreeRTOS web page: http://www.freertos.org. The example in Atmel | START is ready to be used out of the box in Atmel Studio.

Using FreeRTOS with the AVR microcontroller typically consumes 2400 bytes of flash and 51 bytes of RAM plus a configurable amount of heap (stack) allocated for the tasks. The above numbers are from the START example with all but one task stripped from the application. Adding one additional task consumes additionally 22 bytes of flash, and no additional RAM as each task gets its stack allocated on the heap. Adding features like stream support, Mutex, queues, etc. will as expected consume extra flash.

There is some overhead in using FreeRTOS, but for larger software projects the benefits easily overcome this code overhead. Tasks can be re-used between applications and platforms. By working on different tasks, developers can work independently on different parts of the application. The developer does not need to worry about creating timing issues for other tasks in the same application. Also, applications can easily be expanded by simply adding a new task. In addition, FreeRTOS also offers many useful features for the developer which one normally would spend a lot of time creating for each application. E.g., buffer, stream, and queue functionality are trivial to implement in FreeRTOS.

FreeRTOS offers debugging functions like stack painting and stack overflow hooks. These capabilities are easily enabled in the FreeRTOSConfig.h file by setting configCHECK_FOR_STACK_OVERFLOW to either "1", or "2". With a setting of "1" to enable the stack overflow hook, FreeRTOS will then call the function,
void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName );
defined by the user, if the task's stack pointer goes outside the allocated area. A setting of "2" will fill the stack with a known value at the start. These tools together with the extensive debugging features offered by the AVR microcontrollers make it easy to fine-tune the tasks' memory consumption, e.g., by reading out the content of SRAM during run-time debugging. That way, it is easy to pinpoint stack overflow issues in the application that would otherwise be difficult to detect and debug.