When faced with the decision between a single-task or multiple-task approach in FreeRTOS projects, what factors should you consider to make an informed choice that aligns with your project’s specific requirements and constraints?"
How do you determine whether to use a single-task or multiple-task approach in your project’s.
In my opinion, if you really think a single task can handle the task, then you don’t really need FreeRTOS around and can just build a simple “freestanding” application. The exception would be if you currently have just one task worth of work, but anticipate a possible need for more in the future.
For most cases, I can find multiple things that want tasks to support them. Generally, I have one task per “asynchronous” input to the system (or class of inputs for things like “buttons”), and most tasks are built on the concept of waiting for an input, then do what is needed, and then go back to waiting for the next input.
Considering you are working with an ESP32 microcontroller and the FreeRTOS context, would you opt for a single-task or multi-task approach when dealing with LED blinking and timely UART polling? Please provide your choice along with a explanation, taking into account the timing requirements and the capabilities of the ESP32 and FreeRTOS.
Sounds a bit like homework now. I don’t know the ESP32, but LED blinking and responding to a UART (you shouldn’t be “Polling” it) sound like different tasks.
Side note, LED blinking might not need a task itself, but could well be done using just Timers.
An RTOS (and specifically FreeRTOS) offers several advantages but I’d argue by far the most important one is simplicity. Adding an RTOS to your embedded code certainly bumps the complexity initially, but if you add significantly more code, you often end up with an easier to understand system.
Using tasks allow for separation of unrelated tasks which simplifies the programmers life. Having to only worry about a single function for each task, and then letting the scheduler handler scheduling competing tasks simplifies code because you don’t need to worry about the interplay of tasks in each task. And this is just for the very basic RTOS (essentially just a scheduler).
FreeRTOS has many other features (notification mechanisms, functionalities from an interrupt, Memory Protection Unit support) which further simplifies building a new embedded solution.