J-Link RTT for the Masses using Semihosting on ARM

16 pointsposted 13 hours ago
by kristianp

6 Comments

wrs

11 hours ago

I use RTT fine without a J-Link (I have an ST-Link). There’s a fantastic Rust package called defmt-rtt that uses macros to leave all the bulky text in the ELF file and just stream the printf arguments. Super fast logging, as verbose as you want with very little overhead.

bobmcnamara

12 hours ago

> If we don’t have a debugger connected, the breakpoint instruction is going to throw and exception.

Another fun trick: route all semihosting calls through this function in RAM:

  BX LR
  BX LR

Then when you connect the debugger, overwrite with `BKPT 0xAB` to enable semihosting like so:

  BKPT 0xAB
  BX LR
This saves the overhead of an interrupt when not in use. You can still have the hardfault handler ignore it in case you uncleanly disconnect the debugger.

duskwuff

12 hours ago

Two important notes:

1) Semihosting calls are extremely slow. They halt the processor until the debug probe polls the target, notices that it's stopped at a semihosting breakpoint, handles that, and resumes it. This can take tens to hundreds of milliseconds per call.

2) You technically need to initialize the semihosting file descriptors with an open() call before using them. Many debuggers will allow you to use the descriptors without initialization, but not all will.

stn8188

10 hours ago

This is super cool, but the best part of the article to me is that I now have a new favorite hexapeak word: 0xF0CACC1A! (Spoken as someone who has recently gotten into bread making).

embeng4096

12 hours ago

This is really cool to see posted! Today I learned. I’ve used uart and RTT both but this is taking things a step further. Always love to see useful embedded content like this online and on hacker news

mrheosuper

11 hours ago

I always find Semihosting slow for logging purpose.