Debugging With DAPLink + OpenOCD + STM32CubeIDE
Debugging With DAPLink + OpenOCD + STM32CubeIDE
STM32CubeIDE
Visit https://jrcrulida.wordpress.com/2023/07/02/debugging-with-daplink-openocd-stm32cubeide/
for a more updated version of this post.
This post describes the steps in setting up STM32CubeIDE to use DAPLink and
an external OpenOCD installation.
CAVEAT(S):
1. A custom “Launch Group” must be created for every project that will use
the external OpenOCD debugger.
2. I am using Windows but I am assuming that this would work in Linux and
other operating systems as well; the path slashes just needs to be
adjusted.
3. I am also assuming the following:
○ OpenOCD is already extracted/installed somewhere in the computer
and added in the PATH variable,
○ DAPLink drivers are installed (if needed), and
○ STM32CubeIDE is installed.
PRELIMINARY STEPS:
1. Connect the appropriate wires from the DAPLink debugger to the target
board. In this post, I am using a NUCLEO-F411RE with the embedded
ST-Link cut off.
2. Plug in in the DAPLink debugger to the computer. Check the “Device
Manager” for the corresponding COM port for the debugger.
3. DAPLink is supported by OpenOCD. To check if everything is working so
far, open up a terminal and enter the following:
openocd -f interface/cmsis-dap.cfg -f
target/<your_target>.cfg
3. Create a new configuration and give it a name that’s relevant to the project.
Since I am targeting an STM32F411RE microcontroller, I’ll name this
DAPLink_F411RE. In the Location field, enter the full path to the
OpenOCD executable. In the Working Directory field, enter the path to
where the OpenOCD scripts are located. In the Arguments, enter the
following arguments and replace <your_target>.cfg with the
appropriate target config file for your board or chip:
-f interface/cmsis-dap.cfg -f target/<your_target>.cfg .
See the following figure for examples. Then click Apply, then Close.
1. Making sure that the active project is selected, go to the Menu toolbar,
then click Run -> Debug Configurations.
2. In the Debug Configurations Dialog, right-click GDB Hardware Debugging
and click New Configuration as shown in the following figure.
3. Choose an appropriate name for the debug configuration, then click
Apply…BUT NOT CLOSE IT YET.
4. Go to the Debugger tab. Clear the entry in the “GDB Command:” field.
Next, click on the “Variables…” button and select
gnu_tools_for_stm32_compiler_path. After that, append the following to
the newly inserted variable “\arm-none-eabi-gdb.exe”. Set the JTAG
Device to OpenOCD (via socket) and the GDB Connection String to
localhost:3333. Click Apply. The following figure shows how it should look
like (the important parts are in red).
5. Go to the Startup tab. Check “Reset and Delay (seconds): 0“. Check
“Set breakpoint at:” and type main in its field. Leave the rest as is. Then
click Apply.
6. Go to the Source tab. Leave it as it is.
7. Go to the Common tab. Select Shared file: in the Save As option and
leave the default entry. Check the Debug option in the Display in
favorites menu as shown in the following image. Then click Apply and
then click Close.
A launch group is created to automate the running of the program followed by the
debug operation. It is important to note that Steps 2 and 3 in this section needs
to be done in order so that when the launch group is activated, the Run
configuration is executed before the Debug configuration.
1. Go to Menu toolbar, then click Run -> Debug Configurations. Right-click
on Launch Group then create a New Configuration as shown in the
following image.
5. Once this is done, you should get something similar to the following figure.
Then click Apply, then click Close.
1. The Launch Group that was created in PART 3 might or might not show
when the arrow next to the Play icon is clicked. If it is not showing, go to to
Menu toolbar, then click Run -> Debug Configurations. The launch group
should appear the next time you click the arrow next to the Play icon.
2. Go to the Launch Group section and select the launch group created in
PART 3, then click Debug. If all goes well, you will see something similar
to the following image.
3. NOTE: If you run into an error that says “Error address 0x20000000
already has watchpoint 1“, stop the debugging then go to Menu toolbar,
then click Run -> Remove All Breakpoints.
PART 5. CONCLUSION
The open-source DAPLink debugger has been around for a few years and it is a
great tool if you want to a cheap debugger that also has UART functionality. It
works.
OTHER RESOURCES:
● https://usamodelkina.ru/23338-otladka-stm32-s-pomoschju-daplink-v-stm3
2cubeide.html
● https://www.galliumio.com/1531/debugging-with-stm32cubeide/
● https://www.cxybb.com/article/lone5moon/120092024
● https://openocd.org/
● https://openocd.org/doc-release/html/index.html