FreeRTOS on Atmega8?

How to compile FreeRTOS real-time operating system on 8-bit AVR microcontroller Atmega8? It is not supported out of the box as well as google hardly helps with that issue. I did some experiments and understood why people are not doing this.

I have posed this rhetoric question some time ago while finishing winter decor e-snowflake toy based on Atmega8. Lately during my much more complex project I returned to this idea as I planned to use Atmega88 (successor with JTAG debugging capabilities). As FreeRTOS does not compile with Atmega8(8) as a target by default, I just tuned up port mapping quickly based on datasheet just to get it built. 6162 bytes out of 8kB of Flash and 672 bytes out of 1024 of available RAM is taken just to make OS running, plus at least 45 bytes of RAM for each task’s context switching (swapping registries and internal RTOS data); you need add to it space necessary to keep variable using in task itself. Having simple lightweight tasks consuming up to 200 bytes of RAM each, makes it 3 in total.

In my case it would not work. I had to add some numeric computations and using floating-point makes it impossible: atmega does not have FPU so that GCC has to link-in math libraries that add to flash up to 4 kB extra code depending on what float operations are engaged. Even if I had implemented these operations with my integer-based algorithm shrinking this part to ~400 bytes, complete logic finally took around 7kB. To make it even worse I needed to use MODBUS protocol on top of it. Going simple (ineffective if you will) way by using FreeModbus library, just for its minimal subset of operations add extra 3660/331 bytes to flash/RAM accordingly. I stabilized complete solution around 12kB saving some space for possible enhancements. Adding FreeRTOS would require bigger flash like Atmega32(8) has, which in turn would require PCB redesign.

To summarize, do not bother with Atmega8 if you think FreeRTOS. Instead of $2 just spend $3 on Atmega168 that doubles flash size making room for OS and your code (FreeRTOS targets it out of the box). If you insist on Atmega8 and you are ready to disclose your source code, you can give a try to FemtOS based on GPL license. Ultimately if you are still in favor of Atmega8 in commercial project then take a look on timer-based scheduler algorithms instead of full blown portable OS.

This entry was posted in Electronics, Software and tagged , , , . Bookmark the permalink.

2 Responses to FreeRTOS on Atmega8?

  1. Jaeyong Cho says:

    Thanks for good article and exprience sharing.
    It’s very clear and cool.
    Have a nice day.

  2. Mostafa says:

    Thanks for sharing your experience.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.