Page 2 of 2

Re: Virtual control interface via semihosting

Posted: Thu Apr 30, 2015 2:54 pm
by inca
I recently got semihosting up and going again using ChibiStudio (without chibi or chibi hal, unfortunely) and STM32 STD PERIPH lib.

The default startup.s and linker files from ST seem not to work with semihosting.

I've not testing the chibi startup.s and .ld script, but I'd imagine a similar outcome.

The only configuration that works for me is to use the GAE toolchain samples for semihosting in GAE/share/gcc-arm-none-eabi/samples/startup for the assembly .s and linker .ld files. I am not competent enough to tell what the meaningful differences are without a time-consuming search. I can say that the linker scripts are written in different styles and have different named sections and the startup.s has slightly different implementation to init the memory in ResetHandler().

Honestly, I'm not really sure why we've made such complex systems for describing the startup init. At the end of the day, we are moving data and that's it. Nothing else. Not sure why I need a fancy syntactical programming language of a linker script to map memory to data. And as for determining the requirements of a complete linker file? Good luck. Hence my default to the GAE versions. If it works for them, then it should work for GDB, too.

Re: Virtual control interface via semihosting

Posted: Thu Jun 20, 2019 10:39 am
by ceremcem
inca wrote:I recently got semihosting up and going again using ChibiStudio (without chibi or chibi hal, unfortunely) and STM32 STD PERIPH lib.



Is there an example project for introduction to semihosting?

Re: Virtual control interface via semihosting

Posted: Mon Jun 21, 2021 12:17 pm
by rolanddixon
This maybe an old thread, but for anyone stuck with semihosting with chibios and has landed here in a frantic google search, then there are a couple of things that need to be done to get it up and running for file I/O specifically. Interactions with stdin, stdout and stderr should work out the box.

You need to provide malloc, reentrant malloc, free and reentrant free implementations:

Code: Select all

void* malloc(size_t sz)
{
   if (sz == 0) return NULL;
   return chHeapAlloc( NULL, sz );
}

void* _malloc_r( struct _reent* r, size_t sz )
{
   (void) r;
   if (sz == 0) return NULL;
   return chHeapAlloc( NULL, sz );
}

void free(void* p)
{
   chHeapFree( p );
}

void _free_r(struct _reent* r, void* p)
{
   (void) r;
   chHeapFree( p );
}


Now the Makefile needs some linker flags:

Code: Select all

ULIBS = --specs=rdimon.specs -lrdimon -Xlinker -z -Xlinker muldefs


You will not need the syscalls.c provided with chibios as the rdimon lib provides the system calls required. The "-Xlinker -z -Xlinker muldefs" linker options are required as _malloc_r and _free_r are defined in newlib libc stdlib and, as such, the linker will complain about multiple definitions of the symbol.

Hope this helps...