Closed ChrisIdema closed 2 years ago
TERMINAL:
Waiting for gdb server to start...[2022-07-08T10:58:06.379Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session connected. You can switch to "DEBUG CONSOLE" to see GDB interactions. openocd -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /home/user/git/stm32-template -f /home/user/.vscode/extensions/marus25.cortex-debug-1.4.4/support/openocd-helpers.tcl -f interface/stlink.cfg -f target/stm32g4x.cfg Open On-Chip Debugger 0.11.0 Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html CDRTOSConfigure Info : auto-selecting first available session transport "hla_swd". To override use 'transport select
'. Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD Info : Listening on port 50001 for tcl connections Info : Listening on port 50002 for telnet connections Info : clock speed 2000 kHz Info : STLINK V3J9M3 (API v3) VID:PID 0483:374E Info : Target voltage: 3.319251 Info : stm32g4x.cpu: hardware has 6 breakpoints, 4 watchpoints Info : starting gdb server for stm32g4x.cpu on 50000 Info : Listening on port 50000 for gdb connections Info : accepting 'gdb' connection on tcp/50000 target halted due to debug-request, current mode: Thread xPSR: 0x21000000 pc: 0x0800166a msp: 0x2001bfe0 Info : device idcode = 0x10016479 (STM32G49/G4Axx - Rev 'unknown' : 0x1001) Info : flash size = 512kbytes Info : flash mode : single-bank Info : Unable to match requested speed 2000 kHz, using 1000 kHz Info : Unable to match requested speed 2000 kHz, using 1000 kHz target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08002cbc msp: 0x2001c000 Info : Unable to match requested speed 2000 kHz, using 1000 kHz Info : Unable to match requested speed 2000 kHz, using 1000 kHz target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08002cbc msp: 0x2001c000 Info : Unable to match requested speed 2000 kHz, using 1000 kHz Info : Unable to match requested speed 2000 kHz, using 1000 kHz target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08002cbc msp: 0x2001c000 Info : Unable to match requested speed 2000 kHz, using 1000 kHz Info : Unable to match requested speed 2000 kHz, using 1000 kHz target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08002cbc msp: 0x2001c000 stm32g4x.cpu tpiu stm32g4x.cpu tpiu config (disable | ((external | internal ( | <:port> | -)) (sync <port width> | ((manchester | uart) )) [ ])) tpiu tpiu config (disable | ((external | internal ( | <:port> | -)) (sync | ((manchester | uart) )) [ ])) **Error: invalid subcommand "init" /home/user/.vscode/extensions/marus25.cortex-debug-1.4.4/support/openocd-helpers.tcl:14: Error: in procedure 'CDSWOConfigure' at file "/home/user/.vscode/extensions/marus25.cortex-debug-1.4.4/support/openocd-helpers.tcl", line 14**
DEBUG CONSOLE:
Reading symbols from arm-none-eabi-objdump --syms -C -h -w /home/user/git/stm32-template/../build-stm32-template/cmake-blinky.elf Reading symbols from arm-none-eabi-nm --defined-only -S -l -C -p /home/user/git/stm32-template/../build-stm32-template/cmake-blinky.elf Launching GDB: arm-none-eabi-gdb -q --interpreter=mi2 /home/user/git/stm32-template/../build-stm32-template/cmake-blinky.elf Set "showDevDebugOutput": true in your "launch.json" to see verbose GDB transactions here. Helpful to debug issues or report problems Error: arm-none-eabi-nm failed! statics/global/functions may not be properly classified: Error: spawn arm-none-eabi-nm ENOENT Expecting
nm
next toobjdump
. If that is not the problem please report this. Launching gdb-server: openocd -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /home/user/git/stm32-template -f /home/user/.vscode/extensions/marus25.cortex-debug-1.4.4/support/openocd-helpers.tcl -f interface/stlink.cfg -f target/stm32g4x.cfg Please check TERMINAL tab (gdb-server) for output from openocd Finished reading symbols from objdump: Time: 28 ms Finished reading symbols from nm: Time: 27 ms Reading symbols from /home/user/git/stm32-template/../build-stm32-template/cmake-blinky.elf... 0x08001634 in HAL_GetTick () at /home/user/git/stm32-template/STM32G491RE/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal.c:336 336 } Program stopped, probably due to a reset and/or halt issued by debugger Unable to match requested speed 2000 kHz, using 1000 kHz Unable to match requested speed 2000 kHz, using 1000 kHz target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08002cbc msp: 0x2001c000 Unable to match requested speed 2000 kHz, using 1000 kHz Unable to match requested speed 2000 kHz, using 1000 kHz target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08002cbc msp: 0x2001c000stm32g4x.cpu tpiu
stm32g4x.cpu tpiu config
(disable | ((external | internal (
| <:port> | -)) (sync <port width> | ((manchester | uart)
)) [ ])) tpiu tpiu config (disable | ((external | internal ( | <:port> | -)) (sync | ((manchester | uart) )) [ ])) **invalid subcommand "init" /home/user/.vscode/extensions/marus25.cortex-debug-1.4.4/support/openocd-helpers.tcl:14: Error: in procedure 'CDSWOConfigure' at file "/home/user/.vscode/extensions/marus25.cortex-debug-1.4.4/support/openocd-helpers.tcl", line 14** Program received signal SIGINT, Interrupt. Reset_Handler () at /home/user/git/stm32-template/STM32G491RE/startup_stm32g491xx.s:62 62 ldr r0, =_estack Warning: the current language does not match this frame. Note: automatically using hardware breakpoints for read-only addresses. Temporary breakpoint 1, main () at /home/user/git/stm32-template/STM32G491RE/Core/Src/main.c:90 90 HAL_Init();
So apparently There is an error at line 14 of openocd-helpers.tcl:
tpiu init; # we are allowed to call this multiple times. So, call it just in case
I have no idea what this command does. Uncommenting the lines that give an error gets rid of the error message, but it won't fix the problem. Updating Cortex-Debug to pre-release version didn't help either.
See section 16.6.3 of https://openocd.org/doc/html/Architecture-and-Core-Commands.html I don't understand why your version of openocd would not have this command.
Can you comment tpiu init
out to see if it works? You can make a copy of this file and have your own initialization methods. We describe the openocd-helpers.tcl. in https://github.com/Marus/cortex-debug/wiki/SWO-Output#swo-configuration (item 2)
Instead of commenting it out, could you replace that line with the following
catch {tpiu init}; # we are allowed to call this multiple times. So, call it just in case
I have commented the line out before and it didn't help. I got errors at other lines, which I also commented out until all errors were gone.
I now replaced it with your catch function and I get:
Error: invalid command name "catch{tpiu" in procedure 'CDSWOConfigure'
What I did discover was that if I were to view the SWO trace in STM32CubeProgrammer and then disconnecting the debugger was ITM was probably initialized and subsequent debugging in VsCode didn't freeze at the ITM_SendChar anymore. But still the same errors and no SWO in VsCode.
edit: I forgot to add a space after catch. I now get:
Error: invalid subcommand "
init" stm32g4x.cpu tpiu stm32g4x.cpu tpiu config (disable | ((external | internal (
| <:port> | -)) (sync <port width> | ((manchester | uart) )) [ ])) tpiu tpiu config (disable | ((external | internal ( | <:port> | -)) (sync | ((manchester | uart) )) [ ])) Error: invalid subcommand "names"
To me, it appears that you are using some old version of openocd. Problem with openocd versioning is while it says Open On-Chip Debugger 0.11.0
there are many versions of the same.
The only version I trust for STLink is the one they ship with STM32CubeIDE. You will find openocd in there. The scripts they provide are also more up-to-date. They may ship more than one version, make sure you use the latest.
Also, you can replace the entire contents of the CDSWOConfigure
function with whatever you want. Its job is to configure the TPIU to make it work for your device. It may work. In your case, you did the following equivalent on the command-line
proc CDSWOConfigure { CDCPUFreqHz CDSWOFreqHz CDSWOOutput } {
tpiu config internal - uart off 170000000
itm ports on
}
That is not what we do and it overrides all the frequencies you specified but that is okay as you own the script now.
I checked out a different variant of the exact same version. The openocd version from apt is very old so I had it build from source. But somehow that version is missing some functionality. So Instead I downloaded a binary from here: https://github.com/xpack-dev-tools/openocd-xpack/releases/tag/v0.11.0-4 and set "cortex-debug.openocdPath" to the extracted folder. I now no longer get that error, but I get a different error:
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2022-03-25-17:31)
Licensed under GNU GPL v2 For bug reports, readd http://openocd.org/doc/doxygen/bugs.html CDRTOSConfigure Info : auto-selecting first available session transport "hla_swd". To override use 'transport select
'. Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable} Info : Listening on port 50001 for tcl connections Info : Listening on port 50002 for telnet connections Info : clock speed 2000 kHz Info : STLINK V3J9M3 (API v3) VID:PID 0483:374E Info : Target voltage: 3.315431 Info : [stm32g4x.cpu] Cortex-M4 r0p1 processor detected Info : [stm32g4x.cpu] target has 6 breakpoints, 4 watchpoints Info : starting gdb server for stm32g4x.cpu on 50000 Info : Listening on port 50000 for gdb connections Info : accepting 'gdb' connection on tcp/50000 target halted due to debug-request, current mode: Thread xPSR: 0x61000000 pc: 0x08004b52 psp: 0x20000e50 Info : device idcode = 0x10016479 (STM32G49/G4Axx - Rev 'unknown' : 0x1001) Info : RDP level 0 (0xAA) Info : flash size = 512kbytes Info : flash mode : single-bank Info : device idcode = 0x10016479 (STM32G49/G4Axx - Rev 'unknown' : 0x1001) Info : RDP level 0 (0xAA) Info : OTP size is 1024 bytes, base address is 0x1fff7000 Info : Unable to match requested speed 2000 kHz, using 1000 kHz Info : Unable to match requested speed 2000 kHz, using 1000 kHz target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08005ea8 msp: 0x2001c000 Info : Unable to match requested speed 2000 kHz, using 1000 kHz Info : Unable to match requested speed 2000 kHz, using 1000 kHz target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08005ea8 msp: 0x2001c000 Info : Padding image section 0 at 0x080001d8 with 8 bytes Info : Unable to match requested speed 2000 kHz, using 1000 kHz Info : Unable to match requested speed 2000 kHz, using 1000 kHz target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08005ea8 msp: 0x2001c000 Info : Unable to match requested speed 2000 kHz, using 1000 kHz Info : Unable to match requested speed 2000 kHz, using 1000 kHz target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0x08005ea8 msp: 0x2001c000 /home/user/.vscode/extensions/marus25.cortex-debug-1.4.4/support/openocd-helpers.tcl: Error: Could not find TPIU/SWO names. Perhaps it hasn't been created?
I will try to find where STM32Cube put its openocd version.
I found where it is, but I don't know how I can make VsCode find all the cfg files.
"cortex-debug.openocdPath": "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.externaltools.openocd.linux64_2.1.0.202110201500/tools/bin/openocd",
I added the full paths of the cfg files:
"configFiles": [ "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts/interface/stlink.cfg", "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts/target/stm32g4x.cfg" ],
But then it cannot find:
/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts/target/stm32g4x.cfg:6: Error: Can't find target/swj-dp.tcl in procedure 'script' at file "embedded:startup.tcl", line 26 at file "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts/target/stm32g4x.cfg", line 6
The xPack seems more up-to-date by it may still be missing/old config files.
/home/user/.vscode/extensions/marus25.cortex-debug-1.4.4/support/openocd-helpers.tcl: Error: Could not find TPIU/SWO names. Perhaps it hasn't been created?
So, the config files you used never created the TPIU HW interface. If I see the target/stm32g4x.cfg
shipped with STM32CubeIDE, which are in a different dir. btw.
This is what I have in my install for the script files
hdm@HaneefMac-2021 STM32CubeIDE.app % find . -name stm32g4x.cfg
./Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts/target/stm32g4x.cfg
./Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.200.202202161333/resources/openocd/st_scripts/target/stm32g4x.cfg
There are so many versions of the truth, I cannot keep it straight.
You need to configure the searchDir's instead of using full path names because they have their own relative path names.
In launch.json
"searchDir": [
"${workspaceRoot}",
"/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts"
],
"configFiles": [
"interface/stlink.cfg",
"target/stm32g4x.cfg"
],
Or something like that.
It can now find the cfg files, but now I get this error:
Open On-Chip Debugger 0.11.0+dev-00438-ga75fc63 (2021-11-03-15:26) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html CDRTOSConfigure Info : auto-selecting first available session transport "hla_swd". To override use 'transport select
'. DEPRECATED! use 'swj_newdap' not 'hla newtap' DEPRECATED! use 'swj_newdap' not 'hla newtap' ... DEPRECATED! use 'swj_newdap' not 'hla newtap' DEPRECATED! use 'swj_newdap' not 'hla newtap' DEPRECATED! use 'swj_newdap' not 'hla newtap' DEPRECATED! use 'swj_newdap' not 'hla newtap' DEPRECATED! use 'swj_newdap' not 'hla newtap' DEPRECATED! use 'swj_newdap' not 'hla newtap' embedded:startup.tcl:944: Error: Infinite eval recursion in procedure 'script' at file "embedded:startup.tcl", line 26 in procedure 'swj_newdap' called at file "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts/target/stm32g4x.cfg", line 62 in procedure 'hla newtap' called at file "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts/target/swj-dp.tcl", line 28 ... in procedure 'swj_newdap' called at file "embedded:startup.tcl", line 238 in procedure 'hla newtap' called at file "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts/target/swj-dp.tcl", line 28 in procedure 'swj_newdap' called at file "embedded:startup.tcl", line 238 in procedure 'hla newtap' called at file "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts/target/swj-dp.tcl", line 28 in procedure 'swj_newdap' called at file "embedded:startup.tcl", line 238 in procedure 'using_hla' called at file "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts/target/swj-dp.tcl", line 27 at file "embedded:startup.tcl", line 944 [2022-07-08T17:01:05.160Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed GDB server session ended. This terminal will be reused, waiting for next session to start...
I feel like I'm constantly chasing bugs as if my system configuration is very odd. Is ubuntu 20.04 not common? I had to increase the scrollback of the terminal to 10k since my terminal was flooding with error messages. There is something very weird going on.
Lots of users using ubuntu 20.04 but packages you installed may not be up to date.
Do you have STM32CubeIDE installed. If so, maybe I can guide you into something far simpler. Maybe
Yes I have STM32CubeIDE 1.8.0 installed. I normally use this for development, but we are now converting our projects to Cmake and will be using VsCode as an IDE. I'm used to STM32CubeIDE. Also VsCode, but not with STM32 (in the past I have used platformio with VsCode with STM32).
If you have/create a STM32CubeIDE project with your device then you can open the Debug Configuration for OpenOCD and you will see the following
If you run the debug session even once, it will create the .cfg
file. We will need that. It will have everything we need and you can use this file as the only config file in launch.json. You may want to make a copy of this file in case Eclipse overwrites it in the future.
Click the Show Command Line
button and it will show you exact command-line ST uses for openocd. From here, we collect the following
-s
option. These are what goes into the searchDir
in launch.json
This is the official way ST does and that is what I do regardless of what the Internet tells me. But that is me. Everyone does it differently.
Yes I have STM32CubeIDE 1.8.0 installed. I normally use this for development, but we are now converting our projects to Cmake and will be using VsCode as an IDE. I'm used to STM32CubeIDE. Also VsCode, but not with STM32 (in the past I have used platformio with VsCode with STM32).
That is okay. I just use STM32CubeIDE as a reference in lieu of documentation from ST. I know that its flow has been tested that way so I don't try to second guess that.
I will try it. But I'm a bit skeptical as STM32CubeIDE crashes when debugging with openocd (at least with a different board we have).
We just need it to start and create that cfg file.
It works! The only thing I changed was I grabbed the generated cfg file "STM32G491RE_blinky Debug.cfg" and substituted that for my cfg files:
"configFiles": [
"STM32G491RE_blinky Debug.cfg"
// "interface/stlink.cfg",
// "target/stm32g4x.cfg"
],
The file is quite small, so I can probably generate it myself for different targets (I use a python script to parse the ioc file and makefile generated by STM32CubeMX) Here is the contents of the file:
# This is an NUCLEO-G491RE board with a single STM32G491RETx chip
#
# Generated by STM32CubeIDE
# Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s)
source [find interface/stlink-dap.cfg]
set WORKAREASIZE 0x8000
transport select "dapdirect_swd"
set CHIPNAME STM32G491RETx
set BOARDNAME NUCLEO-G491RE
# Enable debug when in low power modes
set ENABLE_LOW_POWER 1
# Stop Watchdog counters when halt
set STOP_WATCHDOG 1
# STlink Debug clock frequency
set CLOCK_FREQ 8000
# Reset configuration
# use hardware reset, connect under reset
# connect_assert_srst needed if low power mode application running (WFI...)
reset_config srst_only srst_nogate connect_assert_srst
set CONNECT_UNDER_RESET 1
set CORE_RESET 0
# ACCESS PORT NUMBER
set AP_NUM 0
# GDB PORT
set GDB_PORT 3333
# BCTM CPU variables
source [find target/stm32g4x.cfg]
# SWV trace
set USE_SWO 0
set swv_cmd "-protocol uart -output :3344 -traceclk 170000000"
source [find board/swv.tcl]
This was how STM32CubeIDE called openOCD:
/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.externaltools.openocd.linux64_2.1.0.202110201500/tools/bin/openocd "-f" "STM32G491RE_blinky Debug.cfg" "-s" "/home/user/git/openocdcube_test/STM32G491RE" "-s" "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.0.100.202111151130/resources/openocd/st_scripts" "-s" "/opt/st/stm32cubeide_1.8.0/plugins/com.st.stm32cube.ide.mpu.debug.openocd_2.0.100.202110211057/resources/openocd/st_scripts" "-c" "gdb_report_data_abort enable" "-c" "gdb_port 3333" "-c" "tcl_port 6666" "-c" "telnet_port 4444"
Update: It also works with the xpack openocd version.
I just create sample projects once per device and use the generated cfg file. I sometimes comment stuff out that may conflict with the options I set, but so far it just works for me.
The GDB_PORT
concerns me (but seems to be ignored). We (and ST as well) see that from the command-line so I don't understand why they set it here and in their other config files.
In the command line I can get SWO working:
My target has a CPU frequency of 170MHz.
Start openocd:
Start debug session:
I use https://github.com/robertlong13/SWO-Parser to view the SWO output:
This correctly outputs:
But in VsCode I cannot see anything in the SWO console. This is my configuration:
Sometimes the program hangs in ITM_SendChar: