dcrocker wrote on Tuesday, January 02, 2018:
Hi all, I am about to start converting a project to use FreeRTOS. So I am looking for tips. Here is some background:
- I have previous experience of RTOS (I used to be a developer of one), but no experience of FreeRTOS yet
- The project is a successful 3D printer control firmware (RepRapFirmware) and the target for the FreeRTOS version will be ARM Cortex M4 and higher ATSAM processors
- The project is somewhat object-oriented and mostly written in C++, but avoids dynamic memory allocation except during initialisation and configuration
- The development tools are Eclipse and gcc
- RAM is already quite tight, but we can afford around 10K (perhaps more) for FreeRTOS and the tasks and stacks, and most tasks shouldn’t need large stacks if we can run them in user mode so that interrupts are handled on a separate stack
- For several months I have been ensuring that any new developments should be suitable to fit into a task-based model
- It uses FatFS for SD card access, and some versions use LWIP to provide a TCP/IP stack
- I was pleased to see that FreeRTOS complies with the MISRA-C coding standard, because I am familiar with it (I am a member of the MISRA-C++ Working Group, and a former member of the MISRA-C Working Group).
My questions:
- To get started, I propose to create a single task which executes the existing main loop code. The Idle task will never get a look-in. After this is working, I will split some of the functions currently executed in the main loop into other tasks. Does this sound a reasonable approach?
- Many of the functions executed by code that will eventialy be split into different tasks access the same data, mostly read-only, by calling accessor methods of the classes that hold that data. It may not be practical for me to use the MPU to partition the memory between tasks. At the same time, it would be nice if the tasks’ own stacks and other working memory could be protected from each other. Any suggestions on the best approach?
- Is there already a C++ wrapper for the more complex FreeRTOS data structures, to simplify the interface to message queues etc. from C++? It would need to be one that does not use dynamic memory allocation.
- I see that instead of FatFS and LWIP I could use FreeRTOS+FAT and FreeRTOS+TCP. Should I use them, or stick with FatFS and Lwip? I think both include some support for FreeRTOS already.
- Some of the existing functions performed by the main loop don’t really merit additional tasks, because they are not time-critical and the existing round-robin approach works well. Nevertheless, converting them to tasks or coroutines would avoid the need to use state machines in some cases. Should I use coroutines for them, or should I avoid coroutines because they are end-of-life as far as FreeRTOS development is concerned?
- Anything else I should be aware of before I start?
Thanks in advance - David