EmbDev.net

Forum: ARM programming with GCC/GNU tools newlib printf problem with floating point


von Batoo L. (batoo)


Attached files:

Rate this post
useful
not useful
Hello,

I am learning WinARM and newlib, I am using WinARM version 20060606, and
my target board is Keil MCB2300 demo board with LPC2387.

The attached file is my source code, my project is modify from
http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/lpc2378_demo1_20070629.zip,
I add the syscall.c for newlib, it works fine to print integer to COM0
or COM1, but it doesn’t work with floating point (e.g. printf(“%f”,
3.14);), the processor always crash when I print a floating point.
(sorry, I can’t sure what happen because I don’t have a JTAG debugger, I
guess the program is dead because the LED doesn’t blinking anymore.)

Could there something be wrong with the syscall.c?

One more question, does newlib-lpc library can support LPC23XX serial?

compiler message as below:
-------- begin (mode: ROM_RUN) --------
arm-elf-gcc (GCC) 4.1.1 (WinARM)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.


Assembling (ARM-only): Common/src/Startup.S
arm-elf-gcc -c -mcpu=arm7tdmi-s -mthumb-interwork -I. -x
assembler-with-cpp -DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2378__
-Wa,-adhlns=Common/src/Startup.lst,-gdwarf-2 Common/src/Startup.S -o
Common/src/Startup.o

Assembling (ARM-only): Common/src/swi_handler.S
arm-elf-gcc -c -mcpu=arm7tdmi-s -mthumb-interwork -I. -x
assembler-with-cpp -DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2378__
-Wa,-adhlns=Common/src/swi_handler.lst,-gdwarf-2
Common/src/swi_handler.S -o Common/src/swi_handler.o

Compiling C: main.c
arm-elf-gcc -c -mthumb -mcpu=arm7tdmi-s -mthumb-interwork -I. -gdwarf-2
-DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2378__  -Os -Wall
-Wcast-align -Wimplicit  -Wpointer-arith -Wswitch -ffunction-sections
-fdata-sections -Wredundant-decls -Wreturn-type -Wshadow -Wunused
-Wa,-adhlns=main.lst  -ICommon/inc -Wcast-qual -MD -MP -MF .dep/main.o.d
-Wnested-externs  -std=gnu99 -Wmissing-prototypes  -Wstrict-prototypes
-Wmissing-declarations main.c -o main.o
main.c: In function 'main':
main.c:99: warning: unused variable 'f'
main.c:127: warning: 'errno' is used uninitialized in this function

Compiling C: fio.c
arm-elf-gcc -c -mthumb -mcpu=arm7tdmi-s -mthumb-interwork -I. -gdwarf-2
-DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2378__  -Os -Wall
-Wcast-align -Wimplicit  -Wpointer-arith -Wswitch -ffunction-sections
-fdata-sections -Wredundant-decls -Wreturn-type -Wshadow -Wunused
-Wa,-adhlns=fio.lst  -ICommon/inc -Wcast-qual -MD -MP -MF .dep/fio.o.d
-Wnested-externs  -std=gnu99 -Wmissing-prototypes  -Wstrict-prototypes
-Wmissing-declarations fio.c -o fio.o

Compiling C: uart.c
arm-elf-gcc -c -mthumb -mcpu=arm7tdmi-s -mthumb-interwork -I. -gdwarf-2
-DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2378__  -Os -Wall
-Wcast-align -Wimplicit  -Wpointer-arith -Wswitch -ffunction-sections
-fdata-sections -Wredundant-decls -Wreturn-type -Wshadow -Wunused
-Wa,-adhlns=uart.lst  -ICommon/inc -Wcast-qual -MD -MP -MF .dep/uart.o.d
-Wnested-externs  -std=gnu99 -Wmissing-prototypes  -Wstrict-prototypes
-Wmissing-declarations uart.c -o uart.o

Compiling C: syscall.c
arm-elf-gcc -c -mthumb -mcpu=arm7tdmi-s -mthumb-interwork -I. -gdwarf-2
-DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2378__  -Os -Wall
-Wcast-align -Wimplicit  -Wpointer-arith -Wswitch -ffunction-sections
-fdata-sections -Wredundant-decls -Wreturn-type -Wshadow -Wunused
-Wa,-adhlns=syscall.lst  -ICommon/inc -Wcast-qual -MD -MP -MF
.dep/syscall.o.d -Wnested-externs  -std=gnu99 -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations syscall.c -o syscall.o
syscall.c:45: warning: no previous prototype for '_read_r'
syscall.c:50: warning: no previous prototype for '_write_r'
syscall.c:55: warning: no previous prototype for '_open_r'
syscall.c:79: warning: no previous prototype for '_close_r'
syscall.c:84: warning: no previous prototype for '_lseek_r'
syscall.c:89: warning: no previous prototype for '_fstat_r'
syscall.c:136: warning: no previous prototype for '_sbrk_r'
syscall.c: In function 'com1_write_r':
syscall.c:162: warning: pointer targets in passing argument 2 of
'UARTSend' differ in signedness
syscall.c: In function 'com0_write_r':
syscall.c:196: warning: pointer targets in passing argument 2 of
'UARTSend' differ in signedness

Compiling C: Common/src/timer.c
arm-elf-gcc -c -mthumb -mcpu=arm7tdmi-s -mthumb-interwork -I. -gdwarf-2
-DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2378__  -Os -Wall
-Wcast-align -Wimplicit  -Wpointer-arith -Wswitch -ffunction-sections
-fdata-sections -Wredundant-decls -Wreturn-type -Wshadow -Wunused
-Wa,-adhlns=Common/src/timer.lst  -ICommon/inc -Wcast-qual -MD -MP -MF
.dep/timer.o.d -Wnested-externs  -std=gnu99 -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations Common/src/timer.c -o
Common/src/timer.o

Compiling C: Common/src/target.c
arm-elf-gcc -c -mthumb -mcpu=arm7tdmi-s -mthumb-interwork -I. -gdwarf-2
-DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2378__  -Os -Wall
-Wcast-align -Wimplicit  -Wpointer-arith -Wswitch -ffunction-sections
-fdata-sections -Wredundant-decls -Wreturn-type -Wshadow -Wunused
-Wa,-adhlns=Common/src/target.lst  -ICommon/inc -Wcast-qual -MD -MP -MF
.dep/target.o.d -Wnested-externs  -std=gnu99 -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations Common/src/target.c -o
Common/src/target.o

Compiling C: Common/src/irq.c
arm-elf-gcc -c -mthumb -mcpu=arm7tdmi-s -mthumb-interwork -I. -gdwarf-2
-DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2378__  -Os -Wall
-Wcast-align -Wimplicit  -Wpointer-arith -Wswitch -ffunction-sections
-fdata-sections -Wredundant-decls -Wreturn-type -Wshadow -Wunused
-Wa,-adhlns=Common/src/irq.lst  -ICommon/inc -Wcast-qual -MD -MP -MF
.dep/irq.o.d -Wnested-externs  -std=gnu99 -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations Common/src/irq.c -o
Common/src/irq.o

Linking: main.elf
arm-elf-gcc -mthumb -mcpu=arm7tdmi-s -mthumb-interwork -I. -gdwarf-2
-DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2378__  -Os -Wall
-Wcast-align -Wimplicit  -Wpointer-arith -Wswitch -ffunction-sections
-fdata-sections -Wredundant-decls -Wreturn-type -Wshadow -Wunused
-Wa,-adhlns=Common/src/Startup.lst  -ICommon/inc -Wcast-qual -MD -MP -MF
.dep/main.elf.d Common/src/Startup.o  Common/src/swi_handler.o   main.o
fio.o uart.o syscall.o Common/src/timer.o Common/src/target.o
Common/src/irq.o     --output main.elf -nostartfiles
-Wl,-Map=main.map,--cref,--gc-sections -lc  -lm  -L../arm-elf/lib
-lnosys -TCommon//LPC2378-ROM.ld

Creating load file for Flash: main.hex
arm-elf-objcopy -O ihex main.elf main.hex

Creating load file for Flash: main.bin
arm-elf-objcopy -O binary main.elf main.bin

Creating Extended Listing: main.lss
arm-elf-objdump -h -S -C main.elf > main.lss

Creating Symbol Table: main.sym
arm-elf-nm -n main.elf > main.sym

Size after:
main.elf  :
section            size         addr
.text             12712            0
.data              2104   1073741824
.bss                204   1073743928
.stack             1024   1073744384
.comment            918            0
.debug_aranges      680            0
.debug_pubnames     924            0
.debug_info        9787            0
.debug_abbrev      2195            0
.debug_line        2272            0
.debug_frame        996            0
.debug_str         2324            0
.debug_loc         2816            0
.debug_ranges        48            0
Total             39004



Errors: none
-------- end --------

Thanks for any help.
Batoo

von Batoo L. (batoo)


Rate this post
useful
not useful
Batoo Lee wrote:

Hi everyone,

I can printf float/double well finally,
in the past few days I studied uC/OS-II and
changed processor mode form USER to SVC mode,
and the printf works well with float/double.
so I guess newlib needs run in privileged mode.

von Clifford S. (clifford)


Rate this post
useful
not useful
Batoo Lee wrote:
> so I guess newlib needs run in privileged mode.

Not in my experience.

von Batoo L. (batoo)


Rate this post
useful
not useful
Clifford Slocombe wrote:
> Batoo Lee wrote:
>> so I guess newlib needs run in privileged mode.
>
> Not in my experience.

Hi Clifford,
I check this problem again,
you are correct.
The problem doesn't cause by operating mode,
the problem is the stack size too small,
originally the stack size is 0x100,
and I change it to 0x400 can fix the problem.
Thank you,
Batoo

von Clifford S. (clifford)


Rate this post
useful
not useful
Batoo Lee wrote:

> the problem is the stack size too small,
> originally the stack size is 0x100,
> and I change it to 0x400 can fix the problem.

Ah! Sorry, should have noticed that, formatted I/O does need about 4k
for stack.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.