Free RTOS for an ARM M0 CPU

First, you probably should NOT modify any of the files in the FreeRTOS/Source tree, those files provide the basic FreeRTOS library.

What you want to do as ADD your own file, in which you write your program that uses FreeRTOS to perform your desired activities. One key piece of information you need to add to your knowledge base is HOW those buttons and LEDs are connected to the processor, it is likely through some GPIO structure, and there will likely be some code, perhaps provided by the maker of the processor to access those GPIO.

The simplest program to do the task would just read each button, and set the LED accordingly, and just loop on this. As you said, this doesn’t need FreeRTOS, but does keep the system totally busy on the task. A slight modification to add FreeRTOS would be to add a time delay in the loop, so you sample the button not in a very tight loop, but a somewhat slower, but still faster than human perception (like 100 Hz to 1000 Hz). Without other tasks, this doesn’t buy you anything, but at least in principle, you are allowing space for other activities.

This does introduce a bit of delay (10 ms to 1 ms) between when the button is pressed and the light goes on, and to reduce this, you need to connect the buttons in a way that when they are pressed or released, they generate an interrupt, which your program catches and uses it to signal the code to update the LED (this could be done with direct-to-task notification, a semaphore or a queue). This last version does fully use FreeRTOS and would show how it operates.

Note, all the code for these versions are outside the files provided by FreeRTOS, perhaps in a single user code file, or in multiple files.

1 Like