Free RTOS for an ARM M0 CPU

I know that my question is a little foolish But this is just a question I am going to ask Because I have not found a simple and straightforward solution

assume there are two switch buttons are connected at input of ARM CPU and Two LED’s are connected at output

When the first button is pressed, the first LED will turn ON .
When the second button is pressed, the second LED will turn ON

This is a very small task that we can do without rtos.

But what if I want to do this through free ratos. Is it possible? I don’t think it’s not possible, We can do that

assume following source are the file included in your project:
• FreeRTOS/Source/tasks.c
• FreeRTOS/Source/queue.c
• FreeRTOS/Source/list.c
• FreeRTOS/Source/portable/[compiler]/[architecture]/port.c.
• FreeRTOS/Source/portable/MemMang/heap_x.c

My question is, which file do I have to modify if I am using free rtos for two switches and leds?

Note : I will clear again that the example given by me is not correct for RTOS, I am not asking for a code.

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