454 CHAPTER 19 Semihosting
J-Link / J-Trace (UM08001) ©
2004-2017 SEGGER Microcontroller GmbH & Co. KG
19.1 Introduction
Semihosting is a mechanism for ARM based target devices to provide a way to com-
municate/interact with a host system (the PC where the debugger is running on) to
allow different operations to be performed /automatized. Typical use-cases for semi-
hosting are:
• Calls to printf() in the target to be forwarded to the host system and then output
in a console/terminal on the host
• Calls to scanf() to retrieve user input entered in a console/terminal on the host
and then being received and evaluated by the target
• Performing file I/O operations on the host system (reading / writing files)
• Writing a flashloader that reads the bin file to be flashed from the host system
and performs the flashing operation chunk-wise
Most standard I/O libraries for embedded applications come with semihosting imple-
mentations for printf() and scanf().
19.1.1 Advantages
• Provides standardized commands for file I/O operations on the host, allowing rel-
atively complex operations with minimal logic in the target application
• Does not need chip-specific hardware capabilities
• Semihosting handling is natively supported by many debuggers/IDEs, for exam-
ple GDB.
19.1.2 Disadvantages
• Target CPU is halted on each semihosting command, debugger evaluates the
semihosting command and restarts the CPU. This affects real-time behavior of
the system.