How to debug an Arduino Sketch with Ozone and J-Link

From SEGGER Wiki
Jump to navigation Jump to search

This article will describe how an Arduino sketch can be debugged with Ozone and J-Link/J-Trace.

Requirements

The following guide will assume the following requirements:

  • J-Link V11 or later.
  • Ozone V3.26b or later
  • 19 pin Cortex-M adapter
  • J-Link software V7.60 or later
  • Arduino IDE V1.8.13 or later (Pro IDE works as well, which is now called Arduino IDE V2)
  • Portenta H7 board
  • Portenta Breakout board

This guide assumes that you already know how to operate the Arduino IDE and how to create sketches. If not, we recommend visiting one of the many Arduino guides that explain this in detail. This guide also assumes that you know how to connect the board to J-Link and how to power both.

How to

In this guide we will use the standard Arduino Blinky application for reference as this easily shows if all steps went well or not.

The resulting application folder with the Ozone project included you can download here for reference: Portenta_H7_Blinky_Test_Ozone.zip

  • In the Arduino IDE set the active board to "Arduino Portenta H7 (M7 Core)
  • Open the blinky sketch via File->Examples->02.Digital->BlinkWithoutDelay
  • Go to File->Preferences and set the option "Show verbose output during compilation"

Arduino IDE Preferences.png

  • Now compile the sketch, e.g. via Sketch->Verify/Compile
  • We now have to locate the elf file output from the sketch, which will be used to debug in Ozone. For this, the verbose console output comes in handy.
  • Scroll to the bottom of the console, there you should find an output as follows. Important is the red outlined part.

Arduino IDE Consoleout.PNG

  • The red rectangle shows the path where the resulting elf file is located. Remember that path.
  • Now start Ozone.
  • Press "Create New Project"
  • Select the STM32H747XI_M7 as target device.
  • Press Next.
  • Set host interface to USB and target interface to SWD.
  • Next.
  • Now press the three dots and navigate to the elf file which was created by the Arduino IDE earlier. In this example it is path C:\Users\Nino\AppData\Local\Temp\arduino_build_695820\BlinkWithoutDelay.ino.elf

Ozone Elf Selection.png

  • Next.
  • Now for both settings Initial PC and stack pointer, select "Do not set". This is important, otherwise the Arduino bootloader will not be executed and the sketch execution will fail or behave unexpected. For more information on why this is necessary, see here.

Ozone PC SP Settings.png

  • Finish.
  • The Ozone project is created and you can debug your application.
  • Start the debug session with F5. Per default, the debugger will halt at main.
  • To continue execution, simply press F5 again.

If everything worked out correctly, the green LED next to the USB-C port should blink.

Troubleshooting

  • Per default, the Arduino IDE will create optimized code which is missing crucial debug information for all debug features of Ozone to work. It is recommended to disable code optimization in the compiler. For information about how to we recommend to contact Arduino support.
  • On most Arduino platforms a sleep mode will be active. Keep in mind that some debug features do not work or only in a limited fashion when sleep modes are active. We recommend disabling them if possible. For information about how to we recommend to contact Arduino support.
  • Serial messages are not supported by Ozone. If you want to display your printf messages from your application, we recommend using an external serial terminal that runs in parallel to Ozone.
  • When using functions like sleep() it is possible that the timer used in that case will not stop when the target device is halted. To avoid this happening, some target devices used on Arduino platforms have special registers that can be set via a debug script which will stop the corresponding timer as expected. Information about if your target device supports such register can be found in the corresponding reference manual of the chip. How to write a debug script that sets that register is explained here: J-Link_script_files