cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Visitor
Visitor
4,971 Views
Registered: ‎04-16-2013

Error when running the rgb2gay Example

Dear all, 

 

Im traing to run the rgb2gay example:

 

1) I have create the edk proces with Simulink

2) I add the pcode created with Simulink and Sysgem to my EDK project.  

3) Affter generatting the Netlist, the Bitstream and export de Desing I have created the Sofrware using SDK

 

4) I have used the code that is shown in the example (System Generator for DSP User Guide" document, page 155 ):

5) I have programed the FPGA OK and run the code. 

 

6) In the serial port I get:

Hello World
-- Entering main() --
Hello World
-- Entering main() --
Hello World
-- Entering main() --
Hello World
-- Entering main() --
Hello World

 

The same 2 lines are repeated indefinitely


what is happening?? why the program does no pass the xc_create line??

If I add a prinf affter this line... nothing happens... the two lines remains (Hello World -- Entering main() --)

 

The other point is that I can not find the lines 

/* Definitions for peripheral SG_PLBIFACE_0 */
#define XPAR_SG_PLBIFACE_0_DEVICE_ID 0

 

in to the xparameters.h in order to fix the index of RGB2GRAY_PLBW_ConfigTable .... I have assumed that it is 0... 

 

Many thanks in advance for your help. 

BR

 

 

 

The code that I have used:

#include "xparameters.h"

#include "stdio.h"
#include "xutil.h"
// header file of System Generator Pcore
#include "rgb2gray_plbw.h"

 

RGB2GRAY_PLBW_Config RGB2GRAY_PLBW_ConfigTable[0];
int main (void) {
int i;
uint32_t gray, red, green, blue;
print("-- Entering main() --\n\r");
xc_iface_t *iface;
xc_from_reg_t *fromreg_gray;
xc_to_reg_t *toreg_red, *toreg_green, *toreg_blue;
// initialize the software driver
xc_create(&iface, &RGB2GRAY_PLBW_ConfigTable[0]);
// obtain the memory locations
xc_get_shmem(iface, "result", (void **) &fromreg_gray);
xc_get_shmem(iface, "red", (void **) &toreg_red);
xc_get_shmem(iface, "green", (void **) &toreg_green);
xc_get_shmem(iface, "blue", (void **) &toreg_blue);
for (i=15; i<30; i++){
red = i;
green = i + 10;
blue = i + 20;
// Write RGB value to peripheral
xc_write(iface, toreg_red->din, red); 
xc_write(iface, toreg_green->din, green); 
xc_write(iface, toreg_blue->din, blue); 
xil_printf("R = 0x%x, G = 0x%x, B = 0x%x -- ",
red, green, blue);
xc_read(iface, fromreg_gray->dout, &gray); 
xil_printf("Gray = %x \n\r", gray);

print("-- Exiting main() --\n\r");
return 0;
}

 

 

  

 

 

0 Kudos
Reply
6 Replies
Professor
Professor
4,970 Views
Registered: ‎08-14-2007

Since there is no "Hello World" in the C program you posted, I think the problem is

that you are not picking up the correct .elf file when you build the project.  If you created

your code starting from the Hello World example, it is possible that the project settings

are still pointing to the Hello World code and not the code you have changed.  Another

possibility is that your software was never actually built, for example there was a

linker error, etc. and the .elf file is stale.

-- Gabor
0 Kudos
Reply
Visitor
Visitor
4,963 Views
Registered: ‎04-16-2013

Thanks for you quickly reply... 

 

You are rigth about the Hello word... 

When I have copy the code i just removed... 

I am really sure that  I am running the right code ...

If I change the print string I see it in the serial port... 

 

The problem is nothing after the xc_create is executed.... 

I mean, if I add  print(" This line is after xc_create" )... I never see this in the serial port. 

 

There the code:

#include "xparameters.h"
#include "stdio.h"
#include "xutil.h"
// header file of System Generator Pcore
#include "rgb2gray_plbw.h"
RGB2GRAY_PLBW_Config RGB2GRAY_PLBW_ConfigTable[0];
//void print(char *str);

int main (void)
{
//init_platform();
int i;
print("Hello World\n\r");
uint32_t gray, red, green, blue;
print("-- Entering main() --\n\r");
xc_iface_t *iface;
xc_from_reg_t *fromreg_gray;
xc_to_reg_t *toreg_red, *toreg_green, *toreg_blue;
// initialize the software driver
xc_create(&iface, &RGB2GRAY_PLBW_ConfigTable[0]);

// obtain the memory locations
xc_get_shmem(iface, "result", (void **) &fromreg_gray);
xc_get_shmem(iface, "red", (void **) &toreg_red);
xc_get_shmem(iface, "green", (void **) &toreg_green);
xc_get_shmem(iface, "blue", (void **) &toreg_blue);
for (i=15; i<30; i++){
red = i;
green = i + 10;
blue = i + 20;
// Write RGB value to peripheral
xc_write(iface, toreg_red->din, red);
xc_write(iface, toreg_green->din, green);
xc_write(iface, toreg_blue->din, blue);
xil_printf("R = 0x%x, G = 0x%x, B = 0x%x -- ",
red, green, blue);
xc_read(iface, fromreg_gray->dout, &gray);
xil_printf("Gray = %x \n\r", gray);
}
print("-- Exiting main() --\n\r");
return 0;

 

cleanup_platform();

return 0;
}

 

 

 

0 Kudos
Reply
Professor
Professor
4,955 Views
Registered: ‎08-14-2007

This line looks suspicious:

 

RGB2GRAY_PLBW_Config RGB2GRAY_PLBW_ConfigTable[0];

It seems to be defining a zero-element array of type RGB2GRAY_PLBW_Config.  Later
you are using the address of its first element:

 

xc_create(&iface, &RGB2GRAY_PLBW_ConfigTable[0]);

So perhaps this is causing other things to get inadvertently overwritten?

-- Gabor
0 Kudos
Reply
Visitor
Visitor
4,948 Views
Registered: ‎04-16-2013

Hi,

 

RGB2GRAY_PLBW_Config is a structure, created directy by the EDK. 

 

The 0 is due to the ID devide... (as far as I understood in the System Generator for DSP document):

 

There can be multiple instances of a System Generator pcore in an XPS project. Each of the
instances is associated with a device ID, which can be found in “xparameter.h”. Assume
that the instance of interest has a device ID of 0 based on the following information in
“xparameter.h”.
/* Definitions for driver SG_PLBIFACE */
#define XPAR_SG_PLBIFACE_NUM_INSTANCES 1

 

 

I just copy the line xc_create(&iface, &RGB2GRAY_PLBW_ConfigTable[0]);

from the tutorial.... 

 

 

Thanks

 

 

 

 

 

typedef struct {
uint32_t version;
// Pointers to low-level functions
xc_status_t (*xc_create)(xc_iface_t **, void *);
xc_status_t (*xc_release)(xc_iface_t **);
xc_status_t (*xc_open)(xc_iface_t *);
xc_status_t (*xc_close)(xc_iface_t *);
xc_status_t (*xc_read)(xc_iface_t *, xc_r_addr_t, uint32_t *);
xc_status_t (*xc_write)(xc_iface_t *, xc_w_addr_t, const uint32_t);
xc_status_t (*xc_get_shmem)(xc_iface_t *, const char *, void **shmem);
// Optional parameters
// (empty)
// Memory map information
uint32_t result;
uint32_t result_n_bits;
uint32_t result_bin_pt;
// uint32_t result_attr;
uint32_t blue;
uint32_t blue_n_bits;
uint32_t blue_bin_pt;
// uint32_t blue_attr;
uint32_t green;
uint32_t green_n_bits;
uint32_t green_bin_pt;
// uint32_t green_attr;
uint32_t red;
uint32_t red_n_bits;
uint32_t red_bin_pt;
// uint32_t red_attr;
// XPS parameters
Xuint16 DeviceId;
uint32_t BaseAddr;
} RGB2GRAY_PLBW_Config;

 

 

 

 

0 Kudos
Reply
Professor
Professor
4,939 Views
Registered: ‎08-14-2007

The problem I see is that when you allocate memory for an array of structures, the number in

the square brackets is not an index into the array, but the size of the array.  A size of zero would

say you don't have any instances, and it's not clear what the pointer to the first element would

give you.  That's why it seems that the [0] in the first line I mentioned should be [1] if you have

one instance, or if you have a definition of the number of instances then you could use

that like [XPAR_SG_PLBIFACE_NUM_INSTANCES].  Then if you happened to add more

instances you'd allocate the memory for the appropriate number of structures.

 

 

-- Gabor
0 Kudos
Reply
Visitor
Visitor
4,931 Views
Registered: ‎04-16-2013

Many thanks for you help.

 

At the end, the problem was that I had to add the IP driver to the SDK environment

 

http://forums.xilinx.com/t5/Embedded-Development-Tools/Creating-MicroBlaze-Peripherals-in-System-Generator/td-p/169808

 

Problem solved!

 

0 Kudos
Reply