Skip to content

Commit 0432689

Browse files
committed
chore(debug): review debug section
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 8a04851 commit 0432689

24 files changed

+56
-83
lines changed

Getting-Started_V1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
> [!WARNING]
2-
> This page is dedicated to Legacy Arduino IDE (1.8.X).
2+
> This page is dedicated to Legacy Arduino IDE (1.8.X) usage.
33
> Legacy Arduino IDE (1.8.X) can be used only with core version prio to 2.8.0.
44
> For core version higher or equal to 2.8.0, see the [[Getting Started]]
55

_dev/How-to-debug.md

Lines changed: 55 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
11
# How to debug
22

33
Below, some ways to debug:
4+
* [Arduino IDE 2 (Supported and recommended way)](#arduino-ide-2-supported-and-recommended-way)
45
* [Eclipse and Sloeber](#eclipse-and-sloeber)
56
* [PlatformIO](#PlatformIO)
67
* [Visual Studio and VisualGDB](#visual-studio-and-visualgdb)
78
* [Visual Studio Code and Arduino extension](#Visual-Studio-Code-and-Arduino-extension)
89
* [Command line GDB](#command-line-gdb)
910

1011
> [!WARNING]
11-
> **Only the Arduino IDE is officially supported.**
12+
> **Only the Arduino IDE 2 is officially supported.**
1213
14+
# Arduino IDE 2 (Supported and recommended way)
15+
16+
> [!Note]
17+
> Requires a [ST-Link/V2](https://www.st.com/content/st_com/en/products/development-tools/hardware-development-tools/hardware-development-tools-for-stm32/st-link-v2.html) or [ST-Link/V3](https://www.st.com/en/development-tools/stlink-v3set.html) device connected to the PC over USB and to the board via the SWD interface.
18+
19+
1. If not already done, [[Getting-Started#Install-Arduino.cc-IDE]]
20+
21+
2. Configure the IDE to the desired board. Here the [Nucleo L476RG](http://www.st.com/en/evaluation-tools/nucleo-l476rg.html) which already includes a ST-Link.
22+
23+
See [[Getting-Started#configuring-ide]]
24+
25+
3. Open the Blink sketch from the "**File> Examples > 01.Basics > Blink**".
26+
27+
4. Select the "**Optimize for debugging**" in the "**Sketch**" menu:
28+
29+
[[/img/debug/arduino/OptimizeDebug.png|alt="Optimize for debugging"]]
30+
31+
5. Click the upload button
32+
33+
See [[Getting-Started#upload-method]] to change the upload method.
34+
35+
[[/img/v2/Upload.png|alt="Upload"]]
36+
37+
6. Click the start debugging button:
38+
39+
[[/img/debug/arduino/startDebug.png|alt="Start debugging"]]
40+
41+
[[/img/debug/arduino/debugSession.png|alt="Debugging session"]]
42+
43+
> [!TIP]
44+
> Refer to official documentation to see how [Using the Debugger](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-debugger/#using-the-debugger).
1345
1446
# Eclipse and Sloeber
1547
## 1 - Software requirements
@@ -29,11 +61,11 @@ The GNU MCU Eclipse plug-ins provide multiple tools based on the GNU toolchains
2961

3062
Launch Eclipse, go to _**“Help > Eclipse Marketplace”**_ and search for the _**"GNU MCU plug-in"**_. <br>
3163

32-
[[/img/EclipseMP.png|alt="EclipseMarketPlace"]]
64+
[[/img/debug/sloeber/EclipseMP.png|alt="EclipseMarketPlace"]]
3365

3466
In the tree view, expand _**“GNU MCU Eclipse {version}”**_ and uncheck all items. In previous versions, you had to choose the OpenOCD entry. Since there is no such entry, you cannot select it. OpenOCD will automatically be installed. Confirm and follow the recommended instructions. Then restart Eclipse.<br>
3567

36-
[[/img/EclipseMPGNU.png|alt="EclipseMarketPlaceGNU"]]
68+
[[/img/debug/sloeber/EclipseMPGNU.png|alt="EclipseMarketPlaceGNU"]]
3769

3870
To finish the OpenOCD plug-in configuration, and for a simpler integration, install OpenOCD binaries by following the [“How to install the OpenOCD binaries”](https://gnu-mcu-eclipse.github.io/openocd/install/
3971
) tutorial. This Guide will tell you to extract the openocd binaries to a specific path (Windows).
@@ -42,19 +74,19 @@ To finish the OpenOCD plug-in configuration, and for a simpler integration, inst
4274
From the Eclipse main tab, go to _**“Help > Eclipse Marketplace”**_ and search for _**Sloeber**_. <br>
4375
Download the _**"Sloeber plugin"**_ , follow the recommended instructions and restart Eclipse. <br>
4476
By now, the main tab should look like the following:
45-
[[/img/SloeberMenu.png|alt="SloeberMenu"]]
77+
[[/img/debug/sloeber/SloeberMenu.png|alt="SloeberMenu"]]
4678

4779
### 1.3 - Install STM32 Cores
4880
Open _**“Arduino > Preferences”**_.<br>
4981
In the tree view that pops up, go to _**“Arduino > Third party index url’s”**_ and add the STM32 support package URL:
5082

5183
https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/main/package_stmicroelectronics_index.json
5284

53-
[[/img/UrlIndex.png|alt="UrlIndex"]]
85+
[[/img/debug/sloeber/UrlIndex.png|alt="UrlIndex"]]
5486

5587
Hit _**“Apply and Close”**_ then re-open the _**“Arduino > Preferences”**_ menu. The STM32 Core is now available in the _**“Platforms and Boards”**_ menu.
5688

57-
[[/img/CoreInstall.png|alt="CoreInstall"]]
89+
[[/img/debug/sloeber/CoreInstall.png|alt="CoreInstall"]]
5890

5991
Select the latest core version and hit _**“Apply and Close”**_.
6092

@@ -73,7 +105,7 @@ Complete the Arduino required information (board type, port number …) form and
73105

74106
Do not forget to select the _**“Platform folder”**_ that corresponding to the STM32 Core version previously installed.
75107

76-
[[/img/ProjectConfig.png|alt="ProjectConfig"]]
108+
[[/img/debug/sloeber/ProjectConfig.png|alt="ProjectConfig"]]
77109

78110
> [!NOTE]
79111
> If you plan to debug, select "_**Debug (-g)**_" from the "_**Optimize**_" list else you will not have debugging symbols.
@@ -82,7 +114,7 @@ From there, you can create your own sketch or use pre-configured examples. <br>
82114
In this case, we will try the _**“Blink”**_ example.<br>
83115
From the _**“select code”**_ bar, apply _**“Sample sketch”**_ and then choose _**“Examples > 01.Basics > Blink”**_ and _**“Finish”**_.
84116

85-
[[/img/BuiltInExamples.png|alt="BuiltInExamples"]]
117+
[[/img/debug/sloeber/BuiltInExamples.png|alt="BuiltInExamples"]]
86118

87119
> [!NOTE]
88120
> As the GCC ARM Toolchain is provided by the STM32 core, you do not have to download it in order to program your board.
@@ -119,7 +151,7 @@ Alternatively you can also reach the debug configurations menu by right-click on
119151
From the _**“Run”**_ menu, select _**“Debug Configurations”**_.
120152
Double-click on **_“GDB OpenOCD Debugging”_** to create a new configuration and set the configuration name.
121153

122-
[[/img/DebugMenu.png|alt="DebugMenu"]]
154+
[[/img/debug/sloeber/DebugMenu.png|alt="DebugMenu"]]
123155

124156
Move to the _**“Debugger”**_ tab in order to configure OpenOCD and GDB.
125157

@@ -139,7 +171,7 @@ The _**“Actual executable”**_ field show the full executable path.
139171
-s "${openocd_path}/../scripts" -f interface/stlink-v2-1.cfg -f target/stm32f0x.cfg
140172
```
141173

142-
[[/img/OCDConfig.png|alt="OpenOCD-config"]]
174+
[[/img/debug/sloeber/OCDConfig.png|alt="OpenOCD-config"]]
143175

144176
> [!IMPORTANT]
145177
> Do not forget to replace the config files with the version of the board you are using.
@@ -154,7 +186,7 @@ In the _**“Debugger”**_ tab, scroll to the GDB Client setup field.
154186

155187
By now, the _**“Debugger”**_ tab should look like the following:
156188

157-
[[/img/DebugConfig.png|alt="DebugConfig"]]
189+
[[/img/debug/sloeber/DebugConfig.png|alt="DebugConfig"]]
158190

159191
Move to the _**“Startup”**_ tab, scroll until the _**“Run/Restart Commands”**_ fields and add:<br>
160192
```
@@ -172,11 +204,11 @@ If the configuration process runs correctly, you will be able to see the debug c
172204

173205
If you are facing problems with messages like "binary not found" you should try to click on the drop down menu and then on your configuration instead of just click on the debug icon.
174206

175-
[[/img/DebugConsole.png|alt="DebugConsole"]]
207+
[[/img/debug/sloeber/DebugConsole.png|alt="DebugConsole"]]
176208

177209
Now, you can easily debug your code by using the Eclipse debug features including running step-by-step mode, live breakpoint, inspecting memory access, live view of variable contents and many more.
178210

179-
[[/img/DebugView.png|alt="DebugView"]]
211+
[[/img/debug/sloeber/DebugView.png|alt="DebugView"]]
180212

181213

182214
# PlatformIO
@@ -198,80 +230,18 @@ This [tutorial](https://visualgdb.com/tutorials/arduino/stm32/) shows how to dev
198230

199231
## 1. Install
200232

201-
See [prerequisites](https://github.com/microsoft/vscode-arduino/blob/main/README.md#prerequisites).
202-
203-
* Download and install [Visual Studio code](https://code.visualstudio.com/)
204-
* Install Arduino extension from Microsoft: [vscode-arduino](https://github.com/Microsoft/vscode-arduino)
205-
206-
[[/img/VSCodeArduinoExtension.png|alt="VSCode Arduino Extension"]]
207-
208-
## 2. Configuration
209-
210-
Some settings are required for [vscode-arduino](https://github.com/Microsoft/vscode-arduino) extension.
211-
In your user [`settings.json`](https://code.visualstudio.com/docs/getstarted/settings), add:
212-
```
213-
"arduino.path": "c:\STM32\arduino\arduino-1.8.9-windows\arduino-1.8.9\",`
214-
"arduino.additionalUrls": "https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json"
215-
```
216-
217-
> [!TIP]
218-
> For further options see [vscode-arduino Readme](https://github.com/microsoft/vscode-arduino/blob/main/README.md)
219-
220-
Now, Ensure STM32 core installation is installed by opening the "**Arduino Board Manager**". Open the Command Palette (<kbd>F1</kbd> or <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>) and search/select **Arduino: Board Manager**, `STM32 Cores` should be listed in `Contributed` Type:
221-
222-
[[/img/VSCodeBoardManager.png|alt="VSCode Board Manager"]]
223-
224-
## 3. Build an example
225-
226-
### 3.1 Board Configuration
227-
228-
Firstly, it is necessary to choose a board to build.
229-
230-
Open the "**Arduino Board Configuration**". Open the Command Palette (<kbd>F1</kbd> or <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>) and search/select **Arduino: Board Config**
231-
232-
[[/img/VSCodeBoardConfig.png|alt="VSCode Board Config"]]
233-
234-
In this example, [Nucleo L476RG](http://www.st.com/en/evaluation-tools/nucleo-l476rg.html).
235-
236-
### 3.2 Choose an example
237-
238-
Open the "**Arduino Examples**" by opening the Command Palette (<kbd>F1</kbd> or <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>) and search/select **Arduino: Examples**
239-
240-
[[/img/VSCodeArduinoExamples.png|alt="VSCode Arduino Examples"]]
241-
242-
For this example, Blink has been selected, then you will have this:
243-
244-
[[/img/VSCodeBlinkExample.png|alt="VSCode Blink Example"]]
245-
246-
### 3.3 Build and upload
247-
248-
Opening the Command Palette (<kbd>F1</kbd> or <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>) and search/select **Arduino: Verify** to only build or **Arduino: Upload** to build and upload.
249-
250-
[[/img/VSCodeUpload.png|alt="VSCode Upload"]]
251-
252-
## Enhance C/C++ code browsing
253-
254-
[[/img/under-construction.jpg|alt="Under construction"]]
255-
256-
## 4. Debug configuration
257-
258-
### 4.1. Install
259-
* Install Cortex-Debug from Marus25 (@Marus): [Cortex-Debug](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug)
260-
261-
[[/img/VSCodeCortexDebugExtension.png|alt="VSCode Cortex-Debug Extension"]]
262-
263-
* Install OpenOCD
233+
See the Visual Studio Code extension for Arduino [README.md](https://github.com/microsoft/vscode-arduino/blob/main/README.md).
264234

265235
# Command Line GDB
266236

267-
## 5. Command Line GDB
268-
### 5.1. Requirements
237+
## 1. Command Line GDB
238+
### 1.1. Requirements
269239
* Linux, tested in Ubuntu 18.04
270240
* Requires Arduino IDE with stm32duino installed
271241
* STLink compatible dongle
272242
* assuming Blue Pill board, but it probably work with any other STM32 board
273243

274-
### 5.2. Compiling for Debug
244+
### 1.2. Compiling for Debug
275245
* In the Arduino IDE, go to menu File->Preferences and check compilation verbose
276246
* Open your code, for example, the blink code
277247
* In the Arduino IDE, go to Tools->Optimize->Debug. This will include -g in the compilation process, including debug symbols
@@ -321,7 +291,7 @@ Application is running
321291
Start operation achieved successfully
322292
```
323293

324-
### 5.3 Debugging with Command Line GDB
294+
### 1.3 Debugging with Command Line GDB
325295

326296
* Open a terminal and run `st-info` to start gdbserver
327297
* Open another terminal and run `~/.arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/arm-none-eabi-gdb /tmp/arduino_build_742171/Blink-stm32.ino.elf` to run the gdb used by stm32duino. Note that the path to the ELF file was figure out in the compilation messages in the Arduino IDE, shown in the previous section.
@@ -349,7 +319,10 @@ c
349319
c
350320
```
351321

352-
### 5.4 Debugging with GUI GDB
322+
### 1.4 Debugging with GUI GDB
353323

354324
* It is also possible to debug with GUI, such as `ddd`. It requires software installation with the command `sudo apt-get install -y ddd`.
355-
* To run `ddd`, open a terminal and type `ddd --debugger ~/.arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/arm-none-eabi-gdb /tmp/arduino_build_742171/Blink-stm32.ino.elf`. Note that you must point to the appropriate gdb and ELF file.
325+
* To run `ddd`, open a terminal and type `ddd --debugger ~/.arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/arm-none-eabi-gdb /tmp/arduino_build_742171/Blink-stm32.ino.elf`.
326+
327+
> [!NOTE]
328+
> Check to point to the appropriate gdb and ELF file.

img/VSCodeArduinoExamples.png

-45.4 KB
Binary file not shown.

img/VSCodeArduinoExtension.png

-135 KB
Binary file not shown.

img/VSCodeBlinkExample.png

-104 KB
Binary file not shown.

img/VSCodeBoardConfig.png

-41.6 KB
Binary file not shown.

img/VSCodeBoardManager.png

-45.7 KB
Binary file not shown.

img/VSCodeCortexDebugExtension.png

-166 KB
Binary file not shown.

img/VSCodeUpload.png

-102 KB
Binary file not shown.

img/debug/arduino/OptimizeDebug.png

19.5 KB
Loading

0 commit comments

Comments
 (0)