How to cast an integer/float into a string?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Noname
Posts: 36
Joined: Wed Oct 09, 2013 7:14 pm

How to cast an integer/float into a string?

Post by Noname »

Hello

Everyting is in the title :D.

I have some values from I2C sensors I want to display on a character display (uGFX). That's why I need to convert the int/floar values into strings.

Thanks
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to cast an integer/float into a string?

Post by Giovanni »

Hi,

Using sprintf() for example, it is no different from a normal C application. You may also use chprintf() but you need to create a stream writer to a string buffer.

Giovanni
Noname
Posts: 36
Joined: Wed Oct 09, 2013 7:14 pm

Re: How to cast an integer/float into a string?

Post by Noname »

Hello

Yes that is what I have tried before but the compiler doesn't seem to like the sprintf function :D.
I don't know why.

Linking build/ch.elf
c:/chibistudio/tools/gnu tools arm embedded/4.7 2013q2/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv7e-m\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
collect2.exe: error: ld returned 1 exit status
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to cast an integer/float into a string?

Post by Giovanni »

Hi,

This is because you must provide a _sbrk() implementation to the compiler. The compiler does not provide syscalls for a bare machine. the documentation is here: https://sourceware.org/newlib/libc.html#Syscalls

It is not complex, there is also an implementation under ./os/various/syscall.c but it was done for the YAGARTO compiler and must be adapted.

Giovanni
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

Re: How to cast an integer/float into a string?

Post by russian »

Noname wrote:Everyting is in the title :D.Thanks


Giovanni is a kind man.

Using the word "cast" in this context tells me that you really need to figure out a bit of the fundamentals - like a couple of fundamental differences between primitive types and human-readable strings...
Post Reply