How can I print an Integer

ChibiOS public support forum for topics related to the STMicroelectronics SPC56x family of automotive micro-controllers.
Post Reply
GianlucaLaManna
Posts: 25
Joined: Fri Mar 13, 2015 12:12 pm

How can I print an Integer

Post by GianlucaLaManna »

Hello.
I use the board SPC560P-DISP.
How can I print an Integer with Tera Term through a serial connection?
I use the function chnWriteTimeout to print a string. So:

Code: Select all

chnWriteTimeout(&SD1, (uint8_t *)"Hello World!\r\n", 14, TIME_INFINITE);

But an Integer?
I tried to use chprintf, but not working.
thanks.

Best regards
Gianluca
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How can I print an Integer

Post by Giovanni »

GianlucaLaManna wrote:I tried to use chprintf, but not working.


Define "not working".

Giovanni
GianlucaLaManna
Posts: 25
Joined: Fri Mar 13, 2015 12:12 pm

Re: How can I print an Integer

Post by GianlucaLaManna »

Yes. It does not recognize the function chprintf. I included the header chprintf.h

Code: Select all

uint32_t number=25;

chprintf(&SD1, "%u \n\r", number);


The error is:

Code: Select all

main.c:(.text_vle.main+0x10c): undefined reference to `chprintf'
collect2: ld returned 1 exit status
make: *** [build/out.elf] Error 1


Gianluca
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How can I print an Integer

Post by Giovanni »

Is the "Output Formatter" component included in your project? chprintf is included there, it requires ChibiOS too.

Giovanni
GianlucaLaManna
Posts: 25
Joined: Fri Mar 13, 2015 12:12 pm

Re: How can I print an Integer

Post by GianlucaLaManna »

Sorry, I don't know and I don't understand.

This is my include in my code:

Code: Select all

#include "components.h"
#include "adc_lld_cfg.h"

#include "pwm_lld_cfg.h"
#include "icu_lld_cfg.h"



I have to include something else? Or enable some option in the configuration.xml file?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How can I print an Integer

Post by Giovanni »

Please look at all the ChibiOS demos included in SPC5Studio, all of them use chprintf(). You could start from one of those demos for your experiments.

Giovanni
GianlucaLaManna
Posts: 25
Joined: Fri Mar 13, 2015 12:12 pm

Re: How can I print an Integer

Post by GianlucaLaManna »

Ok, but in the demo for my board using only chnWriteTimeout. Thanks anyway. :)

Gianluca.
GianlucaLaManna
Posts: 25
Joined: Fri Mar 13, 2015 12:12 pm

[Solved] How can I print an Integer

Post by GianlucaLaManna »

I used os-less.
Now I use chibios.

I solved so:

Code: Select all

chprintf((BaseSequentialStream *)&SD1, "Value of number is:  %d", number);


Thanks.

Best regards
Gianluca.
Post Reply