Debugging mbed 5.0 projects with Eclipse and pyOCD

This article explains how to debug an exported MBED project with eclipse and pyOCD. To debug a project you need to first import with mbed-cli, create an eclipse makefile project and finally setup debugger configurations. Below are these steps but in much more detail.

Initial Setup

  • Download the latest version of eclipse with CDT
  • Install the GNU ARM Eclipse plugin
    • Open Eclipse
    • Click the Help menu item and select Install New Software
    • In the Work with box paste the install address and press enter - http://sourceforge.net/projects/gnuarmeclipse/files/Eclipse/updates/
    • The package GNU ARM C/C++ Cross Development Tools should appear. Select it.
    • Click Next repeatedly and accept licence agreements
    • Click Finish. If prompted to restart eclipse select Yes
  • Install tools necessary for makefile projects:
    • GCC ARM Embedded
    • Windows only
      • Add GCC ARM Embedded bin directory to path after installing - Ex. C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2015q2\bin
  • Install python 2.7.9 or above.
    • Windows Only - Make sure to select "Add to path" when installing
  • Install pyOCD by running "pip install pyocd"
  • Install mbed-cli by running "pip install mbed-cli"

Importing to Eclipse and Building

  • Import the desired project with "mbed-cli import <project>"
  • Open Eclipse
  • Click the File menu item, mouse over New and select Makefile Project with Existing Code
    • Paste the location of your project into Existing Code Location
    • Project Name should automatically populate. Update name here if desired.
    • In Toolchain for Indexer Settings select <none>
    • Click Finish to create the project
  • To setup building in eclipse go to the Project menu item and select Properties
    • Select C/C++ Build
    • Unselect Use default build command
    • For Build command enter mbed-cli compile -j0 -t <toolchain> -m <target> -o debug-info.
      • For <toolchain> you can choose between GCC_ARM, ARM and IAR
      • For <target> You can choose any supported mbed target, such as K64F
      • Note - the option -j0 instructs mbed-cli to build with all cores
      • Note - the option -o debug-info instructs mbed-cli to build with debugging information.
    • Click Apply and then click OK. /media/uploads/c1728p9/30_-_build_config_3.png
  • Click the build button in eclipse and verify the project builds successfully.

Setting up debug configuration

The last step before actually debugging it to setup the debug configuration. This only needs to be done once for per project. Once created the configuration can be checked into revision control, allowing anyone else working on the project to use it without needing to go through setup again.

  • On the Run menu item select Debug Configurations... to bring up configurations
  • Right click on GDB pyOCD Debugging and select New
  • Open Main tab and verify Project is correct and C/C++ Application correctly points to the .elf file. /media/uploads/c1728p9/10_-_debug_main_4.png
  • Open Debugger tab
    • In the pyOCD Setup box :
      • Check Start pyOCD locally if it isn't checked already
      • Set Executable: to pyocd-gdbserver or the full path to your installation.
      • Set GDB port: to a free port. The default value of 3333 should work.
    • In the GDB Client Setup box:
      • Set Executable to arm-none-eabi-gdb.exe
      • In Commands: add set mem inaccessible-by-default off if it is not present
    • It should look something like this when configured: /media/uploads/c1728p9/11_-_debug_debugger_3.png
    • Defaults will work in Startup tab
    • Defaults will work in Source tab
    • Open Common tab
      • Under Save as select Shared file. The default name will work. This allows the debug configuration to be saved locally and checked into the current project.
      • In Display in favorites menu box check Debug

Debugging

To start a debugging session open the drop-down menu next to the bug icon and select the debug configuration created earlier. This will automatically load the current program and begin a debugging session. From there you can do things like set breakpoints, set watchpoints, view registers, view disassembly, browse memory and examine the callstack. /media/uploads/c1728p9/21_-_debugging_5.png


6 comments on Debugging mbed 5.0 projects with Eclipse and pyOCD:

01 Aug 2016

Russ

Would this work with GR-PEACH, using Renesas RZAH1 Arm Cortex A9 based CPU with CoAP and ARM Connect functions? Thank you, very repectfully Xtrm Designs LLC

12 Aug 2016

Hello Xtrm Designs LLC,

At the moment you can't unfortunately. Right now pyOCD only supports Cortex-M. Eventually it will support Cortex-A though.

Thanks, Russ

01 Sep 2016

Xtrm Designs,

You could probably use OpenOCD instead of PyOCD to debug Cortex A.

http://openocd.org/

Cheers,

Mike

18 Nov 2016

Hi Russ, the current mbed-cli does not accept "-o debug-info". Can you please let me know if I need to add anything extra to debug with pyocd? Or maybe you could do a quick update on this wiki for what has changed?

Thanks, Dan

29 Nov 2016

The debug-info option was replaced with '- -profile debug'

24 Mar 2017

I was wondering, if it is possible to skip downloading process and force the debugger to attach to an already downloaded program?

The use case for me is that sometimes I have to stop/start debugging sessions w/o actually changing the binary (i.e. different breakpoint placement, forgot to check some assumptions, etc.) And since the code is quite big, I have to wait 20-30 sec while it gets re-downloaded to the probe board.

Please log in to post comments.