How print double with newlib-nano ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How print double with newlib-nano ?

1,569 Views
jeremypont
Contributor I

Hello,

I try to print double max value (DBL_MAX) on uart and I have hardfault interrupt.

I use newlib-nano with flag -u _printf_float.

I have the same issue with standard libc.

If I  print "small" double, it works.

I use kds3.0 with gcc 4.8.

My targer is kl46z on freedom board.

Do you have any idea why it doesn't work ?

Thanks in advance,

Jeremy

Labels (1)
0 Kudos
5 Replies

1,037 Views
jeremypont
Contributor I

Hello Alice,

Yes, your example meet my requirement.

I am using cortex m0+ and you seem test on cortex m4 (k22). Am I wrong ?

CM0+ doesn't have fpu, maybe something is wrong with link option ?

My link option are :

arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -O3 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall  -g3 -T "../MKL46Z256xxx4_flash.ld" -Xlinker --gc-sections -Wl,-Map,"FreedomKL46Z.map" --specs=nano.specs -u _printf_float -specs=nosys.specs -Xlinker -z -Xlinker muldefs -o "FreedomKL46Z.elf" -Wl,--start-group  [*.o files] -lc -lgcc -Wl,--end-group -Lm

Thanks for your help,

Jeremy

0 Kudos

1,037 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Jeremy,

I also use the board of FRDM-KL46.

Please add     -specs=rdimon.specs   into linker flag :

pastedImage_1.png

I also attached my project , you can test on your side .

Hope it helps


Have a great day,
Alice Yang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,037 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Jeremy,

Could you please show your code for print, for sorry i don't know

what's the "double max value" and "small" double .

BR

Alice

0 Kudos

1,037 Views
jeremypont
Contributor I

Hello Alice,

I try to print value with this line :

double doubleValue = DBL_MAX;

printf("doubleValue : %.16lE - %.16lf\n", doubleValue, doubleValue);

When I say "small" double, I mean doubleValue = 1.825 for example.

Double maximum value is DBL_MAX from float.h.

Jeremy

0 Kudos

1,037 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Jeremy,

Sorry i do not know what do you want to do , i test on my side ,the result is that :

pastedImage_1.png

Does it can meet your requirement ?

If not , please describe it to me what the result you want to .

If yes, i will tell you how to configure on KDS .

BR

Alice

0 Kudos