Virtual control interface via semihosting

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

inca
Posts: 37
Joined: Mon Apr 22, 2013 12:08 am

Re: Virtual control interface via semihosting

Postby inca » Thu Apr 30, 2015 2:54 pm

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.

ceremcem
Posts: 67
Joined: Mon Aug 10, 2015 6:57 am
Has thanked: 7 times
Been thanked: 6 times

Re: Virtual control interface via semihosting

Postby ceremcem » Thu Jun 20, 2019 10:39 am

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?

rolanddixon
Posts: 26
Joined: Wed Feb 25, 2015 9:45 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Virtual control interface via semihosting

Postby rolanddixon » Mon Jun 21, 2021 12:17 pm

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...


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 13 guests