Semihosting allows your program to use I/O calls and direct them to the ADT Semihosting window. To use semihosting in your project:
· Add printf calls in your program for diagnostic purposes. Output only appears when a ‘\n’ newline character is encountered in the output stream.
· Enable the semihosting option in the Build Options.
· While your program is running under the debugger, printf output will appear in the ADT semihosting window.
To support semihosting, the following “behind the scenes” work is done for you. If you are enabling semihosting for an existing project, you must make this change by hand; however, if you are starting a new project using one of the new project wizards, then this is done for you automatically.
The startup file must contain a call to a function initialise_monitor_handle prior to calling main. The following is added to the startup template files provided by ImageCraft. For an existing project, you must add the call to your startup file.
You can use a macro define for printf such that, if semihosting is on, it will be defined as printf, or as nothing (a null expression) otherwise:
#define PRINTF printf
#endif // _INIT_SEMIHOSTING_
The __INIT_SEMIHOSTING__ macro is defined automatically by the CodeBlocks IDE if you enable the semihosting checkbox.
The following is for informational purposes. Their actions are performed automatically by the IDE, when the semihosting option is enabled:
· The macro define __INIT_SEMIHOSTING__ is added to the compiler option, so the proper code fragment in the startup file is built.
· -specs=rdimon.specs is added to the linker options.
· The .prj project file has an addition entry: Debug_EnableSemihosting=1