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: 
Highlighted
Visitor jplazarenas
Visitor
995 Views
Registered: ‎01-07-2019

Image send from PS to PL with AXI4-Stream Interface and DMA

Hi all,

First, this is my first post, I do not know if I have opened it in the right place, otherwise please tell me so I can change it. I am currently working with an image processing system. I have designed an IP in Vivado HLS with AXI4-Stream interface for it. The IP is connected to the Zynq processing system (PL: xc7z010clg400-1) through another IP AXI_DMA. Up to here everything seems to work.

The problem comes with the SDK programming. I have read how to configure and use data writing through direct access to memory. However, I need to use an image to test the operation of the entire system, and I am not able to read it from the PS.

From what I understand, I have several options to enter the image in the PS of the device: SD card, Uart, Ethernet. I have read that for most cases it is usually recommended to use Petalinux or another operating system to read the image. However, I think maybe there is a simpler way to do this. I want to read the image so that it can be sent easily through the DMA and received by the IP.

I have problems with how to load the image, with what interface to load it, how to read the pixels, how to organize them, and how to send them by the AXI_DMA. I hope have explained myself well, whichever question you have, please tell me. If necessary I can add the IP or the code in question. This is very important to me, many thanks for the help in advance.

 

A greeting.

0 Kudos
12 Replies
Voyager
Voyager
975 Views
Registered: ‎03-28-2016

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

@jplazarenas,

You might want to start with taking a look at the Video Intro series that is posted on the forums at:

https://forums.xilinx.com/t5/Video/Xilinx-Video-Series/td-p/849583

This will help get you started.  Of particular interest might be the HLS video IP examples and the VDMA examples.

As for loading an image into the PS-DDR, there are many optons of varying degrees of difficulty.  The simplest method is to save the image to a C file as an array.  Add the C file to your appliation software so that the array gets compiled into the executable.  From there it will get loaded into the PS-DDR memory when the executable gets loaded.  I use this method a lot for testing.  The down side is that you have to recompile in order to load a new image.

If you need to dynamically load an image, the Uart might be the easiset but slowest option.  Most terminal programs have the ability to stream a file over the Uart channel.  You would need to write your own software on the Zynq to receive the data and then store it in memory.  An SD card or using Ethernet can both be done with bare-metal or linux.  There are likely examples that you might be able to find and modify to fit your application.

Ted Booth - Tech. Lead FPGA Design Engineer
www.designlinxhs.com
Visitor jplazarenas
Visitor
966 Views
Registered: ‎01-07-2019

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

Hi @tedbooth,

Thank you for your quick reply, and for the tutorials, I have taken a look and they are very complete.

Yes, as you comment, I know the ways you have proposed to introduce the image in the PS. The problem I have is that, in all these options, I do not know how to interpret the image data and then send it through the DMA to be compatible with the AXI of my IP.

For example, if I choose the mode of sending through UART, I do not know what to do with the bytes I receive, how to save them so that they correspond to pixels and how to tell the DMA that I am sending pixels of a certain image.

The truth is that in my case with a limited number of tests I would be worth, so the method you mention of putting the compiled image could interest me. The bad thing in this case, is that I do not know how to enter the image in the program prior to compilation. I suppose that in some way I will have to transform it and turn it into a variable (I've seen in the tutorials the type of .ppm file, I do not know if that would be worth it in my case). Once you manage to compile it as a variable, I must send it with the appropriate format with the functions of the IP of AXI_DMA, which I would not know how to do either.

Maybe you could share with me a link or some example where some of these things are done in order to modify it in my own application. I've been searching for days and have not seen any tutorials or code where they do this directly.

Regards.

0 Kudos
Scholar vanmierlo
Scholar
939 Views
Registered: ‎06-10-2008

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

In what format do you intend to accept the image? Will the PL be able to interpret that format? If not who will have to make the transformation?

0 Kudos
Voyager
Voyager
932 Views
Registered: ‎03-28-2016

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

I would recommend using the same formatting that Xilinx uses for their IP.  Check out UG934 for more details on that:

https://www.xilinx.com/support/documentation/ip_documentation/axi_videoip/v1_0/ug934_axi_videoIP.pdf

Ultimately, you can define what ever format you want for your custom IP.  The first thing is to figure out how the pixels will be packed.  Most of the time some amount of padding is used to put the data on convenient boundaries.  For example if you are using 12-bit Mono data, the pixel is padded out to 16-bits by adding "0"s to the front.  If you are using 8-bit RGB data, then it is common to concatenate them all together and then pad the data to a 32-bit value.  Data format is discussed in UG934.

If you want to include an image in a C program, just store the image in a C file as an array.  Here is an example for pixels that are stored as 16-bit values.

 

my_image.c:

short my_image[480][640] = {....};

 

In your main.c, declare the array as an external array so that it will get linked in correctly.

main.c:

...

extern short my_image[480][640];

...

Ted Booth - Tech. Lead FPGA Design Engineer
www.designlinxhs.com
Visitor jplazarenas
Visitor
899 Views
Registered: ‎01-07-2019

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

Hi @tedbooth ,

Thank you very much again for answering. I have been looking at the different formats of the Xilinx guide. My image is a 32-bit RGB, should I read the array of 4 in 4 bytes and write that in the DMA? Or could I send the full iamgen by DMA and the axi interface do the rest?

The question that comes to me at this point is do I have to package the data in some special way when sending them through the DMA ? Once I have the image in a variable, if it is stored correctly, it should be worth sending the variable by direct access to memory, right?

The next topic is how to convert the image into a variable that can be defined within the keys {...}, so that when you send it by the DMA the axi understands it and there are no problems with the file headers or something similar.

Hi @vanmierlo,

Thanks for the reply. Regarding your question, the format of the image in principle is .bmp, or .jpg. I think that in principle it should not matter, because the IP uses HLS functions of OpenCV and is prepared to work with different types of data, the problem is to get the image to reach the IP and PL and PS are understood. So as such there is no one who makes a transformation.

0 Kudos
Voyager
Voyager
891 Views
Registered: ‎03-28-2016

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

@jplazarenas,

You should package the data in the format that your IP will expect to see.  If you have RGB data, the typical Xilinx fomat places the G at the lowest portion of the word followed by the B followed by the R at the highest portion of the word.  Pad any remaining bits with "0"s to make the size of word that you plan to use.  The Video DMA doesn't require any special formating as long as you configure it properly.  Make sure that the "Stream Data Width" matches the size of the pixel data that you plan to use.  In your case it sounds like you want to use a 32-bit word.  From there, it is helpful to place the image in memory such that it starts on a 32-bit address boundary.  That just makes it easier for the VDMA to read in the image.

As for how to format the RGB componet values into one value, you simply concatenate them together.  For an RGB pixel with 8-bit components you would do the following:

pixel = (R<<16) + (B<<8) + G;

Ted Booth - Tech. Lead FPGA Design Engineer
www.designlinxhs.com
0 Kudos
Scholar vanmierlo
Scholar
792 Views
Registered: ‎06-10-2008

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

Hello @jplazarenas,

Decompressing a JPG is pretty difficult for the PL as it requires a rather large buffer. And then there are the many options for encoding and filtering the pixels. So I totally recommend against transferring the JPG to the PL AS-IS. You will have to decode it either at compile time or in the PS at run time and transform it into a format suitable for the PL.

Also BMP when compressed (RLE) is better handled in the PS, but the PL might be able to handle it. Again there are several encoding options in the format so it probably is easiest to transform it before sending it to the PL.

Maarten

0 Kudos
Visitor jplazarenas
Visitor
777 Views
Registered: ‎01-07-2019

Re: Image send from PS to PL with AXI4-Stream Interface and DMA


Hi @tedbooth @vanmierlo ,

Thank you again for the replies and contributions.

Once I have managed to overcome the problem with the image, I have new problems with the execution of the entire program. Let's see if you can lend me a hand and I'll finish the whole problem.

I have designed a help code to convert and interpret the data information of a .bmp file. For this I used the OpenCV libraries. I have read the color information of each pixel, and I have stored them in a 32-bit variable. After that, I generate the array that will later be the image in the SDK C code.

I = imread("2_tb_final_0.bmp", IMREAD_COLOR); 
int pixel = 0;
int p0 = 0;
int p1 = 0;
int p2 = 0;

for (int j = 0; j < I.rows; j++)
{
   for (int i = 0; i < I.cols; i++)
   {
      unsigned char* p = I.ptr(j, i); // Y first, X after
     pixel = (p[2] << 16) + (p[0] << 8) + p[1];
     p0 = p[0];
     p1 = p[1];
    p2 = p[2];
    cout << pixel << ",";
   }
}

After that, in Vivado I made a block diagram with only one HLS IP. This uses the HLS functions of OpenCV to transform a grayscale image and apply a quantification with a certain limit (attached code). With this I make a block diagram with the AXI_DMA (capture its configuration and the diagram)
I've looked at several tutorials on this topic, and I think I'm doing it right. My only question is whether the clock can be modified from within the zynq from 50 to 100 MHz or if this can cause a problem with the DMA.

After passing this stage and validating the design, I generate the bitstream and pass it to SDK. Here, I run another small program for the theme of image writing from the DMA to the IP. Again, I've looked at quite a few tutorials and I think I'm doing fine. I have doubts with the buffers of sending and receiving information between IP and DMA. In many places they use it but I do not know if in my case it is totally necessary, and if it is, I do not know exactly how to use it to send the image.

Finally, I compile the program, program the FPGA and everything seems to be going well. When trying to debug, both with the System Debugger and with the GDB, it does not let me carry it out. I can not run the program from the main, I sometimes get the Disassembly screen (when I use System Debugger), or the file asm_vector.S (when I do it with GDB). I have looked at configuration options and possible errors, but I have not found anything useful for now. I have tried different versions of SDK and neither. I do not know if the failure is a matter of configuration of the SDK, or if it is a matter of the program, memory, of the block of diagrams ... Here is my unsolvable problem, to see if you can help me ...

Thank you very much again for the help!

asm_vectorS.PNG
axi_dma.PNG
diagrama_bloques.PNG
zynq_HP0.PNG
0 Kudos
Voyager
Voyager
738 Views
Registered: ‎03-28-2016

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

@jplazarenas,

I'm not sure why you would be having issues running your executable on the PS.  You might try creating a new "Hello World" application and just see if you can get that to run with your bit stream.  Another option is to remove the BSP and rebuild it.  Then run "Clean Project" to rebuild the executable.

I'm not sure why you are using the AXI DMA for your design.  The Video DMA would seem like a better choice.  Check out the Video Series for help with the VDMA (#24 -26).  Example 3 in #26 is very similar to what you are doing.

Ted Booth - Tech. Lead FPGA Design Engineer
www.designlinxhs.com
0 Kudos
Moderator
Moderator
697 Views
Registered: ‎11-09-2015

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

Hi @jplazarenas 

Do you have any update on this? Were @tedbooth and @vanmierlo replies helpful?

If your question is answered or your issue is solved, please kindly mark the response which helped as solution (click on "Accept as solution" button below the reply)

If this is not solved/answered, please reply in the topic giving more information on your current status.

Thanks and Regards,


Florent
Product Application Engineer - Xilinx Technical Support EMEA
**~ Don't forget to reply, give kudos, and accept as solution.~**
0 Kudos
Visitor jplazarenas
Visitor
650 Views
Registered: ‎01-07-2019

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

Hello @florentw @tedbooth @vanmierlo ,

In the first place, I feel the delay in answering, I have not been available the last weeks.

@florentw  I understand how the forum works, but I still had not chosen an option as a solution because my problem remains unresolved.

Currently, I've managed to debug the code, but again, I'm still stuck in the XAxiDma_Busy () function.

As I have not been able to advance, I have made a simplified IP in which only one variable enters through the AXI Stream interface, it is converted to image, and it is converted to AXI Stream to exit the function. When doing the block design and opening SDK, again I have problems with the function named. The image seems to be sent correctly to the IP, however, when I try to transfer the data back from the IP to the PS, the function remains infinitely on hold. As much as I read in the forums, I don't know what may be failing in my code.

I enclose the code of HLS, and SDK (the configuration of the IP of the DMA is similar to the one shown above) Please tell me if you see any conceptual or code failure, since in no way I manage to operate the system.

Thank you very much for the help and attention.

A greeting!

0 Kudos
Moderator
Moderator
455 Views
Registered: ‎11-09-2015

Re: Image send from PS to PL with AXI4-Stream Interface and DMA

Hi @jplazarenas 

I think you should add an ILA on the AXI4-Stream interfaces. This might help you to understand if your IP is waiting for data or if the downstream IP is waiting for data and you IP is not providing it.


Florent
Product Application Engineer - Xilinx Technical Support EMEA
**~ Don't forget to reply, give kudos, and accept as solution.~**
0 Kudos