Is it possible to send arbitrary messages (as with printf()) via SWD for debugging?

  • \$\begingroup\$ Yes, but you need software on the device to stage messages or bytes (rather than writing them to the traditional UART), and software on the debug host to claim them. Various open and proprietary implementations exist. \$\endgroup\$ Feb 3, 2015 at 17:27

1 Answer 1


Yes, its called "Retargeting printf via ITM". its very easy to do with STM32.


You just need write a small "retarget.c" file. The key to this is using the "ITM_SendChar()" function. Great tutorial here: http://www.doulos.com/knowhow/arm/Retargetting_a_C_library_function/

I've personally have done this in the past and it works amazing in keil. Keil also has a bunch of tutorials on this. If you still have trouble, let me know

  • \$\begingroup\$ Googling "STM32 SemiHosting" gave me a bunch of solutions involing custom assembly programs and modifying the linker. Is this what you mean by "very easy" or am I looking at a wrong place? \$\endgroup\$
    – andrey
    Feb 3, 2015 at 17:51
  • \$\begingroup\$ Looking at the wrong place. Use the key word "retargeting" or "retarget" \$\endgroup\$
    – hassan789
    Feb 3, 2015 at 18:00
  • \$\begingroup\$ See edits above in answer \$\endgroup\$
    – hassan789
    Feb 3, 2015 at 18:05
  • \$\begingroup\$ But that method is using UART1 and not SWD for data transmission? \$\endgroup\$
    – andrey
    Feb 3, 2015 at 18:08
  • \$\begingroup\$ just realized that myself...see edit \$\endgroup\$
    – hassan789
    Feb 3, 2015 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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