Free Eclipse ARM GCC OpenOCD Toolchain for Windows – Part 4: GDB / OpenOCD Debugger

来源:互联网 发布:五轴加工中心的编程 编辑:程序博客网 时间:2024/06/06 01:34

Ångstroms And Algorithms

Sharing Enthusiasm for Embedded Systems

Free Eclipse ARM GCC OpenOCD Toolchain for Windows – Part 4: GDB / OpenOCD Debugger

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.

Contents

  1. Part 1: Introduction
  2. Part 2: ARM GCC
  3. Part 3: Eclipse IDE
  4. Part 4: GDB / OpenOCD Debugger

Download OpenOCD

Start by downloading OpenOCD from Freddie Chopin’s website by following the link below.

http://www.freddiechopin.info/en/download/category/4-openocd

Debug_Download_OpenOCD

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.

Debug_ARMTC_Folder_With_OpenOCD

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:

C:\ARMTC\openocd-0.7.0\bin

Now test the path to OpenOCD by typing the command below in the command window.

openocd-0.7.0 -v

You should get results similar to what is shown below.

Debug_OpenOCD_version_path_test

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-1.2.2.0 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.

C:\Projects\E407Blinker\STM32-E407_blink_FLASH

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

Debug_Launch_OpenOCD_first_try

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.

Debug_Launch_OpenOCD

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.

Debug_Launch_OpenOCD_Block_OpenOCD

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.

Debug_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.

Debug_Install_GDB_Hardware_Debugging

Once again click Next.

Debug_Install_GDB_Hardware_Debugging_Next

Accept the license agreement, and click finish.

Debug_Install_GDB_Hardware_Debugging_Accept_License

Restart Eclipse.

Debug_Install_GDB_Hardware_Debugging_Restart

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.

Debug_Debug_Configurations

Start by giving this configuration a unique name in the Name text box. Click the radio button next to Disable auto build.

Debug_Config_GDBHW_Main

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.

Debug_Config_GDBHW_Debugger

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.

Debug_Config_GDBHW_Startup

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.

Debug_Config_GDBHW_Startup2

There should be nothing to do in the Source tab.

Debug_Config_GDBHW_Source

In the Common tab, place a check next to Debug so that this configuration will be added to the favorites menu.

Debug_Config_GDBHW_Common

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.

Debug_ExtTool

In the Location text box of the main tab, add the path to the OpenOCD executable adapting where necessary to fit your project.

${eclipse_home}\..\openocd-0.7.0\bin\openocd-0.7.0.exe

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

Debug_ExtTool_Main

The refresh tab should already be set up.

Debug_ExtTool_Refresh

In the build tab, ensure that the Build before launch check box is empty.

Debug_ExtTool_Build

The Environment tab should already be properly set.

Debug_ExtTool_Environment

In the common tab, ensure that a check is added next to the option to display this configuration in the external tools menu.

Debug_ExtTool_Common

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.

Debug_Launch_OpenOCD_Server

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.

Debug_Launch_OpenOCD_Server_Console_Output

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.

Debug_Run_Launch_1

At this point the application should be loaded, and the processor should be halted. Next, click the resume button.

Debug_Run_Resume_2

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.

Debug_Run_Suspend_3

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.

Debug_Run_Breakpoints_4

Conclusion

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.

Debug_Install_New_Software

Paste the address of the Zylin update site below in to the work with text box, and click the add button.

http://opensource.zylin.com/zylincdt

Debug_Add_Update_Site

Type Zylin in the name text box of the resulting Add Repository dialog and click OK.

Debug_Add_Repository

Once the plugin loads, push the Select All Button, and click next

Debug_Add_ZylinCDT

Click next on the Install Details dialog.

Debug_Install_Details

Accept the license, and click Next.

Debug_License

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.

Debug_Debug_Configurations

In the resulting debug configurations dialog, double click the Zylin Embedded Debug (Native) option.

Debug_Zylin_Embedded_Debug_Native

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.

Debug_Config_Main_Tab

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.

Debug_Config_Debugger_Tab

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
  • continue

Debug_Config_Commands_Tab

I didn’t change anything in the Source or Environment tabs.

Debug_Config_Source_Tab

Debug_Config_Environment_Tab

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.

Debug_Config_Common_Tab

If you click the down arrow next to the bug symbol, you should be able to see the new debug configuration.

Debug_New_Debug_Config


0 0
原创粉丝点击