Using the Segger J-Link Debugger with the Portenta Breakout

This tutorial teaches you how to set up the board with the Segger J-link debugger.

Overview

This tutorial will show you how to debug an Arduino sketch using the Portenta H7, Portenta Breakout board and the Segger J-link device. Using the Arduino IDE we will build a version of the sketch so that it can be used in Segger's Ozone debugger.

Goals

  • How to debug an Arduino sketch
  • How to connect the Portenta breakout to the Segger J-link device
  • How to use the Segger J-link and Portenta with the Ozone debugger

Required Hardware and Software

Instructions

1. Setting up with the Arduino IDE

First, if you haven't already, install the Arduino IDE and connect your Portenta H7. When uploading a sketch to your Arduino board with the Arduino IDE, it will build an .ELF file of the sketch. We will need this file to debug in Ozone in the next step. To easily find the file path to the .ELF file, we can enable the show verbose output option in the Arduino IDE. To do this, open up the preferences under File > Preferences in the Arduino IDE.

Preferences in Arduino IDE
Preferences in Arduino IDE

When you have the preferences window open, look for the Show verbose output during: compilation option and make sure that the checkbox is ticked.

Arduino IDE preference window
Arduino IDE preference window

Now we are ready to upload the script that we want to debug. If you don't have a sketch to test, you can use the example sketch found in the Conclusion section of this tutorial.

When we upload the sketch with the Arduino IDE, we need to know where the .ELF file will be saved. Build your project in the Arduino IDE, and highlight the output directory, it could look for example like C:\Users\profile\AppData\Local\Temp\arduino_build_815037. Note down the path for easier access in the next step.

The .elf file path in Arduino IDE
The .elf file path in Arduino IDE

2. Connecting the Boards and Device

First, connect the Portenta H7 to the Breakout. To begin using the J-link device with the Portenta H7 and Breakout, you will need a J-link adapter, sold separately. The cable for the adapter needs to be connected as indicated in the illustration below, with the cable going inwards towards the H7 and center of the Breakout. On the J-link side, connect the cable going away form the J-link device on the adapter. Now you just need to connect the USB cable from the J-link to your computer and the USB cable from the Portenta H7 that is on the Breakout to your computer.

Illustration of connection
Illustration of connection

3. Using the Setup with Segger Ozone

Download and install Segger's Ozone debugger. If you are on windows, make sure to also download the J-Link Software and Documentation Pack for Windows.

When starting Ozone, make sure to enter the correct CPU into the settings box. The Portenta H7 uses the STM32H747XI, you can then chose between the M4 and M7 core on the Portenta.

Segger Ozone J-Link cpu settings
Segger Ozone J-Link cpu settings

Continue to the next step. Here we need to change the Target Interface to SWD. The Portenta H7 does not support JTAG. Then select your J-link device in the list of emulators and head to the next page.

Segger Ozone J-Link connection settings
Segger Ozone J-Link connection settings

Now you get to the window that asks you to select the program to be debugged, this is where you load the project's .ELF file. With the temporary output path that we noted before. Navigate to the correct directory, and select the .ELF file.

Temporary .ELF file location
Temporary .ELF file location

When the setup is finished Ozone will open the file containing the main function. You will note that this is not the .ino sketch you wrote since this is an abstraction layer generated by the IDE. To open our .ino sketch we need to go to Find > Find source file in the top toolbar.

Find source file in Ozone
Find source file in Ozone

In the little window that appears, type ".ino". You should now be able to see the file, select the file and it will open it in Ozone.

Find source file window
Find source file window

Now you are ready to start debugging. Simply go to Debug > Download & Reset Program to start debugging your sketch, you can add breakpoints , inspect variables, halt the execution and more.

Start debugging in Ozone
Start debugging in Ozone

For more information about the features present in the Ozone debugger, please go here.

Conclusion

In this tutorial, you learned how to connect your Portenta H7 and Breakout board to a J-link device and use it with the Ozone debugger. We also went through how to create a file with Arduino IDE that can be debugged in Ozone. And finally how to use the Ozone debugger to debug an Arduino sketch.

Example Sketch

int counter1 = {0}; int counter2 = {0}; unsigned long timer1 = {0}; unsigned long timer2 = {0}; int period1 = 1000; int period2 = 500; void setup() { // Set the LED pins up as OUTPUT pinMode(LEDR, OUTPUT); pinMode(LEDG, OUTPUT); pinMode(LEDB, OUTPUT); digitalWrite(LEDR, HIGH); digitalWrite(LEDG, HIGH); digitalWrite(LEDB, HIGH); } void loop() { if (millis() >= timer1 + period1) { timer1 = millis(); counter1++; digitalWrite(LEDB, !digitalRead(LEDB)); } if (millis() >= timer2 + period2) { timer2 = millis(); counter2++; digitalWrite(LEDR, !digitalRead(LEDR)); } }

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.