Skip to content

Update debugger tutorial for Arduino IDE >=2.0.3 #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 7, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,23 @@ Now we are ready to start debugging our sketch. Connect the power to the MKR boa

Then create or open the sketch that you want to debug. If you don't already have a sketch in mind, feel free to use the example sketch found at the end of this tutorial.

Now go to the folder where the sketch is located. Add a `.json` file in the same folder as your sketch and name it `debug_custom.json`. The easiest way would be to create a text file and rename it `debug_custom.json`. In the `.json` file, add the following lines:
Now go to the folder where the sketch is located. Add a `.json` file in the same folder as your sketch and name it `debug_custom.json`. The easiest way would be to create a text file and rename it `debug_custom.json`. In the `.json` file, add the following lines:

```arduino
{
"servertype": "jlink",
"device": "ATSAMD21G18",
"interface": "SWD",
"serverpath": "C:/Program Files (x86)/SEGGER/JLink/JLinkGDBServer"
"servertype": "jlink",
"device": "ATSAMD21G18",
"interface": "SWD",
"serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL"
}
```

The `"serverpath"` needs to be changed to the location where you installed the J-link package in the previous step. When this is done, click on the debugging icon.
The `"serverpath"` field needs to be set to the path of the "J-Link GDB Server CL" tool executable file that is located under the folder of the J-Link package you installed in the previous step. The file is named:

- **If you are using Windows:** `JLinkGDBServerCL.exe`
- **If you are using Linux or macOS:** `JLinkGDBServer`

When you have finished creating the `debug_custom.json` file, click on the debugging icon.

![Start debug feature in Arduino IDE 2.0](assets/mkr_jlink_IDE_debugging_button.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ Once your program has been uploaded, we can start using the debugger.

Let's begin by creating something called a **breakpoint**. Breakpoints are used to stop the program execution at a specific line (or when a specific condition is verified). We can use multiple of these in a program (the number is variable depending on the processor).

In this example, we are going to set a breakpoint for **line 33** and **line 36**. These are set by clicking to the left of the line numbering in the editor.
In this example, we are going to set a breakpoint for **line 33** and **line 35**. These are set by clicking to the left of the line numbering in the editor.

![Navigating the Debugger.](assets/debugger-img03.png)

We can now go through our code, step by step.
The first (automatic) stop will be triggered by the **Debugger** itself, and it will be a standard entry-point, ignore that for now.
The debugger will automatically stop at the first breakpoint it reached.

Let's continue, by clicking on the **Play/pause** button (**Continue**). The program will now run to the first breakpoint, line 33. If we click it again, it will jump to line 36 (the lines 34 and 35 will still be executed but we won't see that). Clicking the **Play/pause** button again will continue running the program which will pause at its next breakpoint, line 33. We're in the main loop, after all.
Let's continue, by clicking on the **Play/pause** button (**Continue**). The program will now run to the next breakpoint (e.g., line 35). If we click it again, it will jump to line 33 (the other lines in the program sequence will still be executed but we won't see that). Clicking the **Play/pause** button again will continue running the program which will pause at its next breakpoint, line 35. We're in the main loop, after all.

![Going between breakpoints.](assets/playpause.gif)

Expand Down