AD

Thursday 25 June 2015

FreeRTOS on Arduino UNO using Eclipse IDE: Part 3


Previous: Part 2.

In the last part of this tutorial, we are going to create a simple application.

7. Creating a FreeRTOS application



We are going to create a FreeRTOS version of the same "Blink" sketch we used to test the board and our development environment. Everything we are going to do now is quite similar to what we have done in the section 4 of this tutorial.



7.1. Create a new C++ Project and select AVR Cross Target Application / Empty Project as project type. Press next.



Creating a project.

7.2. Deselect the Debug configuration. Press next.

We don't need the Debug configuration.

7.3. Select ATmega328p as MCU Type. Press finish.


Selecting the MCU type.

7.4. We need to add the folder /Source/include from the FreeRTOS static library project to the include directory path of our application project.
- Open the project properties and go to the section C/C++ General / Paths and Symbols.
- Click on Add...
- Fill the dialog according to the following pictures.

Adding FreeRTOS include folder to the include path.

Fill the dialog like this.

7.5. We also need to configure the linker so it find the symbols defined in the FreeRTOS library.
- Still in the project properties, go to the section C/C++ Build / Settings;
- Select AVR C++ Linker / Objects and add the object file as shown in the following pictures.

Adding FreeRTOS object file.

Fill the dialog like this.

7.6. Create a source file (e.g. main.cpp) and type (or copy) this code. The code has basically the same structure as the previous example.
- The main loop (responsible for blinking the LED) is in a separate function (not in main). This is used to create a task instead of being directly called;
- The function vTaskStartScheduler, called at the second line of the main function takes care of executing the tasks. The lines after that call are never executed;
- We need to create a callback named vApplicationStackOverflowHook, that will be executed in case of we run out of memory.


7.7. Build the project (press Ctrl+B). You will probably not find any problem.

7.8. Configure AVRDude. As we already created a programmer, everything we need to do is selecting it (we don't need to create it again).


7.9. Upload the software by pressing the "AVR" button on the toolbar. Sometimes Eclipse "forgets" the project on which you are working and complains that no AVR project is selected. If that happens, just select the project on Project Explorer panel and try it again.



Conclusion

After following this procedure, you will still have the same application you had at the beginning (using Arduino IDE). But you will have plenty of options to create multi-thread applications using threads, queues, semaphores, mutexes, etc. Your possibilities are limited only by your imagination (which I hope to be huge) and the available memory (which I know it is not that big).