How to debug a Portenta M7 with an Arduino project and GDB?

× Not what you are looking for? Did you want USB/WiFi debug, trace and performance monitoring instead?

The Portenta H7 M7 has support for an in-built debugger "Monitor for Remote Inspection" (MRI).

This can now be used out of the box in vMicro in a few simple steps, with no additional hardware.


Note IconNote:

This is available from vMicro versions 2021.0606.13 onwards, in conjunction with the "Arduino Mbed OS Portenta Boards" platform.

Debugger Connections

Simply connect your Portenta H7 M7 to your PC via the USB(C) cable as normal:

Portenta H7 USB Connection

Software Setup

Ensure you have Visual Studio and the vMicro Extension Installed

Open your Sketch, and select the options from vMicro > Debugging as shown below:

Portenta Debug Toolbar Settings


NOTE - as the debugger uses the SerialUSB interface of the Portenta, you will have to remove all calls to Serial from your code. Alternatively use a seperate serial interface for your messages.

You will need to add a couple of additions to your sketch (also in output window on debugger select):

  1. Ensure you have the Debug Configuration selected from the Configuration Manager Window
  2. Check the COM Port on the Debug Toolbar is correct.
  3. Include the ThreadDebug.h file at the top of your sketch by adding the ThreadDebug Library
  4. Add the below code above setup():
    UsbDebugCommInterface  debugComm(&SerialUSB);
    ThreadDebug            threadDebug(&debugComm, DEBUG_BREAK_IN_SETUP); 
    // Set to DEBUG_NO_BREAK_IN_SETUP to prevent automatic stop in setup
  5. If you know where you want the first breakpoint in your code, add it now
  6. Double Tap the Reset button to put the board into DFU Mode (Green LED fades in and out)
  7. Check the COM Port selected for Upload is still correct, and build and upload the code to the board
  8. To start the debugging session use "Debug > Attach to Process" (your code does not start executing until the debugger has attached)
Portenta Debugging in vMicro and Visual Studio

Congratulations - you should have the debugger running, and further windows can be opened from the "Debug > Windows" menu once you have started debugging