In this part of the tutorial we will be setting up eclipse to launch a full debug session where the processor can be flashed with the application, and ran. Once this part is successfully completed you will be able to set breakpoints and view memory, just like any expensive toolchain. This part of the tutorial was the most difficult for me to get right. Hopefully you will have fewer problems than I did.
Start by downloading OpenOCD from Freddie Chopin’s website by following the link below.
Once you’ve downloaded OpenOCD, extract the 7zip file. Next, add the extracted OpenOCD folder to the ARMTC folder. Below is what my ARMTC folder now looks like.
Now, as we did for the ARMGCC, add the path to the OpenOCD bin folder to your PATH environment variable. If you are not sure how to do this, refer back to the Part 2 post. My path to OpenOCD is:
Now test the path to OpenOCD by typing the command below in the command window.
You should get results similar to what is shown below.
Install the Olimex ARM JTAG
Now we need to install the drivers for the Olimex JTAG device. I used the instructions for installing the drivers that are contained in the README file in the OlimexODS drivers folder. Start by plugging in your JTAG device. You should then be prompted to either automatically install the drivers, or provide a location. Choose install from a specific location, and if you have downloaded the OlimexODS, choose the olimex-libusb-184.108.40.206 folder contained in the drivers folder. If you don’t have OlimexODS, the navigate to the OpenOCD drivers folder, extract the libusb-win32_ft2232_driver-120229 zip file, and point the driver installer to this folder. I recommend using the drivers provided by Olimex, if you can, since I haven’t tried the drivers provided by OpenOCD. Please comment if you have successfully used the OpenOCD FT232 drivers with the Olimex JTAG device.
Next, we can further test OpenOCD by launching it from a command window. Open a new command window in the main folder of the project. My path is shown below.
Now, enter the command shown below adapting wherever necessary to match your project configuration. The results I got are shown below. If the image is too small to see in your browser window, the click it to open to full size.
openocd-0.7.0 -f C:\ARM\openocd-0.7.0\scripts\interface\olimex-arm-usb-tiny-h.cfg -f project.cfg
As you can see, this failed for me. The version of OpenOCD that I downloaded didn’t have the olimex_stm32_e407.cfg file. To get this to work, I had to copy this file from the OlimexODS folder tree, and paste it in to my OpenOCD scripts/boards folder. After copying the script in to my OpenOCD directory, I tried the command again. Below is the result.
This time you can see that OpenOCD was successfully launched. The last line tells you that you have 6 breakpoints and 4 watchpoints.
Also, windows will likely ask if you want to allow access to OpenOCD. I went ahead and gave it full access.
Now we will integrate OpenOCD, GDB, and Eclipse. If it isn’t already running, start Eclipse and select the workspace that we created in part 3.
Install GDB Hardware Debugging Plugin
Click Help then Install New Software.
In the Work with text box, select Kepler. Wait for the options to load in the Name box. Once the Name box is populated, expand the Mobile and Device Development category. place a check next to C/C++ GDB Hardware Debugging, and click next.
Once again click Next.
Accept the license agreement, and click finish.
Configure GDB Client
At this point, we will configure the GDB client. Start by clicking the down arrow next to the bug symbol, then click Debug Configurations.
Start by giving this configuration a unique name in the Name text box. Click the radio button next to Disable auto build.
In the Debugger tab, change the GDB Command to arm-none-eabi-gdb. Ensure that Generic TCP/IP is selected for the JTAG Device, and that the Host name is localhost. Type 3333 for the Port number.
In the Startup tab, ensure that Reset and Halt are not checked. Enter monitor reset halt in the Initialization Commands text box. Ensure that the Load image and Load symbols boxes are checked.
Also in the Startup tab, ensure that the remaining boxes are unchecked. Unless you know of any run commands that would be useful, then it should be safe to leave this text box empty.
There should be nothing to do in the Source tab.
In the Common tab, place a check next to Debug so that this configuration will be added to the favorites menu.
Click the Apply button, then the Close button for now.
OpenOCD Server Launcher
Now we will set up a way to launch OpenOCD from Eclipse. Do this by clicking the down arrow next to the External Tools icon, then select External Tools Configurations.
In the Location text box of the main tab, add the path to the OpenOCD executable adapting where necessary to fit your project.
To add the project location as the working directory, click the Variables tab, scroll down to projcet_loc, and click Ok.
Add the line below to your arguments list.
-f ../scripts/interface/olimex-arm-usb-tiny-h.cfg -f project.cfg
The refresh tab should already be set up.
In the build tab, ensure that the Build before launch check box is empty.
The Environment tab should already be properly set.
In the common tab, ensure that a check is added next to the option to display this configuration in the external tools menu.
When you are finished, click Apply and then Close.
Launch OpenOCD Server
Click the down arrow next to the external tools icon, and then click on the OpenOCD Server Launcher that we created in the previous steps.
In the console window you should be able to see someting similar to what is shown below where it tells you how many breakpoints, and how many watch points you have available.
Launch GDB Client
Now it is time to actually run the test program on the board. Ensure that your JTAG is connected to your computer through USB, that the JTAG is properly connected to your board, and that the target board is powered. Launch the GDB client by clicking the down arrow next to the debug symbol and clicking on the newly created launch configuration.
At this point the application should be loaded, and the processor should be halted. Next, click the resume button.
This will start the application and you should be seeing the LED blinking. Once you are done screaming like a girl with excitement, because you have made what at one point felt like the impossible, actually happen, click the suspend button to stop the processor.
Now add break points by double clicking the area to the left of the delay lines as shown below. Once you’ve added the break points repeadedly click the resume button. This should alternately stop on each break point toggling the status of the LED on and off at each break point.
This brings us to a stopping point in the tutorial series. When developing with the ARM GCC, Eclipse, and OpenOCD it seems like there are unlimited possibilities, but also just as many pitfalls. Hopefully we can share information, and make this process easier in the future.
Zylin Alternative GDB Client
Alternatively you can install the Zylin Eclipse Plugin. I have used this one successfully in the past, but wasn’t able to get it to work with this version of Eclipse. To add the Zylin Eclipse plugin. Start by clicking the Help tab, and selecting Install New Software.
Paste the address of the Zylin update site below in to the work with text box, and click the add button.
Type Zylin in the name text box of the resulting Add Repository dialog and click OK.
Once the plugin loads, push the Select All Button, and click next
Click next on the Install Details dialog.
Accept the license, and click Next.
Click Ok to the warning about unsigned content. Next, you will be prompted to restart eclipse. Click Ok, and allow Eclipse to restart. When Eclipse restarts, once again select the workspace from Part 3, and click OK.
Now we need to create a new debug configuratoin. Click the down arrow to the right of the bug symbol and select Debug Configurations as is shown below.
In the resulting debug configurations dialog, double click the Zylin Embedded Debug (Native) option.
This creates a new debug configuration. In the main tab, rename your debug configuration to whatever you want. I just changed the word Default to Debug.
In the debugger tab, ensure that the Embedded GDB debugger is selected. Change the name of the GDB debugger to arm-none-eabi-gdb. Also, ensure that the GDB command file text box is blank.
Add the Initialize commands below to the commands tab.
- target remote localhost:3333
- monitor reset halt
- monitor wait_halt
- monitor sleep 100
- monitor poll
- monitor flash write_image erase main.bin 0x08000000
Add the run commands below.
- monitor soft_reset_halt
- monitor wait_halt
- monitor poll
- thbreak main
I didn’t change anything in the Source or Environment tabs.
In the Common tab, check the box to add this to the debug favorites menu. Be sure to click the apply button, and then the close button.
If you click the down arrow next to the bug symbol, you should be able to see the new debug configuration.