You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/02.hero/boards/uno-r4-minima/tutorials/debugger/debugger.md
+24-16Lines changed: 24 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,13 @@ tags:
8
8
author: 'Hannes Siebeneicher'
9
9
---
10
10
11
-
Debugging is the process of identifying and fixing errors in your code. It’s a vital skill for anyone writing code especially when dealing with microcontrollers like those on your Arduino. There are different types of debugging that are covered [here](/learn/02.microcontrollers/04.debugging/debugging.md).
11
+
Debugging is the process of identifying and fixing errors in your code. It’s a vital skill for anyone writing code especially when dealing with microcontrollers like those on your Arduino. As with everything, debugging can be done at different levels, you can read up on the topic [here](/learn/microcontrollers/debugging).
12
12
13
-
But generally speaking, debugging is used to inspect the code at different points in time, check the value of variables, and read specific memory addresses to make sure information is being passed on as intended. This is especially helpful when creating complex projects but even as a beginner, it can be helpful to know the basics of debugging, consequently saving you time and energy when trying to find the little annoying error causing your code to go bananas.
13
+
In this context, debugging is a term used to describe the process of inspecting the code at different points in time.
14
+
15
+
An analogy that is often used is to think of it as "stepping into" the code, grabbing full control of the clock and walking through it line by line, checking the value of variables as you go, and reading specific memory addresses to make sure information is being passed on as intended.
16
+
17
+
This is especially helpful when creating complex projects, but even as a beginner, it can be helpful to know the basics of debugging, consequently saving you time and energy when trying to find the little annoying error causing your program to break down.
14
18
15
19
This article covers the basic steps for debugging the UNO R4 Minima using the SWD pins and a J-Link® debugger.
16
20
@@ -40,7 +44,7 @@ Debugging your Arduino project allows you to dive deep into your code and troubl
40
44
41
45
Connecting the J-link to your UNO R4 Minima is super easy because there are special pins for debugging labeled as **SWD** pins.
42
46
43
-

47
+

44
48
45
49
Your J-link should come with a cable included and if you look closer you will see that one side is marked with red, indicating the orientation of the cable. The red side of the cable should be on the same side as the VCC pin on the SWD pad. To know the exact orientation of your cable be sure to check the respective documentation or datasheet of your debugger but you can start with the orientation as shown below and if it doesn't work you can try placing it differently until you get a working connection. Once we start using the debugger software in the following steps you will know if the cable is placed correctly.
46
50
@@ -50,51 +54,55 @@ Your J-link should come with a cable included and if you look closer you will se
50
54
51
55
First, if you haven't done it yet, install the [Arduino IDE](https://www.arduino.cc/en/software) and connect your UNO R4 Minima. 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 steps. To easily find the file path of 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.
52
56
53
-

57
+

54
58
55
59
When you have the preferences window open, look for the **Show verbose output during: compilation** option and make sure that the checkbox is ticked.
56
60
57
-

61
+

58
62
59
63
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 any example sketch found in the IDE.
60
64
61
65
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 should look for example like `C:\Users\profile\AppData\Local\Temp\arduino_build_815037`. Note down the path for easier access in the next step.
62
66
63
-

67
+

64
68
65
69
### Using the Setup with Segger® Ozone
66
70
67
-
Download and install [Ozone debugger](https://www.segger.com/downloads/J-link/#Ozone). If you are on Windows, make sure to also download the [J-Link Software and Documentation Pack for Windows.](https://www.segger.com/products/debug-probes/j-link/tools/j-link-gdb-server/about-j-link-gdb-server/)
71
+
Download and install [Ozone debugger](https://www.segger.com/products/development-tools/ozone-j-link-debugger/). If you are on Windows, make sure to also download the [J-Link Software and Documentation Pack for Windows.](https://www.segger.com/products/debug-probes/j-link/tools/j-link-gdb-server/about-j-link-gdb-server/)
68
72
69
73
When starting Ozone, make sure to enter the correct CPU into the settings box. The UNO R4 Minima uses the **R7FA4M1AB**.
70
74
71
-

75
+

72
76
73
77
Continue to the next step. Here you need to change the **Target Interface** to **SWD**. Then select your J-Link device in the list of emulators and head to the next page.
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.
In the 'optional settings' dialog, set both options 'Initial PC' and 'Initial Stack Pointer' to 'Do not set' as it would skip the Arduino bootloader, otherwise this may prevent the sketch from running correctly.
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.
86
90
87
-

91
+

88
92
89
93
In the little window that appears, type ".ino". You should now be able to see the file, select the file and open it in Ozone.
Covering all features of Ozone would go beyond the scope of this tutorial but to give you a starting point we will show you how to add a breakpoint and hold your sketch at that point. As mentioned above a breakpoint is an intentional stopping or pausing place at a specific point in the code. You can add them by clicking the sidebar next to your sketch, and you should see a red dot appear. You have now set a breakpoint.
98
+
99
+

92
100
93
-
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 much more.
101
+
Now you are ready to start debugging. Simply go to **Debug > Download & Reset Program** to start debugging your sketch.
94
102
95
-

103
+

96
104
97
-
For more information about the features present in the Ozone debugger, please go [here.](https://www.segger.com/products/development-tools/ozone-j-link-debugger/technology/application-debugging/)
105
+
You will see how your code is executed and **stopped** at the line you set the breakpoint. You can set as many breakpoints as you want, depending on where you want to stop your code. For more information about the features present in the Ozone debugger, please go [here.](https://www.segger.com/products/development-tools/ozone-j-link-debugger/technology/application-debugging/)
0 commit comments