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: 
Observer jishnukd
Observer
11,624 Views
Registered: ‎06-16-2009

Array and xil_printf problem with Microblaze and ML505

Jump to solution
Hello,

I'm using the Virtex-5 ML505 board. I've loaded Microblaze onto a single-processor system. And written the following as the application code.

#include "xparameters.h"
#include "stdio.h"
#include "xbasic_types.h"
#include "xgpio.h"
#include "gpio_header.h"
#include "xsysace.h"
#include "sysace_header.h"
#include "uartlite_header.h"

int main (void) {
    Xuint32 i, *arr1;
    for(i=0;i<40;i++)
        arr1[i]=i;
    print("\r\n ARR1 ");
    print("\r\n **** ");
    for(i=0;i<40;i++)
        xil_printf("\r\n %d > %d", i, arr1[i]);
    return 0;
}

I think I should get the values 0-39 in the respective indices of the array. But I don't get the correct output on Hyperterminal. I get the outputs like 0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13... (4, 9, 14 etc. skipped!) and some junk numbers in the later locatins (above 30 or so). Please help me troubleshooting it.

0 Kudos
1 Solution

Accepted Solutions
Xilinx Employee
Xilinx Employee
13,855 Views
Registered: ‎01-18-2008

Re: Array and xil_printf problem with Microblaze and ML505

Jump to solution
arr1 is not initialized, so you are writing to invalid locations. Instead of defining it as *arr1, use arr1[40]
11 Replies
Xilinx Employee
Xilinx Employee
13,856 Views
Registered: ‎01-18-2008

Re: Array and xil_printf problem with Microblaze and ML505

Jump to solution
arr1 is not initialized, so you are writing to invalid locations. Instead of defining it as *arr1, use arr1[40]
Highlighted
Observer jishnukd
Observer
11,615 Views
Registered: ‎06-16-2009

Re: Array and xil_printf problem with Microblaze and ML505

Jump to solution
I tried to use expressions like *(arr1+i) and arr1[i] both interchangeably and consistently. But, the output was the same as before.
Tags (4)
0 Kudos
Historian
Historian
11,603 Views
Registered: ‎02-25-2008

Re: Array and xil_printf problem with Microblaze and ML505

Jump to solution

jishnukd wrote:
I tried to use expressions like *(arr1+i) and arr1[i] both interchangeably and consistently. But, the output was the same as before.

You miss vsiva's point.

 

When you declare the variable as 

 

    Xuint32 *arr1;

 

you are not reserving any space for anything. All you've declared is a pointer to an unsigned integer. But that pointer isn't pointing to anything.

 

So when you do your for loop, and you access arr1[i], you are accessing garbage because  you never initialized arr1.

 

The suggestion to declare that array variable as arr1[40] is one you should heed.

 

-a

 

----------------------------Yes, I do this for a living.
Participant wasiqnaeem
Participant
11,601 Views
Registered: ‎06-11-2009

Re: Array and xil_printf problem with Microblaze and ML505

Jump to solution

 

exactly do as suggested in the previous post...else check that uart settings match with the  hyperterminal connection settings, dat also sometimes causes the problem of no output.

0 Kudos
Historian
Historian
11,599 Views
Registered: ‎02-25-2008

Re: Array and xil_printf problem with Microblaze and ML505

Jump to solution

wasiqnaeem wrote:

 

else check that uart settings match with the  hyperterminal connection settings, dat also sometimes causes the problem of no output.


That may be true but that's not his problem.

 

-a

----------------------------Yes, I do this for a living.
0 Kudos
Observer jishnukd
Observer
11,570 Views
Registered: ‎06-16-2009

Re: Array and xil_printf problem with Microblaze and ML505

Jump to solution

Yes, I missed vsiva's point. So, I'll try to use malloc for initialization so that the pointer doesn't point to garbage.

 

Thanks! I'll get back to you all asap.

0 Kudos
Observer jishnukd
Observer
11,567 Views
Registered: ‎06-16-2009

Re: Array and xil_printf problem with Microblaze and ML505

Jump to solution
Or I'll use arr1[40] (as an array) throughout.. Then I think I would't have to initialize it.
0 Kudos
Historian
Historian
11,553 Views
Registered: ‎02-25-2008

Re: Array and xil_printf problem with Microblaze and ML505

Jump to solution

jishnukd wrote:
Or I'll use arr1[40] (as an array) throughout.. Then I think I would't have to initialize it.

This is the better solution. In general, in an embedded system with limited memory, you really want to avoid dynamic allocation (malloc and its friends). If you use static allocations (arr1[40]), the toolchain knows how much memory is required and after compiling and linking, they will tell you if your program will fit in your memory!

 

-a

----------------------------Yes, I do this for a living.
Observer jishnukd
Observer
11,540 Views
Registered: ‎06-16-2009

Re: Array and xil_printf problem with Microblaze and ML505

Jump to solution
Ok. I got it. Thanks! :)
0 Kudos
2,604 Views
Registered: ‎09-29-2011

xil_printf float

Jump to solution

Hello,

How can i send a float to UART if I mapped the xil_printf function to RS 232 IP?(Note:sprintf has a too large memory footprint ).

Thank you!

0 Kudos
Moderator
Moderator
2,593 Views
Registered: ‎11-10-2010

Re: xil_printf float

Jump to solution
This is an entirely different question and should be in its own thread. Locked.
0 Kudos