Semihosting with GNU ARM Embedded (LaunchPad) and GNU ARM Eclipse Debug Plugins
Join the DZone community and get the full member experience.
Join For Freein “ semihosting with kinetis design studio ” i used printf() to exchange text and data between the target board and the host using the debug connection. kinetis design studio (kds) has that semihosting baked into its libraries. what about if using the gnu arm embedded (launchpad) tools and libraries (see “ switching arm gnu tool chain and libraries in kinetis design studio “)? actually it requires two more steps, but is very easy too.
there are three things to be in place to use semihosting with the gnu arm embedded (launchpad) libraries:
- option in the gnu linker settings
- enabling semihosting in the debugger settings
- initializing the gnu libraries
linker option
to enable semihosting for the gnu arm embedded ( launchpad ) libraries, i need to add
--specs=rdimon.specs
to the linker options:
in case i’m using newlib-nano and want to use printf() and/or scanf() with floating point support, i need to pull in some symbols explicitly with the linker options ‘u':
-u _scanf_float -u _printf_float
debugger settings
in the gnu arm eclipse plugins, i need to enable semihosting.
segger j-link
for segger j-link, i enable the console in the launch configuration:
additionally i enable semihosting options in the startup options of the debugger:
p&e multilink
for p&e the following settings are used:
settings for openocd
the following settings are used for openocd:
initializing the gnu libraries
if you would now try to use semihosting with running the debugger, you probably will get error messages like this (e.g. from segger j-link):
warning: semihosting command sys_flen failed. handle is 0. warning: semihosting command sys_write failed. handle is 0. warning: semihosting command sys_write failed. handle is 0. warning: semihosting command sys_write failed. handle is 0.
the reason is that the semihosting needs to be enabled by the application. i need to call
initialise_monitor_handles()
before i’m using
printf()
:
1
2
3
4
5
6
7
8
|
extern
void
initialise_monitor_handles(
void
);
/* prototype */
int
main(
void
) {
initialise_monitor_handles();
/* initialize handles */
for
(;;) {
printf
(
"hello world!\r\n"
);
}
}
|
with this, i can use printf() and scanf() through a debugger connection.
summary
while i don’t like printf() for many reasons, sometimes it is useful to exchange data with the host. using semihosting no physical connection is required, as the communication goes through the debugger. it is somewhat intrusive, and adds code and data overhead, but the gnu arm embedded (launchpad) libraries (both newlib and newlib-nano) have semihosting built-in. it is a matter to enable it in the linker and debugger settings, and to initialize the handles in the application.
happy semihosting :-)
Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments