Semihosting with OpenOCD

Semihosting is essentially a console/terminal connection through the debugging channel instead of a separate UART connection. Semihosting is a concept making use of a supervisor call (interrupt) and special registers to exchange data between the debugger interface and the standard library. The standard library for semihosting is called rdimon and already precompiled for the device. You can use it by changing the following library definition in the waf scripts from the "Custom UART" implementation.

Link for Custom UART
        stlib        = ['m','c','nosys'],

against the semihosting one

Link for Semihosting
        stlib        = ['m','c','rdimon'],

The library has to be initialized, which can be achieved by the following modification:

Initialization Code
extern void initialise_monitor_handles(void);

int main()
{
  initialise_monitor_handles();

The semihosting has also to be initialized inside the OpenOCD debugger environment.

(warning)Semihosting requires a debugger attached.

This can be achieved by adding the command "monitor arm semihosting enable" to the GDB commands executed by the IDE inside the "Debug Settings...".

After starting a debug session, you have to switch the console window to the OpenOCD one: