UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Newbie lvjudge1
Newbie
7,858 Views
Registered: ‎03-02-2010

Problem using sprintf

I have encountered some issues trying to use the sprintf function in code for the microblaze. The code compiles and links fine without the sprintf statement, but errors are generated whenever sprintf is used:

ECE4534@ecexilinxvm c:/Spring10-1/Applications/hw4
$ make
mb-gcc -Wall -O2 -c myCcode.cpp
mb-gcc -o Lab2.elf -Wall -O2 -Wl,-T -Wl,linker.ld -Wl,-x rotary.o lab2_support.o
 myCcode.o
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: region ilmb_cntlr_dlmb_cntlr is full
 (Lab2.elf section .text)
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: section .init [00000050 -> 00000077]
 overlaps section .text [00000050 -> 0000fa1f]
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: section .fini [00000078 -> 00000093]
 overlaps section .text [00000050 -> 0000fa1f]
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: section .rodata [00000094 -> 000004f
f] overlaps section .text [00000050 -> 0000fa1f]
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: section .data [00000500 -> 00000af7]
 overlaps section .text [00000050 -> 0000fa1f]
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: section .ctors [00000af8 -> 00000aff
] overlaps section .text [00000050 -> 0000fa1f]
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: section .dtors [00000b00 -> 00000b07
] overlaps section .text [00000050 -> 0000fa1f]
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: section .eh_frame [00000b08 -> 00000
b0b] overlaps section .text [00000050 -> 0000fa1f]
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: section .jcr [00000b0c -> 00000b0f]
overlaps section .text [00000050 -> 0000fa1f]
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: section .bss [00000b10 -> 00000bc7]
overlaps section .text [00000050 -> 0000fa1f]
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: Lab2.elf: section .text lma 0x50 ove
rlaps previous sections
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: Lab2.elf: section .fini lma 0x78 ove
rlaps previous sections
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: Lab2.elf: section .rodata lma 0x94 o
verlaps previous sections
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: Lab2.elf: section .data lma 0x500 ov
erlaps previous sections
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: Lab2.elf: section .ctors lma 0xaf8 o
verlaps previous sections
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: Lab2.elf: section .dtors lma 0xb00 o
verlaps previous sections
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: Lab2.elf: section .eh_frame lma 0xb0
8 overlaps previous sections
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/bin/ld.real: Lab2.elf: section .jcr lma 0xb0c ove
rlaps previous sections
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/lib/libxil.a(sbrk.o): In function `sbrk':
/edkgnu/jm/mb/build/nt/bld_gcc/gcc/libgloss/microblaze/sbrk.c:41: undefined refe
rence to `_heap_end'
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/lib/libxil.a(write.o): In function `write':
/edkgnu/jm/mb/build/nt/bld_gcc/gcc/libgloss/microblaze/write.c:36: undefined ref
erence to `outbyte'
/edkgnu/jm/mb/build/nt/bld_gcc/gcc/libgloss/microblaze/write.c:34: undefined ref
erence to `outbyte'
/cygdrive/c/EDK/gnu/microblaze/nt/bin/../lib/gcc/microblaze-xilinx-elf/4.1.1/../
../../../microblaze-xilinx-elf/lib/libxil.a(read.o): In function `read':
/edkgnu/jm/mb/build/nt/bld_gcc/gcc/libgloss/microblaze/read.c:35: undefined refe
rence to `inbyte'
collect2: ld returned 1 exit status
make: *** [Lab2.elf] Error 1


I am trying to use sprintf to format integers as strings. The following code block produces the error (this is not my whole code, just an example that works as long as sprintf is not used):

{
        char AMFreq_str [5]={0};
        sprintf(AMFreq_str, "%d", currentAMFrequency);
        int startPoint=6;
        if (currentAMFrequency<1000)
        {
            AMFreq_str[3]=(char)NULL;
            startPoint=7;
        }
       
        for (int i=0; i<int(strlen(AMFreq_str)); i++)
        {
            if (AMFreq_str[i]!=(char)NULL)
            lcd_putc(AMFreq_str[i], (i+startPoint));
            }
    }

 

Not sure if it is necessary/helpful but my makefile is included below:

Lab2.elf : myCcode.o rotary.o lab2_support.o
    mb-gcc -o Lab2.elf -Wall -O2 -Wl,-T -Wl,linker.ld -Wl,-x rotary.o lab2_support.o myCcode.o

myCcode.o: myCcode.cpp
    mb-gcc -Wall -O2 -c myCcode.cpp

rotary.o: rotary.s
    mb-gcc -Wall -O2 -c rotary.s

 

I simply cannot figure out what I am doing wrong here. Can anyone offer some advice or insight into what may be going on?

 

Thanks!

Tags (2)
0 Kudos
4 Replies
Explorer
Explorer
7,820 Views
Registered: ‎11-13-2007

Re: Problem using sprintf

Try posting in the EDK forum.
0 Kudos
Highlighted
Newbie jasonjiang
Newbie
6,464 Views
Registered: ‎07-20-2010

Re: Problem using sprintf

I got the same issue.

 

You have to use Microblaze library, my_sprintf(), defined in xil_printf.c like below:


/*------------------------------------------------

-------------------------*/

//
// This is the start of the file for other *printf functions
// that are used in the embedded system.  For some reason,
// the standard printf functions provided in the Xilinx
// library do not seem to work.
//

int my_sprintf(char *buff, char *fmt, ... )
{
    va_list ap;
    int     length;

    va_start(ap, fmt);
    length = xil_vsprintf(buff, fmt, ap);
    va_end(ap);

    return (length);
}

Tags (1)
0 Kudos
Moderator
Moderator
6,409 Views
Registered: ‎09-12-2007

Re: Problem using sprintf

The simple answer is that the sprintf (and the printf for that matter) take up alot of  memory. If you are using printf, try use xil_printf. Below is a list of the functions and the code sizes:

 

printf() 51788 None, full featured 

iprintf() 18294 No floating point, reentrant 

xil_printf() 2953 No floating point, not reentrant(single thread only), no longlong(64 bit) 

putnum() 284 Integer to HEX only, no other formats 

print() 185 No numbers output, just strings 

0 Kudos
Visitor stanfda
Visitor
6,396 Views
Registered: ‎08-24-2011

Re: Problem using sprintf

I've measured sprintf to add 30kb to the size of my files. I'm executing it out of an external memory though, not internal flash and can deal with the hit (although I hadn't seen my_sprintf before). 

0 Kudos