Configure VSCode Debugger

1️⃣ Download pinetime-rust-mynewt according to the instructions in the article “Build and Flash Rust+Mynewt Firmware for PineTime Smart Watch” under the sections (Windows or macOS)…

“[Option 1] Install PineTime Build Tools on Windows”, or

“[Option 2] Install PineTime Build Tools on macOS”

2️⃣ Install and launch VSCode. For Raspberry Pi, use the Community Build of VSCode.

Click File → Open Workspace

Select the workspace.code-workspace file inside pinetime-rust-mynewt

Install all recommended extensions when prompted. This installs the Cortex Debug VSCode Extension (which is defined in .vscode/extensions.json )

3️⃣ We’ll tell VSCode where to find our source files during debugging…

Click File → Add Folder To Workspace

Select the source folder for firmware to be debugged: PineTime-apps

4️⃣ Edit the debugger configuration file .vscode/launch.json

For ST-Link: Copy the contents of .vscode/launch-nrf52.json to .vscode/launch.json

For Raspberry Pi: Copy the contents of .vscode/launch-nrf52-pi.json to .vscode/launch.json

This selects the debugging interface that we’ll be using with OpenOCD: ST-Link or Raspberry Pi (SWD over SPI).

Note: The launch.json file is overwritten whenever we run pinetime-rust-mynewt/scripts/build-app.sh . So be careful not to build the Rust+Mynewt firmware, and always back up launch.json !

5️⃣ In .vscode/launch.json , set the ELF executable to be debugged…

// Application Executable to be flashed before debugging "executable": "/Users/Luppy/PineTime/PineTime-apps/apps/pinetime/bin/pinetime/PineTime.elf",

Copy the path from the output of the RIOT-OS build earlier.

Why is the ELF file needed? The debugger (GDB) will flash the ELF executable into the flash ROM. It also reads the debug symbols from the ELF file.

6️⃣ In .vscode/launch.json, set additional breakpoints if needed.

Comment out the break lines as shown below…

"postLaunchCommands": [

// After loading the Application, run these gdb commands

// "break main", // Break at main()

// "break __assert_func", // Break for any assert failures

// "break os_default_irq" // Break for any unhandled interrupts

],

By default, the debugger will always break at first line of code in the Reset Handler, which is the first function that will be executed when PineTime powers up.

If you wish to break at the first line of the main() function, uncomment the line "break main"

The break for assert_func will brake execution whenever an assertion fails on Mynewt OS. Good for checking the stack and understanding why it failed. If there is a similar assertion function for your firmware, uncomment this line and replace __assert_func by the function name.

The break for os_default_irq is for unhandled interrupts. If you know the function that handles unhandled interrupts on your firmware, uncomment the line and replace os_default_irq by the function name.

Here’s the .vscode/launch.json debugger configuration I used for debugging RIOT-OS on PineTime…

7️⃣ Set the OpenOCD path in .vscode/settings.json