Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting printf output on command line from STM32F411E-Discovery #674

Closed
5 tasks done
Matombo opened this issue Feb 26, 2018 · 6 comments
Closed
5 tasks done

Getting printf output on command line from STM32F411E-Discovery #674

Matombo opened this issue Feb 26, 2018 · 6 comments

Comments

@Matombo
Copy link

Matombo commented Feb 26, 2018

  • Programmer/board type: Stlink/v2-onboard
  • Programmer firmware version: ??? (don't know how to find out)
  • Operating system: Linux 4.15
  • Stlink tools version and/or git commit hash: 1.5.0
  • Target chip (and optional board): STM32F411E-Discovery

I have a noob question:
I try to get printf output from my board without using an serial adapter, i already read that st-term got ditched in favor of ARM semihosting but every explanation on how to use it, i can find, involves some kind of ide.
And since i'm using a makefile project and st-flash directly that doesn't help much. So i'm currently completly clueless und which tool i should use or google to get some output.

@xor-gate
Copy link
Member

xor-gate commented Feb 26, 2018

@Matombo
Copy link
Author

Matombo commented Mar 1, 2018

So i figured it out how to get console output using semihosting:

  • My starting point is a Makefile project created by CubeMX
  • In the Makefile remove "-lnosys" from LIBS variable and replace "-specs=nano.specs" with "-specs=rdimon.specs" in LDFLAGS variable (this makes the compiler include the semihosting librarys)
  • Use stdio.h and printf in your code (note that if you included the semihosting libraries and are making use of them your program will freeze if the board is not connected to a debugging programm reciving the output)
  • Download and install OpenOCD (which as it looks like can actually be used as a full replacement for stlink)
  • Create a config file (filename.cfg):
source [find interface/stlink-v2.cfg]

source [find target/stm32f4x.cfg]

init

arm semihosting enable

reset
  • let OpenOCD connect to your board with "openocd -f filename.cfg" (note that the reset command in the config makes the programm run from start. The reset must be issued there for the "arm semihosting enable" option to take effect)

  • ???

  • PROFIT!!! (you should get the printf messages)

  • ps you can use gcc-arm-eabi to connect to localhost:3333 for gdb debugging

  • pps to issue openocd commands from gdb prefic them with "monitor" (e.g. "monitor reset halt" and "monitor reset run")

  • ppps I'm not 100% sure on my explanations here, it's just what i think makes sense

@xor-gate
Copy link
Member

xor-gate commented Mar 1, 2018

Thank you for your feedback, but this is related to usage of OpenOCD and not st-util. You should run st-util --semihosting option.

xor-gate added a commit that referenced this issue Mar 1, 2018
@Matombo
Copy link
Author

Matombo commented Mar 2, 2018

Thanks for the info, the manpage of st-util was missing the "--semihosting" flag, but i see, you already fixed that ^^.

I have another question now: If you run "st-util --semihosting" the execution is paused untill you connect to it with gdb. Is there a way to directly start the execution if you just want to get some output (like with openocd where you can choose between "reset halt" and "reset run" in your config files)

@xor-gate
Copy link
Member

xor-gate commented Mar 2, 2018

Semihosting uses the bkpt assembly instruction which hits a breakpoint. Only the debugger is able to get the microcontroller out of this.

@Wfuger
Copy link

Wfuger commented Mar 31, 2020

@Matombo thank you that is incredibly helpful!

@stlink-org stlink-org locked as resolved and limited conversation to collaborators Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants