cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U031 OpenOCD target configuration file

ticoune91
Associate II

Hello,

I would like to program the STM32U031 with OpenOCD on the NUCLEO-U031R8. However, I cannot find a proper target configuration in the list provided by /usr/share/openocd/scripts/target/

I tried stm32f0x.cfg, stm32g0x.cfg, stm32l0.cfg and stm32u5.cfg and no one worked... The farther I was able to go was with stm32l0.cfg which crashed at the step:

STM32L0: Enabling HSI16

I tried the interface configuration file stlink.cfg and stlink-v2.cfg and both gave the same results...

I looked online to find the proper stm32u031 target configuration file for openocd but I wasn't able to find it.

Can someone please help me find the proper file ?

Thank you!

9 REPLIES 9
Pavel A.
Evangelist III

Just start debugging a project for this board with CubeIDE and specify OpenOCD as debugger backend. It will create a config file automatically.

Hello Pavel.

Ideally, I want my workflow/toolchain to be STM32CubeMX -> CMAKE -> openOCD -> GDB so I would like to avoid CubeIDE.

Anyways, I installed CubeIDE and I have use the file stm32u0x.cfg found in /opt/st/stm32cubeide_1.15.1/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.2.0.202401261111/resources/openocd/s
t_scripts/target/stm32u0x.cfg

I tried the following command to program the STM32U031: openocd -s /opt/st/stm32cubeide_1.15.1/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.2.0.202401261111/resources/openocd/st_scripts/ -f /opt/st/stm32cubeide_1.15.1/plugins/com.st.stm32c
ube.ide.mcu.debug.openocd_2.2.0.202401261111/resources/openocd/st_scripts/interface/stlink.cfg -f /opt/st/stm32cubeide_1.15.1/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.2.0.202401261111/resources/openocd/s
t_scripts/target/stm32u0x.cfg -c "program hello_world_cmake.elf verify reset exit"

However, this crashed with the following message :

embedded:startup.tcl:1360: Error: Infinite eval recursion
in procedure 'script'  
at file "embedded:startup.tcl", line 28

Any idea to help me out at this point ?

Thank you for your time and patience.

Pavel A.
Evangelist III

Are you using the ST fork of OpenOCD or something else? U0 is a new family, old OpenOCD versions may be not aware of it yet. 

Hi Pavel,

I am on the OpenOCD release found in Fedora repository. Version 0.12. Not the ST Fork of OpenOCD. There are no provided binairies and it looks complicated to build....

 

I was able to make it work using the STMCubeIDE OpenOCD generated command as inspiration : 

/opt/st/stm32cubeide_1.15.1/plugins/com.st.stm32cube.ide.mcu.externaltools.openocd.linux64_2.3.100.202312181736/tools/bin/openocd "-f" "GPIO_IOToggle Debug (1).cfg" "-s" "/home/deck/STM32
CubeIDE/workspace_1.15.1/GPIO_IOToggle/STM32CubeIDE" "-s" "/opt/st/stm32cubeide_1.15.1/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.2.0.202401261111/resources/openocd/st_scripts" "-s" "/opt/st/stm32cubeide_1
.15.1/plugins/com.st.stm32cube.ide.mpu.debug.openocd_2.1.100.202402161658/resources/openocd/st_scripts" "-c" "gdb_report_data_abort enable" "-c" "gdb_port 3333" "-c" "tcl_port 6666" "-c" "telnet_port 4444" -c "p
rogram hello_world_cmake.elf verify reset exit"

 

The GPIO_IOToggle Debug (1).cfg file was generated by STMCubeIDE and hello_world_cmake.elf is the builded file from the CMAKE project. I am able to program and even debug with GDB remote target on port 3333 if I remove the "exit" word from the command! 

 

It uses the bin of the STM32CubeIDE OpenOCD install instead of my Fedora OpenOCD, but it works and it suits my need for the moment.

 

Thank you for your help and I hope my solution can help someone else.

U0 support patch found on OpenOCD gerrit but in still early stage.
https://review.openocd.org/c/openocd/+/8087

I built patched(and need small fix) version for Windows works well on NUCLEO-U083RC.

If you have interested in ,try this.

I can't figure out how to do this!  Can you provide further instructions?

For example, I am in an existing project (working Blinky for STM32U083) with default setup.

1. I click on "Run" and "Debug Configurations"

2. In the "Debug Configurations" dialog that pops up I'm presented with a list of things on the left (the instructions on the right aren't relevant to this discussion).

3. I make a guess that the item on the left, "GDB Hardware Debugging" is the correct one to select so I click on it to highlight it and click "+" (double-clicking works too).  A "New Configuration" is created.  I rename it to "OpenOCD" and click Apply.  I now see my new name appear in the list on the left.

4. Under "Project", click "Browse" and see my "Blinky" project is already highlighted and click OK.  The C/C++ Application field is autofilled.

5. I have a feeling that this isn't all there is so I click on the "Debugger" tab.  I see a few things I don't understand:

  a. The GDB Command is "gdb".  Is this right?  Shouldn't it be something like "gdb-multiarch"?

  b. What about arguments?  Do I need to put anything there?

  c. Under the "Remote Target" section, the "Debug Server" is "Generic TCP/IP".  This can't be right.  Shouldn't it be
  "ST-LINK(OpenOCD)"?

  d. If I select that, the Connection field now says "unspecified-ip-address:unspecified-port-number".  So, what am I
  supposed to put  there?

That's about as far as I got.

Can you point me to at tutorial on this process?  I'm running Ubuntu 22.04LTS.

 

This is not helpful.  How is this "patch" applied?  What is this "need small fix"?  Is that the patch or do you have to apply some other fix along with the patch?  Is this ST Micro's fork of OpenOCD, the upstream fork or some other fork?  Which branch/tag? I looked at the "gerrit" page and frankly my mind went blank. Can you please provide more details?

 

 I make a guess that the item on the left, "GDB Hardware Debugging" is the correct one

Select "STM32 C/C+ application", then on the debugger tab select Debug probe ST-Link ( OpenOCD) :

PavelA_0-1743536832216.png

Then you can edit the auto-generated script and/or OpenOCD command line options.

Also you can pick your own OpenOCD binary, in the OpenOCD Command field.

As for the patches: this is the public ST fork (note the active branch): https://github.com/STMicroelectronics/OpenOCD

The main OpenOCD project may get changes from that, though I don't know details.

Hi @Pavel A.

I followed your suggestion but the solution wasn't straightforward.

I looked through the generated config file and found the following two source statements:

source [find interface/stlink-dap.cfg]
...
source [find target/stm32u0x.cfg]

The file stlink-dap.cfg can be found in this location

$ find /usr -name "stlink-dap.cfg"
/usr/local/share/openocd/scripts/interface/stlink-dap.cfg

and the location created by CubeIDE installation:

$ find /opt/st/stm32cubeide_1.18.0/ -name "stlink-dap.cfg"
/opt/st/stm32cubeide_1.18.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/interface/stlink-dap.cfg

From what I can tell, the only difference between the two is the addition of the vid_pid pair, '0x0483 0x3744' to the /usr/share version. So, I guess, I could use either of these files without issues. Is that right?

The file in the second source statement, "source [find target/stm32u0x.cfg]" does not exist anywhere under the /usr heirarchy.

However, it does appear here:

find /opt/st/stm32cubeide_1.18.0/ -name "stm32u0x.cfg"
/opt/st/stm32cubeide_1.18.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/target/stm32u0x.cfg

There's also another identical copy of this file kept here:
$ find . -name "stm32u0x.cfg"
./.eclipse/com.st.stm32cube.ide.mcu.rcp.product_1.17.0_139066135_linux_gtk_x86_64/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/target/stm32u0x.cfg

3. When I look at the contents of stm32u0x.cfg, the first 3 non-comment lines are:

source [find target/swj-dp.tcl]
source [find mem_helper.tcl]
source [find gdb_helper.tcl]

The first file is available in two locations:

$ find /usr -name "swj-dp.tcl"
/usr/local/share/openocd/scripts/target/swj-dp.tcl

$ find /opt/st/stm32cubeide_1.18.0/ -name "swj-dp.tcl"
/opt/st/stm32cubeide_1.18.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/target/swj-dp.tcl

Differences:

diff -d -I '^#' -I '^ *#' /usr/local/share/openocd/scripts/target/swj-dp.tcl /opt/st/stm32cubeide_1.18.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/target/swj-dp.tcl
1,2d0
< # SPDX-License-Identifier: GPL-2.0-or-later
<
29c27,29
< if [using_jtag] {
---
> if [using_hla] {
> eval hla newtap $chip $tag $args
> } elseif [using_jtag] {
33,35d32
< } else {
< echo "Error: transport '[ transport select ]' not supported by swj_newdap"
< shutdown

The differences between these files are minimal (something about using_hla - not
sure what that means or if its relevant).

The second file:

$ find /usr -name "mem_helper.tcl"
/usr/local/share/openocd/scripts/mem_helper.tcl

$ find /opt/st/stm32cubeide_1.18.0 -name "mem_helper.tcl"
/opt/st/stm32cubeide_1.18.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/mem_helper.tcl
diff -d -I '^#' -I '^ *#' /usr/local/share/openocd/scripts/mem_helper.tcl /opt/st/stm32cubeide_1.18.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/mem_helper.tcl
1,2d0
< # SPDX-License-Identifier: GPL-2.0-or-later
<

Differences are just in the comments.

However, the third file, gdb_helper.tcl, is only found in one place:

$ find /usr -name "gdb_helper.tcl"
$ find /opt/st/stm32cubeide_1.18.0/ -name "gdb_helper.tcl"
/opt/st/stm32cubeide_1.18.0/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/gdb_helper.tcl
/opt/st/stm32cubeide_1.18.0/plugins/com.st.stm32cube.ide.mpu.debug.openocd_2.2.0.202409171044/resources/openocd/st_scripts/gdb_helper.tcl

After discovering all this, this what I did:

a. Copy all these files to a local heirarchy like so.

$ tree
.
├── Blinky2_Debug.cfg
└── scripts
    ├── gdb_helper.tcl
    ├── interface
    │   └── stlink-dap.cfg
    ├── mem_helper.tcl
    └── target
        ├── stm32u0x.cfg
        └── swj-dp.tcl

3 directories, 6 files

b. Edit Blinky2_Debug.cfg, adding the following line before the first source
statement:

add_script_search_dir "./scripts/"

c. From this local directory, run the following command

openocd -c -f ./Blinky2_Debug.cfg

d. In another termial, run gdb as follows:
gdb-multiarch -q -ex "target remote :3333" ./program.elf

WHEW!  IT WORKED!

(Edits: just cleaning up a couple of typos and missing spaces)