cancel
Showing results for 
Search instead for 
Did you mean: 

How to get ARM semihosting to work on STM32CubeIDE

MGoss.2
Associate

I just started using STM32CubeIDE, and was able to get a blinking LED and getting some UART communication going in no time with a NUCLEO-L476RG eval board.

I am trying to follow the examples in the book "Mastering STM32" by Carmine Noviello, but I am a bit stuck on the ARM Semihosting section. I have tried a couple of things, but I don't know how to get printf() to work for instance in the STM32CubeIDE. Any advice on getting these functions to work so the output is parsed to the UART2 interface would be really appreciated :)

1 ACCEPTED SOLUTION

Accepted Solutions
Ethan HUANG
ST Employee

Spent some time months ago to try this feature and here is my note for your reference. In short:

  1. Exclude syscalls.c
  2. add code for initialise_monitor_handles().
  3. Set additional flag (-specs=rdimon.specs -lc -lrdimon) for linker
  4. Use ST-LINK OpenOCD as debugger (haven't found a way myself to make the other two debuggers work for semihosting yet).
  5. Add initialization commands (monitor arm semihosting enable) in "Startup" tab in Debug Configuration.

View solution in original post

6 REPLIES 6
Ethan HUANG
ST Employee

Spent some time months ago to try this feature and here is my note for your reference. In short:

  1. Exclude syscalls.c
  2. add code for initialise_monitor_handles().
  3. Set additional flag (-specs=rdimon.specs -lc -lrdimon) for linker
  4. Use ST-LINK OpenOCD as debugger (haven't found a way myself to make the other two debuggers work for semihosting yet).
  5. Add initialization commands (monitor arm semihosting enable) in "Startup" tab in Debug Configuration.
Ethan HUANG
ST Employee

And if you want to try printf over UART, here is a reference:

https://github.com/ethanhuanginst/STM32CubeIDE-Workshop-2019/tree/master/hands-on/03_printf

MGoss.2
Associate

Thanks! Exactly what I was looking for, will definitely try this out.

MVale.1
Associate II

Hi!

I see when you choose Debug probe: ST-LINK (OPENOCD), it works for you. My question is: Which programmer/debugger do you use? I'm ussing ST-LINK v2 (chinese clone) and when I choose the same debug probe and clic "Debug", It show me an error.

0690X00000Bvt7oQAB.png

So I will you very grateful if you let me know which programmer/debugger do you use? and if you use ST-LINK v2 chinese clone, too, How can I set it to use it with ST-LINK (OPENOCD) debug probe.

Thank you so much.

MVale.1
Associate II

Hi, everyone!

It works for me: http://shawnhymel.com/1840/how-to-use-semihosting-with-stm32/

I hope it help you.

Bye.

Excellent ! This is working as intended. Could not use it with ST-LIN GDB, too.