print float using newlib nano lib

Asked by Pitchumani Sivanupandi

Hi

I built newlib nano from the sources (with addition of --enable-newlib-io-float option) and trying following example:

#include <stdio.h>
float f1 = 12.34;
int main(void)
{
  printf ("test printf\n");
  printf ("float value: %f\n", f1);
  return 0;
}

$arm-none-eabi-gcc -Wl,-Map=output.map -mcpu=cortex-m3 -mthumb print.c -o print.elf -Dprintf=iprintf -u _printf_float -specs=nano.specs -lc -lnosys -lc

When I try to run using qemu-system-arm, it hangs.

$qemu-system-arm -cpu cortex-m3 -nographic -serial null -monitor null -semihosting -kernel ./print.elf

qemu-arm also fails with "uncaught target signal 11 (Segmentation fault)"
(version 1.4.1)

Am I missing something?

If I use "-specs=rdimon.specs -lc -lrdimon" instead of "-specs=nano.specs -lc -lnosys -lc", qemu print the content.

Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
chengbin
Solved:
Last query:
Last reply:
Revision history for this message
Pitchumani Sivanupandi (pitchumani-s) said :
#1

after linking with -lrdimon, qemu prints the content.
$arm-none-eabi-gcc -Wl,-Map=output.map -mcpu=cortex-m3 -mthumb print.c -o print.elf --specs=nano.specs -lc -lrdimon -u _printf_float

is linking with librdimon.a required always to make use of printf functions?

Revision history for this message
Best chengbin (can-finner) said :
#2

Please give below command a try:
$arm-none-eabi-gcc -Wl,-Map=output.map -mcpu=cortex-m3 -mthumb print.c -o print.elf -Dprintf=iprintf -u _printf_float -specs=nano.specs --specs=rdimon.specs -lc -lnosys -lc

Yes, you have to link rdimon stuff to have semihosting work.

Hoping this can help.

Revision history for this message
Pitchumani Sivanupandi (pitchumani-s) said :
#3

Thanks chengbin, that solved my question.