stlink-org / stlink

Open source STM32 MCU programming toolset
BSD 3-Clause "New" or "Revised" License
4.43k stars 1.24k forks source link

Semihosting with gcc-arm-embedded #147

Closed jhgorse closed 4 years ago

jhgorse commented 11 years ago

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 commented 10 years ago

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 commented 10 years ago

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@github.comwrote:

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/texane/stlink/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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

Thanks. I'll give OpenOCD a try.

xor-gate commented 8 years ago

Related to #227

Nightwalker-87 commented 4 years ago

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

jhgorse commented 4 years ago

@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

jhgorse commented 4 years ago

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