tiradoe
tiradoe

Reputation: 76

Unable to start debug session with OpenOCD/Clion

I'm currently trying to set up CLion for embedded development. Running 'build' by itself creates the executable without any issues, but trying to start the debugger fails with the following error:

/usr/bin/openocd -s /usr/share/openocd/scripts -f /home/username/Projects/STMicroelectronics/STM32CubeIDE/workspace_1.9.0/blackpill/stm32f411ceu6_black_pill.cfg -c "tcl_port disabled" -c "gdb_port disabled" -c "tcl_port disabled" -c "program \"/home/username/Projects/STMicroelectronics/STM32CubeIDE/workspace_1.9.0/blackpill/Debug/blackpill.elf\"" -c reset -c shutdown

Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
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_deassert_srst

Info : clock speed 2000 kHz
Info : STLINK V2J39S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 2.465774
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Error executing event examine-end on target stm32f4x.cpu:
/usr/share/openocd/scripts/mem_helper.tcl:37: Error: wrong # args: should be "expr expression"
in procedure 'program' 
in procedure 'mmw' called at file "/usr/share/openocd/scripts/target/stm32f4x.cfg", line 85
at file "/usr/share/openocd/scripts/mem_helper.tcl", line 37
Info : gdb port disabled
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Error executing event examine-end on target stm32f4x.cpu:
/usr/share/openocd/scripts/mem_helper.tcl:37: Error: wrong # args: should be "expr expression"
in procedure 'program' 
in procedure 'ocd_process_reset' 
in procedure 'ocd_process_reset_inner' called at file "embedded:startup.tcl", line 288
in procedure 'mmw' called at file "/usr/share/openocd/scripts/target/stm32f4x.cfg", line 85
at file "/usr/share/openocd/scripts/mem_helper.tcl", line 37
Error: timed out while waiting for target halted
embedded:startup.tcl:530: Error: ** Unable to reset target **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 567
at file "embedded:startup.tcl", line 530

I'm running this on Fedora Linux 35 with the following config:

source [find interface/stlink.cfg]

# increase working area to 64KB
set WORKAREASIZE 0x10000

transport select hla_swd

source [find target/stm32f4x.cfg]
reset_config srst_only

I took a look at the script (stm32f4x.cfg) and the error is happening here:

proc mmw {reg setbits clearbits} {
        set old [mrw $reg]
        set new [expr ($old & ~$clearbits) | $setbits]
        mww $reg $new
}

Specifically on the set new line. I can force the script to get past that line by faking the result (it just breaks later), but I'm not sure what's supposed to be there.

I can upload code to my stm32f411 without any problems using STM32CubeIDE so I know the connection between my computer and the device is working. The issue seems to be related to the OpenOCD configuration.

I'm pretty new to embedded development so please let me know if any more information would be helpful. Thanks!

Upvotes: 1

Views: 5077

Answers (2)

tiradoe
tiradoe

Reputation: 76

Managed to figure this one out. The issue is with the current version of OpenOCD not fully supporting STM32 devices. ST Microelectronics does provide their own version of OpenOCD that fixed the issue for me.

The custom version of OpenOCD can be found here: https://github.com/STMicroelectronics/OpenOCD

Once you have that, go into the OpenOCD directory and run the following commands:

./bootstrap

./configure --enable-stlink

make

sudo make install

Note: the configure flags might be different depending on the support you need. Run ./configure --help to see the available options

You should now have OpenOCD installed to /usr/local/bin/openocd

The rest of my configuration was ok, but I did have to set reset_config to none as Tom V suggested (thanks!)

In case it helps, here is the my CLion setup:

Embedded Settings

Run Configuration

Upvotes: 3

Tom V
Tom V

Reputation: 5470

"Unable to reset target" is the key line in what you have posted.

If you don't have a hardware reset line available, try changing your openOCD configuration to include:

reset_config none

Upvotes: 1

Related Questions