[Embedded Rust] How can one debug STM32/OpenOCD from CLion/IntelliJ Rust?

If anyone else runs into issues with this, its possible that your OpenOCD config for your board is incorrect.

Like the OP I'm following along the discovery tutorial (which has moved to a full book here).

In CLion/IntelliJ all you need to do is create an OpenOCD Download and Run, you don't need the GDB Remote Debug job as the OpenOCD task will start its own.

You don't need a Target, but if you accidentally choose one, it won't let you unchoose it, so you can make one that "Does Nothing".

The executable will be your debug build file (you can see mine is led-roulette).

Leave it using the built in gdb as this is a multi-arch build which will work.

Now, the board config file. After banging my head on this for a while, I decided to just look inside it. Finding it is a bit tricky, mine (on a Mac) was located here:

usr/local/Cellar/open-ocd/0.10.0/share/openocd/scripts/board/stm32f3discovery.cfg

Here it is in full

# This is an STM32F3 discovery board with a single STM32F303VCT6 chip.
# http://www.st.com/internet/evalboard/product/254044.jsp

source [find interface/stlink-v2.cfg]

transport select hla_swd

source [find target/stm32f3x.cfg]

reset_config srst_only

What you might notice is that it references almost the same files as the tutorial uses from the command line... but the version number on the first one is wrong.

interface/stlink-v2-1.cfg vs source [find interface/stlink-v2.cfg]

I duplicated the file (in the same directory) and changed that line, and my duplicated file then showed up in IntelliJs "Assist".

There's one more thing to do though. At the bottom in the Before Launch you'll need to get rid of the "Build" task and add in one to build your project. Frustratingly you can't use Cargo tasks here (it runs them but then doesn't run the OpenOCD task). Instead I just created an external task to run cargo build from the command line.

After I did that, it works pretty much as expected. You can put in break points, reset the MCU from the IDE and step through your code.

1 Like