This is the second part of the three part tutorial on setting up a free and fully functional GCC + Eclipse + OpenOCD (ST-LINK V/2) GDBServer environments for use with the STM32F0Discovery board. Links to the first and third parts of this tutorial are provided below:
- Part 1 – Setting up the GCC ARM Toolchain
- Part 3 – Setting up Debugging with the Eclipse IDE (OpenOCD GDBServer)
In a previous entry, I demonstrated how one could utilize the gcc-arm toolchain to build a simple blinky LED project for the STM32F0Discovery board. While I didn't look at the code, project structure, makefile structure e.t.c, I demonstrated the steps through which you can install such a toolchain and use it to build the project from the command line. The advantage of this approach is that you could virtually use any text editor to develop your code and then build the project from the command line. Some great code editors include Notepad++ and Gedit.
Now the command line / text editor approach is not for everybody and does not really provide you with a useable debug capability (actually you can debug from the command line....but who really wants to do that ?). A graphical integrated development environment (IDE), that allows you to edit the source code, build the project and provide debugger integration to enable debugging through the IDE is a key tool for the embedded developer. This is where Eclipse comes in.
I'll be honest with you from the outset. I do not like Eclipse because it's based on Java. It's a slow and bloated IDE program, but it's got some amazing functionality. If only it could be written in C++.
To get started make sure that you successfully installed the gcc-arm toolchain as instructed in first part of this tutorial and that you were able to successfully compile the "iotogglem0" project from the command line. Also make sure that you have the "iotogglem0" project in the "C:\Development\Workspace\iotogglem0" directory and the STM32F0Discovery firmware in the "C:\Development\STM32F0-Discovery_FW_V1.0.0" directory as previously instructed. Next we will need to download the Eclipse classic application from this link. At the time of this writing The Eclipse that I downloaded was Eclipse Juno 4.2 for C/C++ Developers. . I downloaded the 64-bit Windows version as I'm running the 64-bit version of Windows 7. The Eclipse download is around 143MB which is not bad for such a powerful development tool. Having said that, I found that Eclipse can easily consume 400-500MB of RAM. So make sure that you have plenty of RAM when running Eclipse.
Once Eclipse is downloaded follow the procedure provided below:
- Extract the "eclipse" Folder from the downloaded zipped Eclipse classic file; which in my case was called: eclipse-cpp-juno-win32-x86_64.zip into the "C:\Development" directory such that the full path of the eclipse directory is: "C:\Development\eclipse". Inside the eclipse directory you will find the eclipse binary (.exe) file. Click on it.
- A workspace launcher window will appear asking you of the location of the eclipse workspace. Be sure to select the "C:\Development\Workspace" as your Workspace directory and press OK.
- At this point lets create a new project based on our "iotogglem0" example!
- Click on File-> New -> Makefile project with existing code. This will open the import Existing Code Window.
- For the Existing Code Location field, click on the "browse" button. This opens an open file dialog. Input the "iotogglem0" folder path which should be in your Workspace directory. The project name is automatically set to that of the chosen folder "iotogglem0". Make sure that you only check the c language and uncheck the C++ language if necessary. and then choose the "cross GCC" toolchain in the box below as shown in Figure 2. Then click finish.
- At this point the project has been included and we only need to make some minor changes to the project properties to be able to build the project in Eclipse. The Eclipse IDE at this point should look Figure 3.
- It's worth mentioning here that even when you want to start a project from scratch, you will probably want to choose to create a makefile based project as we did with iotooglem0 and then import it. If you do not like to use makefiles, there is a GNU-ARM Eclipse plugin that allows you to configure the build process graphically without makefiles. But I find the makefile method to be easier.
- Now right click on the project name "iotogglem0" in the project explorer and click on the properties option. Alternatively you can click on the "iotogglem0" project name in the project explorer. Then click on the properties option under the "Project" menu. This will open a project properties pop up window as shown in Figure 4.
- Click on the "Discovery Options" tab in the left hand side bar. Ensure that the "Discovery profile Options" is set to "Configuration-wide", and that the "compiler invocation command" is "arm-none-eabi-gcc" as shown in Figure 4.
- Then move to the "Settings" tab in the left hand side bar. Ensure that only the GNU ELF parser is selected as shown in Figure 5.
- Next take a look at the "Tool Chain editor Tab". It should look like Figure 6. You should not have to modify anything.
- Click the OK button to close the properties window and then click on "Build Project" which is found in the "Project" Menu. This has the effect of invoking the "make" command and building the project. To clean the project, click on "clean" under the "Project" Menu and then choose the "clean projects selected below" and select the "iotogglem0" project. Then press "OK". This has the same effect as running the "make clean" command. The console window at the bottom of the IDE will show you the output of the build process (see Figure 7) which will be identical to what you saw in the command prompt window when building the project from the command line.
- Also note that you have a problems tab at the bottom of the IDE. Usually you can ignore any errors /warnings shown there. These problems are caused by the fact that eclipse is unaware of the locations of all the header / source files used in the project.
- Make sure you however do not ignore errors shown in the console window. The reason errors are shown under the problems tab is that there are header and source files that are included in the project via the makefile only and not via the IDE. The IDE fails to find these files and lists any variables / functions associated with these files as "could not be resolved" do not worry about these for now. As long as the build process succeeds have no fear!
At this point we have successfully built our program in Eclipse. We can then download the generated ".hex" file onto the STM32F0 Microcontroller via the STM32 ST-Link Utility as demonstrated in part 1.
Before we go we will prepare our IDE setup for debugging by installing the Eclipse CDT plugin. This is needed as it includes GDB integration which we need for debugging. To accomplish this task follow the following procedure:
- Click on "Help->Install New Software". This should open an "Install - Available Software Window (Figure 8). Then Click on the "Available Software Sites" link on the top right. This should open another window"Preferences - Available Software Sites" (Figure 9). Check the "CDT" Check box and click OK.
- This will take you back to the "Install - Available Software Window" ahown in Figure 10. This time there will be a list of plugins that can be installed listed in the Box labelled "Name". Check the "CDT Main Features" and the "CDT Optional Features" plugins as shown in Figure 9 and click the "Next" button. Click the "Next" button again in the "Install - Install Details" window and then accept the "Eclipse Foundation Software User Agreement" by checking the "I accept...." option and click on the Finish button. At this point the CDT plugins will be installed.
- Once Installation is complete you will be prompted to restart Eclipse. Once Eclipse restarts the CDT plugins will be installed and Eclipse will have GDB integration which will enable debugging. Part 3 of this tutorial includes further details in configuring GDB debugging in Eclipse.