Winarm and sprintf

Started by Taris October 29, 2009
I'am new in GCC compilers. How can i use sprintf function with WinArm gcc compiler (Version 20060606). When i try use the sprintf function , comes next error:

-------- begin --------
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.
Compiling: main.c
arm-elf-gcc -c -mcpu=arm7tdmi -I. -gdwarf-2 -DROM_RUN -Os -Wall -Wstrict-prototypes -Wcast-align -Wcast-qual -Wimplicit -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wunused -Wa,-adhlns=main.lst -std=gnu99 -MD -MP -MF .dep/main.o.d main.c -o main.o

Compiling: sysTime.c
arm-elf-gcc -c -mcpu=arm7tdmi -I. -gdwarf-2 -DROM_RUN -Os -Wall -Wstrict-prototypes -Wcast-align -Wcast-qual -Wimplicit -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wunused -Wa,-adhlns=sysTime.lst -std=gnu99 -MD -MP -MF .dep/sysTime.o.d sysTime.c -o sysTime.o

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

Compiling: uartISR.c
arm-elf-gcc -c -mcpu=arm7tdmi -I. -gdwarf-2 -DROM_RUN -Os -Wall -Wstrict-prototypes -Wcast-align -Wcast-qual -Wimplicit -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wunused -Wa,-adhlns=uartISR.lst -std=gnu99 -MD -MP -MF .dep/uartISR.o.d uartISR.c -o uartISR.o

Compiling: armVIC.c
arm-elf-gcc -c -mcpu=arm7tdmi -I. -gdwarf-2 -DROM_RUN -Os -Wall -Wstrict-prototypes -Wcast-align -Wcast-qual -Wimplicit -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wunused -Wa,-adhlns=armVIC.lst -std=gnu99 -MD -MP -MF .dep/armVIC.o.d armVIC.c -o armVIC.o

Compiling: lpcWD.c
arm-elf-gcc -c -mcpu=arm7tdmi -I. -gdwarf-2 -DROM_RUN -Os -Wall -Wstrict-prototypes -Wcast-align -Wcast-qual -Wimplicit -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wunused -Wa,-adhlns=lpcWD.lst -std=gnu99 -MD -MP -MF .dep/lpcWD.o.d lpcWD.c -o lpcWD.o

Assembling: crt0.S
arm-elf-gcc -c -mcpu=arm7tdmi -I. -x assembler-with-cpp -DROM_RUN -Wa,-adhlns=crt0.lst,-gdwarf-2 crt0.S -o crt0.o

Linking: main.elf
arm-elf-gcc -mcpu=arm7tdmi -I. -gdwarf-2 -DROM_RUN -Os -Wall -Wstrict-prototypes -Wcast-align -Wcast-qual -Wimplicit -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wshadow -Wstrict-prototypes -Wunused -Wa,-adhlns=main.o -std=gnu99 -MD -MP -MF .dep/main.elf.d main.o sysTime.o uart.o uartISR.o armVIC.o lpcWD.o crt0.o --output main.elf -nostartfiles -Wl,-Map=main.map,--cref -lc -lm -lc -lgcc -TLPC2103-ROM.ld
c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../arm-elf/lib\libc.a(freer.o): In function `_malloc_trim_r':
mallocr.c:(.text+0x48): undefined reference to `_sbrk_r'
mallocr.c:(.text+0x64): undefined reference to `_sbrk_r'
mallocr.c:(.text+0x84): undefined reference to `_sbrk_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../arm-elf/lib\libc.a(makebuf.o): In function `__smakebuf':
makebuf.c:(.text+0x3c): undefined reference to `_fstat_r'
makebuf.c:(.text+0x110): undefined reference to `isatty'
c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../arm-elf/lib\libc.a(mallocr.o): In function `_malloc_r':
mallocr.c:(.text+0x424): undefined reference to `_sbrk_r'
mallocr.c:(.text+0x4cc): undefined reference to `_sbrk_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../arm-elf/lib\libc.a(stdio.o): In function `__sclose':
stdio.c:(.text+0xc): undefined reference to `_close_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../arm-elf/lib\libc.a(stdio.o): In function `__sseek':
stdio.c:(.text+0x30): undefined reference to `_lseek_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../arm-elf/lib\libc.a(stdio.o): In function `__swrite':
stdio.c:(.text+0x84): undefined reference to `_lseek_r'
stdio.c:(.text+0xac): undefined reference to `_write_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../arm-elf/lib\libc.a(stdio.o): In function `__sread':
stdio.c:(.text+0xd0): undefined reference to `_read_r'
collect2: ld returned 1 exit status
make.exe: *** [main.elf] Error 1

> Process Exit Code: 2
> Time Taken: 00:01
Best regards

An Engineer's Guide to the LPC2100 Series

--- In l..., "Taris" wrote:
>
> I'am new in GCC compilers. How can i use sprintf function with WinArm gcc compiler (Version 20060606). When i try use the sprintf function , comes next error:
>

You are required to provide the system level code to implement a number of functions. Heap management is one of them (_sbrk).

I tend to like the code in JCWren's demo program www.jcwren.com/arm. Look in syscalls.c. You don't need to implement all of that code.

Note high tightly _sbrk is tied to symbols defined in the linker script. You may need to modify both.

You can Google around for more info.

Richard

Newlib is awsome, but it has high costs in code size (reeeealy high), also I
couldn't ger scanf to work.

2009/10/29 rtstofer

> --- In l... , "Taris"
> wrote:
> >
> > I'am new in GCC compilers. How can i use sprintf function with WinArm gcc
> compiler (Version 20060606). When i try use the sprintf function , comes
> next error:
> > You are required to provide the system level code to implement a number of
> functions. Heap management is one of them (_sbrk).
>
> I tend to like the code in JCWren's demo program www.jcwren.com/arm. Look
> in syscalls.c. You don't need to implement all of that code.
>
> Note high tightly _sbrk is tied to symbols defined in the linker script.
> You may need to modify both.
>
> You can Google around for more info.
>
> Richard
>
>
>


--- In l..., "Felipe de Andrade Neves L." wrote:
>
> Newlib is awsome, but it has high costs in code size (reeeealy high), also I
> couldn't ger scanf to work.

There are a lot of folks writing embedded applications who don't use newlib or any other canned library. There could be (probably are) licensing issues with newlib and I believe they have been discussed before. It's wasn't interesting to me because I don't do commercial development. Including printf() is expensive in terms of memory!

It is often easier to just write your own library functions. I tend to use the stuff from "The C Programming Language" by Kernighan/Ritchie and "Software Tools" by Kernighan/Plauger.

I know there are issues with re-entrancy but they only pop up if you have multiple tasks and most of my stuff doesn't use an RTOS.

Richard

It is true, the better choice is to write a own library.. Someday I will.

2009/10/29 rtstofer

> --- In l... , "Felipe de
> Andrade Neves L." wrote:
> >
> > Newlib is awsome, but it has high costs in code size (reeeealy high),
> also I
> > couldn't ger scanf to work.
> >
> > There are a lot of folks writing embedded applications who don't use newlib
> or any other canned library. There could be (probably are) licensing issues
> with newlib and I believe they have been discussed before. It's wasn't
> interesting to me because I don't do commercial development. Including
> printf() is expensive in terms of memory!
>
> It is often easier to just write your own library functions. I tend to use
> the stuff from "The C Programming Language" by Kernighan/Ritchie and
> "Software Tools" by Kernighan/Plauger.
>
> I know there are issues with re-entrancy but they only pop up if you have
> multiple tasks and most of my stuff doesn't use an RTOS.
>
> Richard
>
>
>


--- In l..., "Felipe de Andrade Neves L." wrote:
>
> It is true, the better choice is to write a own library.. Someday I will.
>

Don't put off until tomorrow what you can do today. The sooner you do it the more time and effort you will save in the long term.

When you do bite the bullet, make sure you avoid using the fragile format string-interpreting schemes as used by printf / fprintf / scanf etc. They are accidents just waiting to happen.

Any minimal time that you might save writing code which uses interfaces like this is quickly used up at testing time - and then some. In the worst case you might find yourself trying to sort out obscure runtime problems of your application's users on the other side or the world).

--
Chris Burrows
Armaide: LPC2xxx Integrated Development System
http://www.cfbsoftware.com/armaide

Am 10/29/2009 8:40 PM, also sprach rtstofer:
> I tend to use the stuff from "The C Programming Language" by Kernighan/Ritchie
It's amazing that a 31 year old IT book is still relevant.

rtstofer wrote:
>
> --- In l..., "Felipe de Andrade Neves L." wrote:
>> Newlib is awsome, but it has high costs in code size (reeeealy high), also I
>> couldn't ger scanf to work.
>>
>> There are a lot of folks writing embedded applications who don't use newlib or any other canned library. There could be (probably are) licensing issues with newlib and I believe they have been discussed before. It's wasn't interesting to me because I don't do commercial development. Including printf() is expensive in terms of memory!
>
> It is often easier to just write your own library functions. I tend to use the stuff from "The C Programming Language" by Kernighan/Ritchie and "Software Tools" by Kernighan/Plauger.
>
> I know there are issues with re-entrancy but they only pop up if you have multiple tasks and most of my stuff doesn't use an RTOS.
>
> Richard
>
Search the files in the FreeRTOS download for a file called
printf-stdarg.c. This has a very light weight version of sprintf in it
(not written by me, but the version in the download has a couple of bugs
fixed). It is limited however, for example it does not manage %f, etc.

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.SafeRTOS.com
Certified by T as meeting the requirements for safety related systems.
--- In l..., Dick Balaska wrote:
>
> Am 10/29/2009 8:40 PM, also sprach rtstofer:
> > I tend to use the stuff from "The C Programming Language" by Kernighan/Ritchie
> It's amazing that a 31 year old IT book is still relevant.
>

IT Book ???

You have never read have you ??!!!

don

--- In l..., "cfbsoftware1" wrote:
>
> --- In l..., "Felipe de Andrade Neves L." wrote:
> >
> > It is true, the better choice is to write a own library.. Someday I will.
> > Don't put off until tomorrow what you can do today. The sooner you do it the more time and effort you will save in the long term.
>
> When you do bite the bullet, make sure you avoid using the fragile format string-interpreting schemes as used by printf / fprintf / scanf etc. They are accidents just waiting to happen.
>
> Any minimal time that you might save writing code which uses interfaces like this is quickly used up at testing time - and then some. In the worst case you might find yourself trying to sort out obscure runtime problems of your application's users on the other side or the world).
>
> --
> Chris Burrows
> Armaide: LPC2xxx Integrated Development System
> http://www.cfbsoftware.com/armaide
>
I don't want to imply that I have ever rewritten the C library or even a minor portion of it. When I start a project, I get the serial port to work first. Then I write a few put??? functions to output hex bytes, shorts and words. Next I write a putnum routine to output decimal values and add a few string routines.

I avoid sprintf, printf and scanf at every opportunity. I don't always use fopen, fclose, fget and fput either. I just don't want the overhead.

But my projects tend to be pretty simple and don't tend to have a lot of user interaction. Formatted IO is usually a minor portion of the work.

However, as I don't use JTAG, having the various string and put functions simplifies debugging.

Richard