Cannot Attach or Launch to MSOM with STLink-V3Minie Debugger

I am having trouble connecting to the m404 SOM using the stlink-v3 minie debugger from vscode particle workbench. I'm using the latest Macbook Pro as of this writing.
I am set up to use openOCD and gdb. When I try to run a debugging session it stops with a dialog stating:
OpenOCD: GDB Server Quit Unexpectedly. See gdb-server output in TERMINAL tab for more details.

My logs are as follows:
Terminal:
Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
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
srst_only separate srst_nogate srst_open_drain connect_assert_srst

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 100 kHz
Info : STLINK V3J15M7 (API v3) VID:PID 0483:3754
Info : Target voltage: 3.258964
Error: init mode failed (unable to connect to the target)

  • The terminal process "/opt/homebrew/bin/zsh '-l', '-c', '/opt/homebrew/bin/openocd -f interface/stlink.cfg -f /Users/tommygun/code/cpp/core/liberty-fw_/stm32l4r5_custom.cfg'" failed to launch (exit code: 1).
  • Terminal will be reused by tasks, press any key to close it.

My Debug Console output is:

Cortex-Debug: VSCode debugger extension version 1.12.1 git(652d042). Usage info: GitHub - Marus/cortex-debug: Visual Studio Code extension for enhancing debug capabilities for Cortex-M Microcontrollers
"configuration": {
"name": "Particle Debug (Auto OpenOCD)",
"cwd": "/Users/tommygun/code/cpp/core/liberty-fw_",
"executable": "/Users/tommygun/code/cpp/core/liberty-fw_/target/6.2.0/msom/liberty-fw_.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32L4x5",
"runToEntryPoint": "setup",
"gdbTarget": "localhost:3333",
"gdbPath": "/opt/homebrew/bin/arm-none-eabi-gdb",
"showDevDebugOutput": "raw",
"configFiles": [
"interface/stlink.cfg",
"openocd/target/stm32l4r5_custom.cfg"
],
"preLaunchTask": "OpenOCD",
"interface": "swd",
"svdFile": "/Users/tommygun/code/cpp/core/liberty-fw_/STM32L4x5.svd",
"postRestartCommands": [
"monitor reset halt"
],
"openOCDLaunchCommands": ,
"configurationTarget": 6,
"gdbServerConsolePort": 55878,
"pvtAvoidPorts": [],
"chainedConfigurations": {
"enabled": false
},
"debuggerArgs": [],
"swoConfig": {
"enabled": false,
"decoders": [],
"cpuFrequency": 0,
"swoFrequency": 0,
"source": "probe"
},
"rttConfig": {
"enabled": false,
"decoders": []
},
"graphConfig": [],
"preLaunchCommands": [],
"postLaunchCommands": [],
"preAttachCommands": [],
"postAttachCommands": [],
"preRestartCommands": [],
"preResetCommands": [],
"postResetCommands": [
"monitor reset halt"
],
"searchDir": [],
"toolchainPrefix": "arm-none-eabi",
"extensionPath": "/Users/tommygun/.vscode/extensions/marus25.cortex-debug-1.12.1",
"registerUseNaturalFormat": true,
"variableUseNaturalFormat": true,
"serverpath": "/Users/tommygun/.particle/toolchains/openocd/0.12.0-particle.2/bin/openocd",
"pvtVersion": "1.12.1",
"sessionId": "82793ef6-c66a-496f-b3ee-202bfa9a99a5",
"pvtShowDevDebugOutput": "raw"
}
Reading symbols from /opt/homebrew/bin/arm-none-eabi-objdump --syms -C -h -w /Users/tommygun/code/cpp/core/liberty-fw
/target/6.2.0/msom/liberty-fw
.elf
Reading symbols from /opt/homebrew/bin/arm-none-eabi-nm --defined-only -S -l -C -p /Users/tommygun/code/cpp/core/liberty-fw
/target/6.2.0/msom/liberty-fw
.elf
Launching GDB: /opt/homebrew/bin/arm-none-eabi-gdb -q --interpreter=mi2
1-gdb-version
Launching gdb-server: /Users/tommygun/.particle/toolchains/openocd/0.12.0-particle.2/bin/openocd -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /Users/tommygun/code/cpp/core/liberty-fw_ -f /Users/tommygun/.vscode/extensions/marus25.cortex-debug-1.12.1/support/openocd-helpers.tcl -f interface/stlink.cfg -f openocd/target/stm32l4r5_custom.cfg
Please check TERMINAL tab (gdb-server) for output from /Users/tommygun/.particle/toolchains/openocd/0.12.0-particle.2/bin/openocd
Finished reading symbols from objdump: Time: 24 ms
OpenOCD: GDB Server Quit Unexpectedly. See gdb-server output in TERMINAL tab for more details.

I noticed that a reset is Not asserted when trying to connect to the target (MSOM) and the application keeps on running and stays connected to the cloud.
The wiring from the debugger to the MSOM is using the testpoints on the back of the MSOM that particle uses to program and test the device in an SWD configuration (Reset, SWO, SWDIO, SWCLK,VCC, GND)

I've ran out of ideas of what could be the problem. I see that others on this forum state they have no problem using the particle debugger but they aren't in stock so can't eliminate that variable.
Does anyone have an idea what is going on?
My launch.json file is:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: Debug code with Visual Studio Code
"version": "0.2.0",
"configurations": [
{
"name": "Particle Debug (Auto OpenOCD)",
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}/target/6.2.0/msom/liberty-fw_.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32L4x5",
"runToEntryPoint": "setup",
"gdbTarget": "localhost:3333",
"gdbPath": "/opt/homebrew/bin/arm-none-eabi-gdb",
"showDevDebugOutput": "raw",
"configFiles": [
"interface/stlink.cfg",
"openocd/target/stm32l4r5_custom.cfg"
],
"preLaunchTask": "OpenOCD",
"interface": "swd",
"svdFile": "${workspaceFolder}/STM32L4x5.svd",
"postRestartCommands": [
"monitor reset halt"
],
"openOCDLaunchCommands": ,
},
{
"type": "cortex-debug",
"request": "attach",
"interface": "swd",
"servertype": "openocd",
"name": "Particle Debugger",
"cwd": "${workspaceRoot}",
"rtos": "FreeRTOS",
"armToolchainPath": "${command:particle.getDebuggerCompilerDir}",
"executable": "${command:particle.getDebuggerExecutable}",
"serverpath": "${command:particle.getDebuggerOpenocdPath}",
"searchDir": [
"${command:particle.getDebuggerSearchDir}"
],
"configFiles": [
"${command:particle.getDebuggerConfigFiles}"
],
"postAttachCommands": [
"${command:particle.getDebuggerPostAttachCommands}"
],
"particle": {
"version": "1.1.0",
//"debugger": "particle-debugger"
"debugger": "stlink"
},
"chainedConfigurations": [
"delayMs:1000"
],
},
{
"type": "cortex-debug",
"request": "attach",
"servertype": "openocd",
"name": "Generic DAPLink Compatible Debugger",
"cwd": "${workspaceRoot}",
"rtos": "FreeRTOS",
"armToolchainPath": "${command:particle.getDebuggerCompilerDir}",
"executable": "${command:particle.getDebuggerExecutable}",
"serverpath": "${command:particle.getDebuggerOpenocdPath}",
"searchDir": [
"${command:particle.getDebuggerSearchDir}"
],
"configFiles": [
"interface/stlink.cfg",
"${workspaceFolder}/stm32l4r5_custom.cfg"
],
// "configCommands": [
// "adapter speed 100",
// "transport select swd"
// ],
"postAttachCommands": [
"${command:particle.getDebuggerPostAttachCommands}"
],
"particle": {
"version": "1.1.0",
"debugger": "generic-cmsis-dap"
}
}
]
}

And my tasks.json file is:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang build active file",
"command": "/usr/bin/clang",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
},
{
"label": "OpenOCD",
"type": "shell",
"command": "/opt/homebrew/bin/openocd",
"args": [
"-f", "interface/stlink.cfg",
"-f", "${workspaceFolder}/stm32l4r5_custom.cfg"
],
"isBackground": true,
"problemMatcher": {
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": "Listening on port 4444",
"endsPattern": "Info : Listening on port 3333"
}
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated"
}
},
],
"version": "2.0.0"
}

My custom cfg file is:

Custom STM32L4R5 target config for OpenOCD

source [find target/stm32l4x.cfg]

set _CPUTAPID 0x2ba01477

Optionally disable the IDCODE check if causing issues

NOTE: This bypasses safety checks; use only when debugging

adapter speed 100

#transport select swd

This might help with certain STM32 chips that go into low-power

reset_config srst_only srst_nogate connect_assert_srst connect_under_reset

Uncomment if OpenOCD still struggles

set WORKAREASIZE 0x4000

The M-SoM (also Photon 2 and P2) are Realtek RTL872x MCUs, not STM32.

The ST/LINK series can only be used with STM32 MCUs including Gen 2 devices such as the E-Series (except E404X), Electron, Photon 1, and P1.

You need to use a CMSIS/DAP debugger with the M-SoM.

So what debugger is compatible with the MSOM?

The Particle Debugger is no longer available, but there are many, many clone devices. Look for a "CMSIS-DAP debugger" that supports ARM Cortex-M. See the debugger instructions for how to connect it.

1 Like

So Purchased and setup using CMSIS-DAP debugger (SYST) and when I try launching I get the following output:

  • Executing task: openocd -f interface/cmsis-dap.cfg -f openocd/target/RTL8722_custom.cfg

Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
Info : auto-selecting first available session transport "swd". To override use 'transport select '.
srst_only separate srst_nogate srst_open_drain connect_assert_srst

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: FW Version = 1.6.181013
Info : CMSIS-DAP: Serial# = 6030424000053
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 1 nRESET = 1
Info : Connecting under reset
Info : CMSIS-DAP: Interface ready
Info : clock speed 100 kHz
Error: Error connecting DP: cannot read IDR

  • The terminal process "/opt/homebrew/bin/zsh '-l', '-c', 'openocd -f interface/cmsis-dap.cfg -f openocd/target/RTL8722_custom.cfg'" terminated with exit code: 1.
  • Terminal will be reused by tasks, press any key to close it.

I see the correct communications signals on SWDIO and SDCLK. I see it does a reset at the beginning as well. My thought is still with the configuration files launch.json and task.json.
My launch config is as follows:
"name": "Particle Debug (Auto OpenOCD)",
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}/target/6.2.0/msom/liberty-fw.elf",
"request": "attach",
"type": "cortex-debug",
"servertype": "openocd",
"device": "Cortex-M33",
"runToEntryPoint": "setup",
"gdbTarget": "localhost:3333",
"gdbPath": "/opt/homebrew/bin/arm-none-eabi-gdb",
"searchDir": [
"/opt/homebrew/share/openocd/scripts"
],
"showDevDebugOutput": "raw",
"configFiles": [
"interface/cmsis-dap.cfg",
"openocd/target/RTL8722_custom.cfg"
],
"preLaunchTask": "OpenOCD",
"svdFile": "${workspaceFolder}/STM32L4x5.svd",
"postRestartCommands": [
"monitor reset halt"
],
"openOCDLaunchCommands": ,
Where can I get the .svd file for the MSOM as I am reusing the STM32L4x5.svd which I'm not satified with?

I would create a fresh project using Particle: Create New Project and get the debugger working with that, then try to merge the changes into your real project.

You should not have a .svd file configured in your configuration, because it should be part of the Particle base configuration and depends on the device you are targeting. Also, your configuration is picking up bits of Homebrew's GDB, which is not the one that should be called. There's one that's installed in ~/.particle/toolchains/openocd. It should be using 0.12.0-particle-d8e1d63 0.12.0-particle.2 which has the changes to allow it to work properly; the base install from Homebrew will not work.

OK so I commented out the launch section that I inserted and used the existing cortex-debug launch config / attach sections and I get much further:
Open On-Chip Debugger 0.12.0+dev-g5aed15f (2024-10-11-22:03)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
CDLiveWatchSetup
Info : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
/Users/tommygun/.vscode/extensions/marus25.cortex-debug-1.12.1/support/openocd-helpers.tcl: rtl872x.cpu configure -rtos FreeRTOS
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: JTAG supported
Info : CMSIS-DAP: FW Version = 1.6.181013
Info : CMSIS-DAP: Serial# = 6030424000053
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 1 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x6ba02477
Info : [rtl872x.cpu] Real-M300 (KM4) r1p0 processor detected
Info : [rtl872x.cpu] target has 2 breakpoints, 1 watchpoints
Info : [rtl872x.cpu] Examination succeed
Info : starting gdb server for rtl872x.cpu on 50000
Info : Listening on port 50000 for gdb connections
Info : accepting 'gdb' connection on tcp/50000
Error: No symbols for FreeRTOS
undefined debug reason 8 (UNDEFINED) - target needs reset
Warn : RTOS FreeRTOS not detected. (GDB could not find symbol 'pxCurrentTCB')

KM4: reset-assert-post event
0x480003f8: 02000201
[rtl872x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x10100100 msp: 0x1007effc
KM4: reset-assert-post event
0x480003f8: 02000201
[rtl872x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x10100100 msp: 0x1007effc

I'm down to symbol files / code files not found
What does the above output indicate? I'm wondering if rtos = freeRTOS is correct here.
{
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"name": "Particle Debugger",
"cwd": "${workspaceRoot}",
"rtos": "FreeRTOS",
"armToolchainPath": "${command:particle.getDebuggerCompilerDir}",
"executable": "${command:particle.getDebuggerExecutable}",
"serverpath": "${command:particle.getDebuggerOpenocdPath}",
"searchDir": [
"${command:particle.getDebuggerSearchDir}"
],
"configFiles": [
"${command:particle.getDebuggerConfigFiles}"
],
"postAttachCommands": [
"${command:particle.getDebuggerPostAttachCommands}"
],
"particle": {
"version": "1.1.0",
"debugger": "particle-debugger"
}
},

Do you need to make a debug monolithic build for this to work? Is that possible in Particle Workbench with buildscript 1.16.0? My generated binary is not monolithic when I use compile application and device os for debug in the command palette.

Monolithic debug binaries are never used for RTL872x devices like the M-SoM, and aren't used for newer versions of Device OS on Gen 3 devices (nRF52).

You still need a debug build so the symbols are available, but it's modular. Using the compile and flash debug option in Workbench should flash the right thing.

1 Like