Erich Styger recently posted a great tutorial on how to add console functionality using Single Wire Output (SWO) on ARM Cortex-M targets.
This inspired me to write a more general post on debug output (“printf”) implementations on embedded target, including SWO and RTT.
Debug Output from a Target
There are different methods to get debug output from the target application.
Since the early days of embedded systems, there have been hardware dependent solutions like using a UART or USB CDC. But a UART may already be used by the application and CDC requires a USB stack and a USB connector on the target hardware.
The first software solution is semihosting. With semihosting, the CPU halts to print output and is restarted “behind the scenes” by the debugger. Printing one message can take anywhere from several milliseconds to more than one hundred milliseconds, as it is an expensive operation. The debugger needs to realize that the target has stopped execution, reads registers and memory, writes memory, and can then restart the CPU. This means the target CPU does not run for this period of time. Therefore semihosting can simply not be used for applications which require real time behaviour, such as communication stacks. Additionally the semihosting implementation is debugger dependent, and applications which use semihosting might not run without a debugger connected.
And then there are ARM’s SWO trace port and SEGGER’s Real Time Transfer (RTT).