Skip to main content
MGoss.2
Associate
July 16, 2019
Solved

How to get ARM semihosting to work on STM32CubeIDE

  • July 16, 2019
  • 5 replies
  • 6300 views

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 :)

This topic has been closed for replies.
Best answer by Ethan HUANG

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.

5 replies

Ethan HUANG
Ethan HUANGBest answer
ST Employee
July 16, 2019

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.
DaDude
Associate
September 14, 2020

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

Ethan HUANG
ST Employee
July 16, 2019

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
MGoss.2Author
Associate
July 16, 2019

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

MVale.1
Associate
January 13, 2020

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
January 14, 2020

Hi, everyone!

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

I hope it help you.

Bye.