I have been playing with an Arduino UNO board during the last few days, and I wanted to see if it could do more than those "sketches". So I decided to try FreeRTOS on it. It turns out that I've got pretty good results!
I am going to show how to port FreeRTOS to an Arduino UNO board using Eclipse IDE. This tutorial is organized as follows:
Part 1:
I am going to show how to port FreeRTOS to an Arduino UNO board using Eclipse IDE. This tutorial is organized as follows:
Part 1:
- Configure Eclipse as an Arduino UNO Integrated Development Environment (IDE);
- Create, build and run a simple "Blink" application for an Arduino UNO board using Eclipse.
- Create and build an Arduino UNO port of FreeRTOS as a static library;
- Adapt source files to ATmega328p;
- Create, build and run a FreeRTOS version of the "Blink" application.
By the way, all the source files are available here.
Arduino UNO clone I used in the tests. |
Motivation
Why Arduino UNO?
- It is cheap;
- It is open-source;
- It is highly available;
- It is easy to learn and use;
- It does not require a separate piece of hardware in order to load new code;
- It is popular among hobbyists and students.
Why FreeRTOS?
- It enables us to implement multi-tasking (that is the main reason);
- It supports both real-time tasks and co-routines;
- It provides task notifications, queues, binary semaphores, and counting semaphores;
- It also provides recursive semaphores and mutexes for communication and synchronization between tasks, or between real time tasks and interrupts;
- It has a tiny footprint, which is good for boards with limited resources (such as Arduino UNO);
- It has been designed to be small, simple and easy to use;
- It is open-source (you can find the code here);
- Royalty free.
Why Eclipse?
- It is much richer in features than Arduino IDE;
- It provides syntax-highlighting editor, incremental code compilation, a file/project manager, and interfaces to standard source control systems, such as SVN and Mercurial;
- It has an extensive plugin library where you can find almost every feature you may need;
- It enables us to work with many kinds of projects and programming languages so, if you already learned how to use it, you don't need to learn how to use another IDE.
Configuration
I am going to show how to make FreeRTOS work on an Arduino UNO board using Eclipse as IDE.
For this procedure I will use:
- Debian Jessie AMD64 as operating system;
- Eclipse Luna 4.4.2 64 bit as IDE;
1. Install the arduino package
The complete name of this package is AVR development board IDE and built-in libraries. You would not really need to install everything from this package, but it is the easiest way to get what we need: the built-in libraries. Just type:
$ sudo apt-get install arduino
This will install the Arduino IDE on you system. It is OK for simple projects, but it is quite limited in features and certainly does not fit our needs.
2. Test the board
Lets test the board and the installation of the Arduino libraries by running a simple test in the Arduino IDE.
2.1. Open Arduino IDE (it will be added to the laucher in the Development group). A dialog will probably be presented asking to add your user to the group dialout. That is necessary to access the board via serial line.
2.2. Open the “Blink” sketch example by accessing the menu File / Examples / 01.Basics / Blink.
2.3. Press the upload button (the second button on the tool bar). The software will be upload to the board and executed. You will see the onboard LED blinking. If it happens, everything is fine and you are ready to go on.
2.4. Things that may go wrong:
You may fail to access the board via serial line if you are not part of the dialout group. The Arduino IDE usualy verifies it and add your user to that group automatically. If that doesn't happen, you may need to add yourself to the group manually. In either case, you will need to logout and login again so the changes take effect.
You can verify the groups to which you belong by typing:
$ groups
You can add yourself to the dialout group by typing:
$ sudo usermod -a -G dialout username
3. Install and configure Eclipse IDE for C/C++ Developers
3.1. Download the Eclipse.
3.2. Extract it to the folder of your preference (let's say ~/deve/eclipse) and run it.
3.3. Install the AVR Eclipse Plugin. Access the menu Help / Marketplace, search for AVR, and click on “Install”. A next-next installation wizard will be presented. Just follow the presented instructions.
AVR Eclipse Plugin installation.
4. Test the Eclipse IDE
We are going the test out development environment by creating a simple application. This application will be an "Eclipse version" of the same "Blink" sketch we used to test the board before. You can follow the described steps or simply clone the project from my repository.
4.1. Create a new C++ Project and select AVR Cross Target Application / Empty Project as project type. Press next.
Creating a project. |
4.2. Deselect the Debug configuration. We don't need it as Arduino UNO board does not allow us to debug applications (please let me know if I am wrong about that). Press next.
We don't need the Debug configuration. |
4.3. Select ATmega328p as MCU Type. Press finish.
Selecting the MCU type. |
Source file. |
4.4. Build the project (press Ctrl+B). You will probably not find any problem.
4.5. Configure AVRDude. This step is necessary to tell the AVR Plugin how to access the board we are going to program.
- Open the project properties;
- Select AVR / AVRDude section;
- On "Programmer" tab, create a new programmer configuration by pressing the button "New";
- Programmer Hardware = Arduino
- Override default port = /dev/ttyACM0
- Don't you forget of selecting the created configuration on "Programmer" tab.
Creating a programmer configuration. |
4.6. 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.
Well, now we have the tools we'll need to create our FreeRTOS static library and any FreeRTOS applications we want.
Next: Part 2.