Semihosting

Semihosting is the use of a debugger as a source/sink for stdio with an embedded target. ARM’s SWO feature is used for this along with gcc’s RDI monitor implementation. OpenOCD since 0.8.0 has been able to work as a semihosting interface for ARM. What’s particularly great about semihosting is that your firmware can open/read/write files on the host! Paths are relative to the directory from which openocd is run).

NOTE An embedded application using semihosting WILL NOT WORK without a debugger attached. The application will hang on the first stdio call due to an unhandled debugger exception.

Enabling Semihosting

1. Alter the linker flags to let gcc know you’re using the RDI monitor:

LDFLAGS += --specs=rdimon.specs -lc -lrdimon

2. Make sure initialise_monitor_handles() is called before you use stdio. If you’re using the toolchain’s crt0 then this is already done for you:

extern void initialise_monitor_handles(void);

int main(void) {
    initialise_monitor_handles();

    printf("hello world!\n");

    /* etc. */
}

3. Make sure the OpenOCD command arm semihosting enable is executed before initialise_monitor_handles() is called. If using GDB, you can use the monitor command to do this:

arm-none-eabi-gdb -ex "target ext localhost:3333" -ex "monitor reset halt" -ex "monitor arm semihosting enable" app.elf

Resources

opencm3-stm32l1-semihosting-example-1c4ae95.tgz (2.53 KB) Andrew Kohlsmith, 07/07/2015 02:38 PM

Add picture from clipboard (Maximum size: 1 GB)