Setting up Eclipse to develop freeRTOS projects with Arduino

In this article, I will show you how to setup a development environment for writing freeRTOS programs on Arduino using Eclipse. Although Arduino IDE is a good place for beginners to start with, it lacks must-have features that a professional needs to write C/C++ code, for example, go to definition or project explorer, just name a few. Arduino IDE is not suitable for writing and debugging projects that have a real time operating system such as freeRTOS. At the end of this tutorial, you will be able to:

  • Understand why are we moving away from Arduino IDE
  • Setup Eclipse to write freeRTOS programs
  • Upload a freeRTOS program to an Arduino board using Eclipse

Why do we want to replace Arduino IDE?

Before we start setting up Eclipse for freeRTOS development, let’s review what Arduino IDE is doing to make things work and why we probably do not want to use it.

Arduino has a text editor in which we write our code (called sketch in Arduino terminology) as shown in Figure 1. This is probably the place that we work most of the time, including writing, editing, jumping between function calls, etc. This text editor is very basic and lacks important functionalities for writing code. For example, to find where a function is defined, you need to manually hit Ctrl + F on Windows (or Cmd + F on Mac) to find the function definition. You will need to put everything in one file which makes it very long and difficult to maintain when the program gets bigger, especially for freeRTOS programs. This is not a tool for professional developers. We want to replace Arduino mostly because we want to replace this text editor.

Figure 1: Arduino IDE interface

Compared to Arduino IDE text editor, Eclipse has more features that make it a much better development environment. As can be seen in Figure 2, there is a project explorer on the left so that you can navigate and manage all files in your project. There is a text editor in the middle area where you can open multiple files in multiple tabs at the same time. You can go quickly to a function by looking at the outline view on the right. The navigation bar on the top helps communicate with the Arduino hardware and the console under the bottom displays output. There is a bit of learning curve to familiarise with Eclipse if you have not used it before. But once you are used to it, you will quickly forget about Arduino IDE.

Figure 2: Eclipse workspace

What do we want to keep from Arduino IDE?

There are a few things from Arduino IDE that we want to keep:

  • Firstly, the process to build a program is simple. Arduino IDE invokes some programs automatically to translate the source code to Arduino machine language when you hit the Verify button. Eclipse does not provide those tools out-of-the-box and we need to configure it.
  • Secondly, Arduino IDE has a large number of libraries and simple way to install a library. When moving to Eclipse, we’ll want to be able to use those libraries, especially freeRTOS library.
  • Thirdly, Arduino IDE has a simple way to talk to target Arduino board by specifying the board and the port that the board is connecting to. We need to do some configuration in order to make that happen.
  • Lastly, Arduino IDE has Serial Monitor so that you can print messages to during software development. We’ll need somehow to do the same thing in Eclipse.

If Eclipse is able to do all those things, then there is no reason that we stick to Arduino IDE anymore. In the following sections, I will show you how to configure Eclipse to do all those things.

How to setup Eclipse

Firstly, download and install Eclipse IDE for C/C++ developers from official website. Choose the version that corresponds to your OS (Windows, Linux or Mac). Then Open Eclipse and follow these steps.

Create a new project

Click File->New->Arduino Project. The New Arduino C++ Project dialog will show up. Choose Arduino C++ Sketch and click Next. Then enter project name as blinky and select project location.

Create new Arduino project in Eclipse

Install Arduino platform tools

Click Help->Arduino Download Manager. In Arduino Download Manager dialog, select Platforms, then click Add button. Tick the box Arduino AVR boards and click OK. All the required tools to compile and upload code for Arduino will be downloaded. Note that the tools will be downloaded to folder $(HOME)/.arduinocdt.

Arduino Download Manager in Eclipse

Install FreeRTOS library

We also need to install the freeRTOS library. In the Arduino Download Manager dialog, click Libraries, then click Add button. Type in the search box ‘freertos’. Select the FreeRTOS library under Timing and click OK. The library will be downloaded to folder $(HOME)/.arduinocdt/libraries/.

Install freeRTOS library for Arduino

There is one more step. In order to use the library for the blinky project, we need to specify in the project properties we are using FreeRTOS library. Tick the FreeRTOS library and click Apply and Close.

Writing blinky program

Now write the code to make a LED blink once every second. We’ll create a single task that goes into Blocked state in 1 second interval, then wake up and togger the LED pin.

Compile the program

Compile the program by hitting Command + B or Project->Build project. This is equivalent to Verify button in Arduino IDE.

Upload code to Arduino

To Upload code to Arduino, we’ll need to create a new launch target.

Select Arduino in the New Launch Target dialog that appears, then click Next. Type in the target name as the board name, plug in the Arduino board, the choose the Serial port that corresponds to your target board. Choose the board type that you have, in my case, I am using an Arduino Mega 2560. Then hit Finish. To upload the code to Arduino, click Run->Run. Eclipse will invoke avr-dude to flash the program to Arduino board.

Serial Monitor equivalent in Eclipse

Lastly, to print messages using Serial.println() function, you need to open a connection between Eclipse and Arduino. Go to Window->Show View->Other… Then choose Connections under Connections and click Open. If you have a board connected, it will print CONNECTED in the console and you’ll be able to print out messages to console like the Serial Monitor. By default, it is using 115200 baud rate so in you code, you’ll need to use Serial.begin(115200) to setup the Serial.

Wrapping Up

In this article, we have finished setting up Eclipse for developing freeRTOS applications on Arduino. We’ll talk about debugging freeRTOS application using Eclipse in another tutorial.

Leave a Comment