Using a debugger with Nucleo G071RB

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.

Debugging works with the final version, thanks!

Is there any way to make it work without separately starting the GDB server?

Still getting an occasional:
Failed to get Stack Trace: Selected thread is running. (from stack-list-frames --thread 1 0 20)
and
Unable to get thread information: Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again. (from thread-info 1)
but that’s probably a topic for another thread.

Uh, with which exact OpenOCD command? Does it also work without a -c "reset_config... command?

Yes, works with just the openocd -f interface\stlink.cfg -f target\stm32g0x.cfg

Weird when it didn’t before :open_mouth:

Btu that should mean no extra configuration should be needed.

Can you test with just the platformio.ini

[env:nucleo_g071rb]
platform = https://github.com/maxgerhardt/platform-ststm32.git#patch-2
board = nucleo_g071rb
framework = arduino

?

It sure does :sweat_smile:
I guess we should have started with the upgrade. The platform = https://github.com/maxgerhardt/platform-ststm32.git#patch-2 is the other factor.

Sorry as one final test, it’s still using the latest OpenOCD version.

Please delete the folder C:\Users\<user>\.platformio\packages\tool-openocd again and start debugging again. PlatformIO will redownload / unpack its (older) OpenOCD version again. Does it still work? Otherwise the STM32 platform also needs a OpenOCD upgrade.

Works the same with PlatformIO’s 0.10.0+dev-00378-ge5be992df and the latest 0.11.0-00155-ge392e485e.

Thanks, PR for board manifest update is in the queue at Fix onboard STLink uploading and debugging for Nucleo-Gxxx series by maxgerhardt · Pull Request #509 · platformio/platform-ststm32 · GitHub.

1 Like