sprintf issue - missing syscalls

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

sprintf issue - missing syscalls

Postby Tectu » Mon May 21, 2012 11:19 pm

Hey there,

I get some problems using sprintf() because of missing syscalls:

Code: Select all

Linking build/vitfit.elf
/home/tectu/projects/resources/arm-toolchain/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m/libc.a(lib_a-abort.o): In function `abort':
abort.c:(.text.abort+0xa): undefined reference to `_exit'
/home/tectu/projects/resources/arm-toolchain/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m/libc.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text._kill_r+0xe): undefined reference to `_kill'
/home/tectu/projects/resources/arm-toolchain/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m/libc.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'
collect2: ld returned 1 exit status
make: *** [build/vitfit.elf] Error 1


I found syscalls like _write, _sbrk, _read etc. with google, but none of these.

Does anyone "use successfully sprintf() with chibios?"

Also, is there a reason why these syscalls aren't in chibios/various/syscalls.c ?

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: sprintf issue - missing syscalls

Postby utzig » Mon May 21, 2012 11:44 pm

Basically the reason is that ChibiOS is not a Unix clone. It's an RTOS made to run on constrained hardware. Also there's no kernel/userspace separation and there's no libc library.

If you are in the mood you could easily do your own sprintf using os/various/chprintf.c. Change the prototype from:

void chprintf(BaseSequentialStream *chp, const char *fmt, ...)

to

void chsprintf(char *str, const char *fmt, ...)

and everytime you have a call to _putc change it to use str. For example change:

_putc(chp, (uint8_t)c);

to

*str++ = (uint8_t)c;

This should basically do the trick.

Fabio Utzig

mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Location: Karlsruhe, Germany
Been thanked: 1 time
Contact:

Re: sprintf issue - missing syscalls

Postby mabl » Tue May 22, 2012 6:48 am

Alternatively you could also just fill the stubs. I've never run in trouble with these:

https://github.com/mabl/ChibiOS-Infrast ... bs/stubs.c

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: sprintf issue - missing syscalls

Postby Tectu » Tue May 22, 2012 11:59 am

Thanks for the stubs, mabl. They do indeed work without any problems.

I've one more, related question: I read everywhere, also in the ChibiOS wiki, that functions like sprintf() etc. do take a huge amount of memory. But when I create the workspace for a thread which uses sprintf(), how do I terminate the size of it?
I once read in the wiki about "finding it out" by just moving it from a big value down, until it dosen't work anymore. But isn't there any more "proper" way to do that?

mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Location: Karlsruhe, Germany
Been thanked: 1 time
Contact:

Re: sprintf issue - missing syscalls

Postby mabl » Tue May 22, 2012 12:02 pm

Tectu wrote:I've one more, related question: I read everywhere, also in the ChibiOS wiki, that functions like sprintf() etc. do take a huge amount of memory. But when I create the workspace for a thread which uses sprintf(), how do I terminate the size of it?
I once read in the wiki about "finding it out" by just moving it from a big value down, until it dosen't work anymore. But isn't there any more "proper" way to do that?

There is the option to initialize the stack space full with 0x55 which is overwritten when the stack is used. The eclipse plugin supports measuring the used space that way. Of cause you have to take care that you hit all possible code path before this value is correct.

hazelnusse
Posts: 77
Joined: Thu May 24, 2012 8:01 am

Re: sprintf issue - missing syscalls

Postby hazelnusse » Wed Nov 28, 2012 9:45 pm

mabl,
It looks like you removed that repository from your github -- do you have these function stubs elsewhere?

Thanks,
Luke

mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Location: Karlsruhe, Germany
Been thanked: 1 time
Contact:

Re: sprintf issue - missing syscalls

Postby mabl » Wed Nov 28, 2012 9:50 pm

Yeah, always meant to clean it up and put it back up somwhen in the future... I am not at my development machine now - I've posted earlier versions of the stubs in the other threads.

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: sprintf issue - missing syscalls

Postby Tectu » Sat Dec 01, 2012 10:38 am

Hey there,

Here are the files you need (attachment below).


~ Tectu
Attachments
stubs.zip
(1018 Bytes) Downloaded 957 times


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 5 guests