Set Up Eclipse for Debugging on Mac OS X

Set Up Eclipse for Debugging on Mac OS X

I recently got an ST-LINK/V2 JTAG debugger from Mouser.com so I can play around with hardware debugging on Crazyflie 2.0. To do this more easily, I figured I’d use the Eclipse IDE like the guys at Bitcraze do. Of course, I could use the <a href=”http://files.bitcraze.se/dl/Bitcraze_VM_0.6.ova” title=”Bitcraze 0.6 VM” rel=”nofollow” target=_blank”>Bitcraze 0.6 VM and all would be well and good… But, if you’ve followed this blog, you know I’d much rather do it all in Mac OS X. So, I set out to get things set-up on Yosemite (Mac OS X 10.10). What follows is what I did to get a working Eclipse installation. Most of this was taken from what I discovered in the Eclipse setup on the 0.6 VM that the Bitcraze bunch so kindly created for us…


This is a long tutorial so here’s a list of the major steps (with links):

1) Install Eclipse
2) Launch Eclipse
3) Select a Workspace
4) Install the EGit (Git) Add-on
5) Install the GDB Add-on
6) Set the PATH Variable
7) Add the crazyflie-firmware Project
8) Create “make” Targets
9) Create Debug Configurations
10) Create External Tool Configurations

First, it was fortunate that I already did what I needed to do to get the GCC-ARM toolchain set up, since I needed that for this exercise. If you run the script mentioned in that post, it will download the right GCC-ARM and get your $PATH variable set up correctly. So, run that script in the Terminal and then echo your PATH variable and save that value for later.

echo $PATH

Now, let’s get to the fun part of setting up Eclipse for Crazyflie debugging!

Download and Install Eclipse:
1) Install Eclipse
a) Head on over to the Eclipse downloads page and pick up the the 64-bit CDT IDE for Mac. (hint: it’s this one here). Download and “install” it by putting the unarchived folder wherever you want.

2) Launch Eclipse
a) Launch Eclipse by double-clicking the “eclipse” app in the “eclipse” folder. If you get an error about needing a later version of Java, head over to Oracle’s JDK page and download one, even if your Java preferences pane says you have the latest. I ran into this issue. The Prefs pane said I had the latest installed but “java -version” in the Terminal said I was on 1.6!? I ran the installer for the latest and all was well in the world again. Note: Oracle requires you to create an account to download. Annoying.

3) Select a Workspace
a) Eclipse will ask you to select a workspace on first-run. Easy enough. Just pick a place convenient for you.
Select workspace in Eclipse

4) Install the EGit (Git) Add-on
a) In Eclipse, choose “Install New Software…” from the “Help” menu.
Eclipse Help Menu
b) Click the “Add…” button in the “Install” window that appears.
Eclipse Install Window
c) In the “Add Repository” window, type “EGit” in the “Name” field, then type “http://download.eclipse.org/egit/updates” in the “Location” field. Hit the “OK” button.
Eclipse Add Repository Dialog
d) Finally, check the box next to “Eclipse Git Team Provider” and click the “Next” button. It will download and eventually you’ll get a “Finish” button. When you do, click it.
Eclipse Git Team Provider
e) There’s some more set-up you can do to integrate Git with Eclipse but for now, this is all we need. Here is a good resource (based on a little older version of Eclipse) than can help with further configuration.

5) Install the GDB Add-on (for hardware debugging)
a) Much like the EGit install in step 4, we’ll install GDB for debugging now. Again choose “Install New Software…” from the Eclipse “Help” menu.
Eclipse Help Menu
b) From the “Work with” menu in the “Install” window, choose “Luna.”
Luna
c) In the text field immediately below the “Work with” pop-up menu, enter the text: “gdb“.
gdb filter
d) Check the box next to “Mobile and Device Development” which will subsequently check the box next to “C/C++ GBD Hardware Debugging” automatically.
GDB Hardware Debugging
e) Click the “Next” button at the bottom of the window.
Next
f) Verify the only thing being installed is “C/C++ GBD Hardware Debugging” and click the “Next” button.
GDB Install
g) Click the radio button next to “I accept the terms of the license agreement” (if you actually do), then click the “Finish” button at the bottom right of the window.
License Agreement
h) Wait for the installation to complete and the “Installing Software” window to disappear.
Installing Software
i) Finally, click the “Yes” button to restart Eclipse and activate the GDB add-on.
Restart Eclipse

6) Set the PATH Variable (for the GCC-ARM toolchain)
a) Choose “Preferences” from the “Eclipse” menu.
Eclipse Menu
b) In the left-hand column of the “Preferences” window, click the disclosure triangle next to the item: “Build,” then select the “Environment” item.
Preferences Window
c) Click the “Add” button on the far right of the “Preferences” window to bring up the “New variable” form.
New variable
d) In the “Name” field of the “New variable” entry form, enter “PATH” and in the “Value” field, enter the path string you got from the Terminal when you ran my script earlier. Then click the “OK” button.
Note: If you ever move your GCC-ARM folder, you will need to adjust this variable accordingly.
Add variable form
e) Back in the “Preferences” window, click the “Apply” button, then click the “OK” button.
PATH variable added

7) Add the crazyflie-firmware Project*
*Note: This assumes you have already cloned the “crazyflie-firmware” Git repository. If you have not yet, you can follow the commands in my post on compiling the firmware on Mac OS X to get the repository cloned.
a) From the “File” menu in “Eclipse,” choose “New,” then “Makefile Project with Existing Code.”
File menu
b) In the “New Project” window, enter “crazyflie-firmware” in the “Project Name” field. Then, click the “Browse” button and select the folder containing your crazyflie-firmware Git repository clone. Under “Languages,” uncheck the box next to “C++” (leave the box next to “C” checked). In the “Toolchain for Indexer” section, select “Cross GCC,” then, click the “Finish” button. A new “crazyflie-firmware” project should show up in the left-hand column “Project Explorer” section of the main Eclipse workspace window.
New Project window

8) Create “make” Targets
a) From the “Window” menu in Eclipse choose, “Show View,” then select “Make Target.” The new view shows up on the top-right of the main Eclipse workspace window. I pulled mine down to the lower-left hand side by clicking and dragging on the section’s title tab.
Show Make Target view
b) Right-click on the “Makefile” file icon in the left-hand “Project Explorer” column (you may need to click the disclosure triangle next to the “crazyflie-firmware” folder icon to reveal the files and folders inside). Then, from the contextual menu that pops-up, choose “Make Targets,” then select “Create…”
Create Make Target
c) In the “Create Make Target” form that appears, enter “clean” in the “Target name:” text field, and click the “OK” button.
clean
d) In the “Make Target” view in the Eclipse main workspace window (wherever you put the view), click the icon of a folder with a line through it to “Hide Empty Folders.” The “crazyflie-firmware” folder icon should remain in view. If you click the disclosure triangle next to the “crazyflie-firmware” folder icon, you should see a green “target” icon with the word “clean” next to it. You’ve created your first “Make” target.
make targets
e) Repeat step “b” above. When the “Create Make Target” form appears, this time you should enter “Flash using the debugger” in the “Target name:” field. In the “Make Target” section, uncheck the box next to “Same as the target name” and enter “flash” in the “Make target:” text field instead. Click the “OK” button to save the new target.
flash
f) Repeat step “b” again. When the “Create Make Target” form appears, enter “Flash using radio” in the “Target name:” field. Then, in the “Make Target” section, uncheck the box next to “Same as the target name” and enter “cload” in the “Make target:” text field. Click the “OK” button to save the new target.
cload
g) Repeat step “b” again. When the “Create Make Target” form appears, enter “Make CLOAD” in the “Target name:” field. Then, in the “Make Target” section, uncheck the box next to “Same as the target name” and enter “all DEBUG=0 CLOAD=1” in the “Make target:” text field. Click the “OK” button to save the new target.
Make CLOAD
h) Repeat step “b” again. When the “Create Make Target” form appears, enter “Make Debug” in the “Target name:” field. Then, in the “Make Target” section, uncheck the box next to “Same as the target name” and enter “all DEBUG=1 CLOAD=0” in the “Make target:” text field. Click the “OK” button to save the new target. Now you’ve created all the targets necessary for the “crazyflie-firmware” project.
Make Debug

At this point, you can try to right-click the “Make CLOAD” target and select “Build Target” from the contextual menu. If you didn’t patch the Makefile to change “python2” to “python,” and you don’t have a symlink resolving “python2” to “python,” you’ll likely get an error when trying to compile version.c. You can take a look at the commands in my compiling on Mac OS X post to see how to quickly patch the Makefile. If you ran the commands in that post already, you should be able to compile successfully. Go ahead and try the “clean” target to remove the compiled binaries. Then try some of the other targets. You’ve got the “crazyflie-firmware” project in an IDE now. Go GUI crazy!

You can (and should) continue to add more repositories to the “Project Explorer” column in the Eclipse main workspace window by following step “7” again for each project. The projects you may want to add include: “crazyflie-bootloader,” “crazyflie2-nrf-firmware,” and “crazyflie2-stm-bootloader.” You can add the “make” targets for each of these projects by looking at the Makefile in each project and following step “8” above to create new targets with the correct “make” commands.

9) Create Debug Configurations
Before we can debug, we need to tell Eclipse how to debug the Crazyflie. To do that, we create “Debug Configurations.”
a) Select “Debug Configurations…” from Eclipse’s “Run” menu.
Run menu
b) Click on the “GDB Hardware Debugging” line in the left hand column of the “Debug Configurations” window.
Debug Configurations Window

Now we’ll create a Debug Configuration for the STM32 firmware for both the Crazyflie 1 and Crazyflie 2.

c) Right-click the line, and select “New” to open a “Debug Configurations” window.
New
d) Enter “Crazyflie 1 and 2 STM32” in the “Name” field of the “Main” tab.
Name field
e) Enter “cflie.elf” in the “C/C++ Application” field of the “Main” tab.
cflie.elf
f) Next to the “Project” field of the “Main” tab, click the “Browse” button.
Project
g) In the “Project Selection” window, click “crazyflie-firmware” then click the “OK” button.
Project Selection
h) In the “Build (if required) before launching section” of the “Main” tab, click the “Disable auto build” radio button.
Build
i) Make sure your “Main” tab configuration looks like the following image, then click the “Debugger” tab.
debug config
j) Click the “Browse” button next to the “GDB Command” field in the “GDB Setup” section of the “Debugger” tab.
gdb
k) In the “Select GDB Binary” file browser window, navigate to the folder containing your GCC-ARM toolchain. In the “bin” folder, select the “arm-none-eabi-gdb” binary file.
gdb binary
l) Verify that the “GDB Command” field in the “GDB Setup” section of the “Debugger” tab has the path to your “arm-none-eabi-gdb” binary file.
gdb path
m) Enter “3333” in the field “Port number” in the “Remote Target” section of the “Debugger” tab.
tcp port
n) Click the “Startup” tab and uncheck the “Load image” checkbox in the “Load Image Symbols” section of the “Startup” tab.
startup
o) Finally, click on the “Apply” button near the bottom of the window.

Next we’ll create a Debug Configuration for the nRF51 firmware for the Crazyflie 2. The process is basically the same as we just did.

p) Right-click the “GDB Hardware Debugging” line in the left hand column of the “Debug Configurations” window again and select “New.”
New
q) Enter “Crazyflie 2 nRF51” in the “Name” field of the “Main” tab.
nRF51
r) Enter “cf2_nrf.elf” in the “C/C++ Application” field of the “Main” tab.
cf2_nrf.elf
s) Next to the “Project” field of the “Main” tab, click the “Browse” button. Then, in the “Project Selection” window, click “crazyflie2-nrf-firmware” then click the “OK” button.
Project
t) In the “Build (if required) before launching section” of the “Main” tab, click the “Disable auto build” radio button.
Build
u) Click the “Debugger” tab, then click the “Browse” button next to the “GDB Command” field in the “GDB Setup” section. In the “Select GDB Binary” file browser window, navigate to the folder containing your GCC-ARM toolchain. In the “bin” folder, select the “arm-none-eabi-gdb” binary file. Also, don’t forget to enter “3333” in the “Port number” field of the “Remote Target” section.
gdb
v) Click the “Startup” tab and uncheck the “Load image” checkbox in the “Load Image Symbols” section of the “Startup” tab.
Startup
w) Now you should have two debug configurations under the “GDB Hardware Debugging” line in the left-hand column of the “Debug Configurations” window.
final config
x) Finally, click on the “Apply” button near the bottom of the window. You can also close the window.

10) Create External Tool Configurations
The last pieces of the puzzle are configurations for external tools (openocd). We’ll need a different configuration for each one of the firmwares (STM32 for Crazyflie 1 and Crazyflie 2, and nRF51 for Crazyflie 2). For this step you will need to have the openocd tool installed. This guide assumes you are using MacPorts to install the openocd tool. If you are using another package or have built openocd yourself, please adjust accordingly.

a) Use MacPorts to install openocd. Simply enter the following into a Terminal window: “sudo port install openocd +stlink” then hit the return key and wait for it to compile and install.
b) Select the “External Tools” menu item in Eclipse’s “Run” menu and then choose “External Tools Configurations…”
External Tools menu
c) Click the “Program” line in the left-hand column of the “External Tools Configuration” window.
External Tools Config
d) Right-click the the “Program” line and select “New” from the contextual menu.
New
e) Enter “Crazyflie 2.0 STM32F4” in the “Name” field of the “Main” tab.
Name
f) In the “Location” field of the “Main” tab, enter “/opt/local/bin/openocd” (the path to the openocd tool).
Note: this path assumes you have installed the openocd tool using MacPorts. If you did not, your path is likely different.
openocd path
g) Below the “Working Directory” field of the “Main” tab, click the “Browse Workspace…” button, select the “crazyflie-firmware” line from the list, and click “OK.”
working dir
h) Enter “-d0 -f interface/stlink-v2.cfg -f target/stm32f4x_stlink.cfg -c init -c targets -c “reset halt”” in the “Arguments” field of the “Main” tab.
arguments

To create the configuration for the Crazyflie 1 firmware, repeat steps d through h entering “Crazyflie 1.0” in the “Name” field, and “-d0 -f interface/stlink-v2.cfg -f target/stm32f4x_stlink.cfg -c init -c targets -c “reset halt” in the “Arguments” field.
CF1

To create the configuration for the Crazyflie 2 nRF51 firmware, repeat steps d through h entering “Crazyflie 2.0 nRF51” in the “Name” field, and “-d0 -f interface/stlink-v2.cfg -f target/nrf51_stlink.tcl -c init -c targets -c “reset halt” in the “Arguments” field.
nRF51

At this point we’ve got everything we need to build and debug Crazyflie firmware through Eclipse for both Crazyflie 1.0 and Crazyflie 2.0 STM32 and Crazyflie 2.0 nRF51 chips. In my next post, I’ll detail how to actually start debugging the STM32 firmware with the ST-Link/V2 debugger and the Bitcraze debug adapter.

Comments are closed.