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

Semihosting with gcc-arm-embedded #147

Closed
jhgorse opened this issue Apr 22, 2013 · 9 comments · Fixed by #454 or #455
Closed

Semihosting with gcc-arm-embedded #147

jhgorse opened this issue Apr 22, 2013 · 9 comments · Fixed by #454 or #455

Comments

@jhgorse
Copy link

jhgorse commented Apr 22, 2013

gcc-arm-embedded supports semihosting, a feature which allows the target to access the host over the debug link. This can be useful for debugging, but has greater implications for interactive development in general. How can this be done using stlink's st-util debugger?

Here is the sample code path in gcc-arm-embedded toolchain:
gcc-arm-none-eabi-4_7-2013q1/share/gcc-arm-none-eabi/samples/src/semihost
gcc-arm-none-eabi-4_7-2013q1/share/gcc-arm-none-eabi/samples/readme.txt

Here is the succinct readme on the gcc-arm-embedded package for installation and how to use it:
gcc-arm-none-eabi-4_7-2013q1/share/doc/gcc-arm-none-eabi/readme.txt

Relevant excerpts:

Users can choose to use or not use semihosting by following instructions.
** semihosting
You can add -lrdimon in the command line and compile the programs like:
$ arm-none-eabi-gcc --specs=rdimon.specs
-Wl,--start-group -lgcc -lc -lc -lm -lrdimon -Wl,--end-group $(OTHER_OPTIONS)

** non-semihosting/retarget
If you are using retarget, you can add -lnosys in the command line and compile
the programs like:
$ arm-none-eabi-gcc
-Wl,--start-group -lgcc -lc -lc -lm -lnosys -Wl,--end-group $(OTHER_OPTIONS)

May also be relevant to semihosting (see README.nano for further information):
newlib: libc.a libg.a
newlib-nano: libc_s.a libg_s.a with LDFLAGS += --specs=nano.specs


Resources:
https://answers.launchpad.net/gcc-arm-embedded/+question/212673
https://answers.launchpad.net/gcc-arm-embedded/+question/202914
OpenOCD's contrib/libdcc

@bfoz
Copy link

bfoz commented Mar 5, 2014

Has there been any progress on this front? I've compiled a semihosting test program using gcc-arm-embedded, and loaded it onto an STM32F3 Discovery board using gdb, but when I do 'monitor semihosting enable' I get:

Target does not support this command.

I suspect I'm missing a step somewhere, but I'm having trouble figuring out exactly what I need to do.

@jhgorse
Copy link
Author

jhgorse commented Mar 5, 2014

I think you are confusing "stlink" with "OpenOCD". Nevertheless, Andrey
Yurovsky implemented this in OpenOCD.
https://plus.google.com/+AndreyYurovsky/posts/5rupuziHKGC

On Wed, Mar 5, 2014 at 12:00 AM, Brandon Fosdick
notifications@git.luolix.topwrote:

Has there been any progress on this front? I've compiled a semihosting
test program using gcc-arm-embedded, and loaded it onto an STM32F3
Discovery board using gdb, but when I do 'monitor semihosting enable' I get:

Target does not support this command.

I suspect I'm missing a step somewhere, but I'm having trouble figuring
out exactly what I need to do.

Reply to this email directly or view it on GitHubhttps://github.com//issues/147#issuecomment-36710367
.

Joe Gorse

C: 440-552-0730
LI: Joe Gorse http://www.linkedin.com/pub/joe-gorse/7/12/397
FB: jhgiv https://www.facebook.com/jhgiv

@bfoz
Copy link

bfoz commented Mar 6, 2014

I'm not sure I understand what you mean, although I am fairly certain that I understand the difference between stlink and OpenOCD.

From what I can tell, the gdb provided by the gcc-arm-embedded package can display semihosting output in the console (once provided with some poorly-documented magic incantation), but the debug server (stlink) needs to support it as well. gdb seems to be telling me that some component in the chain isn't properly supporting semihosting, but of course it's not telling me which part. I'm assuming the problem is in stlink because I know the hardware support is there and the test program was compiled according to the relevant instructions for the toolchain. Of course, the problem could still lie somewhere in the build settings, but I thought I'd check to see if stlink is known to support, or not support, semihosting before I go digging into that mess again.

@jhgorse
Copy link
Author

jhgorse commented Mar 6, 2014

Brandon,

Within the remote GDB shell, "monitor " passes to the remote debugger. As far as I am aware, the texane/stlink remote GDB server has not implemented semihosting. If you need to use semihosting, please follow Andrey's instructions with OpenOCD as per the link above.

Cheers,
Joe

@bfoz
Copy link

bfoz commented Mar 7, 2014

Thanks. I'll give OpenOCD a try.

@xor-gate
Copy link
Member

xor-gate commented May 4, 2016

Related to #227

@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Feb 25, 2020

Support for ARM semihosting was added to st-util in Release v1.3.0.

@jhgorse
Copy link
Author

jhgorse commented Feb 25, 2020

@Nightwalker-87 consider Segger RTT or a clean implementation similar to it rather than semihosting. In RTT there is an up and a down buffer which is read/written asynchronously over the SWD/JTAG debug pipe. It is very fast and less intrusive than semihosting and even some of the ARM ITM/ETM/etc. debug features.

Hope this helps!

Cheers,
Joe

@Nightwalker-87 Nightwalker-87 modified the milestones: v1.7.0, v1.3.0 Mar 16, 2020
@Nightwalker-87 Nightwalker-87 modified the milestones: v1.3.0, Feedback required Mar 16, 2020
@jhgorse
Copy link
Author

jhgorse commented Mar 19, 2020

@Nightwalker-87 I no longer use semihosting, per the comment above. Haven't for about 5 years now. =)

@Nightwalker-87 Nightwalker-87 modified the milestones: Feedback required, v1.3.0 Mar 28, 2020
@stlink-org stlink-org locked as resolved and limited conversation to collaborators Apr 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.