Using a debugger with Nucleo G071RB

What is the reason that debugging isn’t supported with the onboard STLink / JLink debugger for G071RB?
Also the code uploading works with the onboard JLink, but not STLink?

The ST-Link upload and debug should be possible by adding

upload_protocol = cmsis-dap
debug_tool = cmsis-dap

to the platformio.ini. Does that work?

(And yes it seems to me the board manifest is indeed just wrong here)

Getting this error when uploading with cmsis-dap.

Error: unable to find CMSIS-DAP device
Error: No Valid JTAG Interface Configured.
*** [upload] Error -1

Does the Nucleo board have a normal unmodified ST-Link firmware on it or did you reflash it to JLink?

Same error with either STLink or JLink.

Well weird that OpenOCD can’t find an adapter. If you’re on Windows you also have the driver installed?

Please open a CLI and run the commands

C:\Users\<user>\.platformio\packages\tool-openocd\bin\openocd -f interface\cmsis-dap.cfg -f target\stm32g0x.cfg
C:\Users\<user>\.platformio\packages\tool-openocd\bin\openocd -f interface\stlink-dap.cfg -f target\stm32g0x.cfg
C:\Users\<user>\.platformio\packages\tool-openocd\bin\openocd -f interface\stlink.cfg -f target\stm32g0x.cfg

while replacing <user> with your actual Windows username.

Hopefully one should say

xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "dapdirect_swd". To override use 'transport select <transport>'.
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : STLINK V2J37M26 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.249738
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : clock speed 1800 kHz
Info : stlink_dap_op_connect(connect)
Info : SWD DPIDR 0x1ba01477
Info : stm32g0x.cpu: hardware has 6 breakpoints, 4 watchpoints
[..]

which indicates a good connection to the chip. You can press Ctrl+C to exit the program again.

If one of them works you can also try my fixes here, by modifying your platformio.ini from

platform = ststm32

to

platform = https://github.com/maxgerhardt/platform-ststm32.git#patch-2

while removing upload_protocol and debug_tool directives.

With STLink firmware, both stlink.cfg and stlink-dap.cfg are successful.

1 Like

Thanks!
With that, upload works fine.
Debugging still doesn’t, here’s the log:

undefinedxPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 2000 kHz
Info : STLINK V2J37M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.266535
Info : stm32g0x.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for stm32g0x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Reading symbols from c:\Users\User\OneDrive\Documents\PlatformIO\Projects\210322-121744-nucleo_g071rb.pio\build\nucleo_g071rb\firmware.elf…
C:\Users\User.platformio\packages\toolchain-gccarmnoneeabi\bin\arm-none-eabi-gdb.exe: warning: Couldn’t determine a path for the index cache directory.
PlatformIO Unified Debugger → Redirecting...
PlatformIO: debug_tool = stlink
PlatformIO: Initializing remote target…
Error: jtag status contains invalid mode value - communication failure
Polling target stm32g0x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms

Hm, OpenOCD reports a failure from the STLink, that is weird. There was a known issue for the mbed-os framework (here), but it seems you’re using Arduino?

Does the issue stay if you unplug and replug the Nucleo board?

Yes, using the Arduino framework.
Re-plugging doesn’t help.

Can you try the following:

  • Press the debug button in VSCode
  • Change over to the “Debug Console” tab in VSCode
  • Start holding the RESET button on the Nucleo
  • after the line PlatformIO: Initializing remote target… has appeared, release the RESET button again

Timing might be a bit tricky. If it works, there is a problem with the reset configuration.

Tried it a few times, no luck. The error message is mostly different (although I’ve gotten this error without pressing the reset button too):

undefinedxPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 2000 kHz
Reading symbols from c:\Users\User\OneDrive\Documents\PlatformIO\Projects\210322-121744-nucleo_g071rb.pio\build\nucleo_g071rb\firmware.elf…
C:\Users\User\.platformio\packages\toolchain-gccarmnoneeabi\bin\arm-none-eabi-gdb.exe: warning: Couldn’t determine a path for the index cache directory.
PlatformIO Unified Debugger → Redirecting...
PlatformIO: debug_tool = stlink
PlatformIO: Initializing remote target…
Error: read version failed

Hmm there aren’t a lot of possibilities left. Your ST-Link firmware is already up-to-date per

and https://www.st.com/en/development-tools/stsw-link009.html#overview.

Either OpenOCD has a problem in that version or there’s a problem with your board. Can you try and do

  1. Download the latest OpenOCD version from Releases · xpack-dev-tools/openocd-xpack · GitHub form (since you’re on Windows, that’s xpack-openocd-0.11.0-1-win32-x64.zip)
  2. Open the folder C:\Users\<user>\.platformio\packages\tool-openocd\
  3. Extract the files of the new release in the above folder, overwriting all the old files
  4. Retry debugging.

The line

xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:29)

Should then also change in the latest version.

Hmm, upgraded, same error.

undefinedxPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-16:44)

Hm…

As one last effort before I declare this as “bug in even latest openocd, needs external review”, we can maybe test if reset methods make absolutely no difference.

Add the bottom of the platformio.ini

debug_tool = custom
debug_server = 
   $PROJECT_PACKAGES_DIR\tool-openocd\bin\openocd
   -f
   interface\stlink-dap.cfg
   -f
   target\stm32g0x.cfg
   -c
   "reset_config none separate"
debug_port = localhost:3333

(docs), While trying all values for reset_config from STM32 + VS Code + mbed upload issue: Error: libusb_open() failed with LIBUSB_ERROR_ACCESS Error: open failed - #12 by maxgerhardt.

If all of them equally do not work, it has no influence.

Sadly I do not have that Nucleo to counter-check, too…

EDIT Fixed wrong env variable.

I think I might have made a oopsie, I had debug_port = COM3 in platformio.ini this whole time. It still doesn’t work, but there are more error lines.

Error: read version failed
2
.pioinit:13: Error in sourced command file:
Remote communication error. Target disconnected.: Success.

Using your config, nothing happens after the build is finished.

Woops indeed, I get the error

Could not launch Debug Server ‘$PROJECT_PACKAGES_DIR/tool-openocd/bin/openocd’. Please check that it is installed and is included in a system PATH
See Redirecting...

Too. This somehow isn’t working as it used to be, although it should be valid per docs.

Please use the platformio.ini

[env:nucleo_g071rb]
platform = ststm32
board = nucleo_g071rb
framework = arduino
debug_tool = custom
debug_server = 
debug_port = localhost:3333

Then open a new terminal window (Windows + R → cmd.exe) and manually execute the command

C:\Users\<user>\.platformio\packages\tool-openocd\bin\openocd -f interface\stlink.cfg -c "transport select hla_swd" -f target\stm32g0x.cfg -c "reset_config none separate"

Whereas <user> has to be replaced again.

If you press the debug button now in VScode, it should try to connect to the openocd server that you have opened in the other shell. You can then the different combinations of the reset_config by aborting OpenOCD (Ctrl+C) and altering the command.

Is debug_server = meant to be empty? I don’t think it likes that:

File “c:\users\User\.platformio\penv\lib\site-packages\platformio\commands\debug\command.py”, line 117, in cli
debug_options = platform.configure_debug_options(debug_options, ide_data)
File “C:\Users\User\.platformio\platforms\ststm32\platform.py”, line 185, in configure_debug_options
server_executable = debug_options[“server”][“executable”].lower()
TypeError: ‘NoneType’ object is not subscriptable

Also I’ve hit the limit on the amount of posts I can make, so I’m just gonna edit this post for replies.

Works for me (with a Nucleo F103RB). Are you using the latest PIO core version? Try opening a CLI again and do pio upgrade --dev.

I’ve upped your trust level so it should be possible.