Is it possible to send debugging messages from MCU to PC over SWD via GDB without interrupting the running code (ie. without using breakpoints), like we could do via UART of MCU by sacrificing 2 UART pins?

  • 1
    \$\begingroup\$ You mean Semihosting? \$\endgroup\$ – Jeroen3 Jun 20 at 9:05
  • \$\begingroup\$ Similar to semihosting: OpenOCD DCC, or SEGGER RTT. Both define a debug channel over JTAG/SWD that works in addition to gdb. \$\endgroup\$ – Turbo J Jun 20 at 9:18
  • \$\begingroup\$ @Jeroen3 It seems so, yes. I've searched my toolchains with the keyword "Semihosting" and I found this from stlink, this from ChibiOS. \$\endgroup\$ – ceremcem Jun 20 at 9:22
  • \$\begingroup\$ @Jeroen3 You may duplicate your comment as an answer so I could accept it. \$\endgroup\$ – ceremcem Jun 20 at 10:56
  • \$\begingroup\$ I have to say that this seems to me like asking how to make a Tesla into a tricycle. Debugging with SWD is so much more powerful than using print statements. With a decent IDE you should be able to trace whatever activity you want. \$\endgroup\$ – Elliot Alderson Jun 20 at 14:20

This can be achieved by something is called semihosting. How this is implemented depends on the specific devices and software you are using.

It works by using an SVC and BKPT instructions to trigger an action from the debugger host.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.