Jump to content
  • 0

How to read from SD card on ZYBO


shahbaz

Question

Hi, 

I want to read a .txt file from a SD card and load it into a register vector. is this possible? because I've read somewhere that file handling can only be done at simulation time to load values/inputs from files.

basically I want to display a 16-bit colored image on LCD using VGA on ZYBO. I've extracted the R, G, B values from each pixel using MATLAB and now I want to assign them to respective r, g, b vector of each pixel which can only be done using file handling, since MATLAB exports these values to .txt file   

Link to comment
Share on other sites

13 answers to this question

Recommended Posts

Hi shahbaz,

If you are Ok using micro SD card adapter embedded in Zybo I would recommend to use it with the driver xsdps provided by Xilinx. Please note that it is connected and intended for use by PS not PL. The driver is located in Vivado library \embeddedsw\XilinxProcessorIPLib\drivers\sdps

In Vivado the only thing is needed is enabling SD card in the processing system. Everything else is done in SDK. There you will need to add library xilffs to the BSP. File system and functions are described in here

Good luck!

 

Link to comment
Share on other sites

hi @jpeyron,

I followed the guide at GitHub under Readme in PMODSD. can you please guide me step wise on how to start from block design and than going to SDK and running the demo. I have added the pmodsd and zynq PS IPs, after auto connection and running the generate bitstream I get following error.

I need your guidance at this image.thumb.png.b7e9c0e3ffd8cb92792484afb1cfcf3e.png

Link to comment
Share on other sites

Hi @shahbaz,

@Notarobot is correct. I forgot the Zynq processor has the xilffs library for the SD card and that the SDcard is directly connected to the PS. You should not use the Pmod SD IP Core.  I have attached some screen shots that should help with getting your project going. I used the Zybo board files. Here is a tutorial on how to install the board files if have not done so already.

thank you,

Jon

 

Zybo_sd_1.jpg

Zybo_sd_2.jpg

Zybo_sd_3.jpg

Link to comment
Share on other sites

Hi @Notarobot, @jpeyron

Thank you for your concern.

After enabling SD_0 in PS in Vivado and creating a BSP in SDK for SD Application, I added all the files from src folder of diver sdps_v1_00_a to the src folder of User App in .sdk. if I debug the project I get following error. 

Secondly are these files in src folder just for configuration? Do I have to add another .c source to put read write commands for sd_card?

 

 

image.thumb.png.d5ad6a74c55201cddb35a9337f22b360.png

Link to comment
Share on other sites

shahbaz,

Typically src folder contains C-code written by the person who design the project. It should contain the main function.

You can try attached Xilinx test code. It's rudimentary but you can change it to your needs.

Also you don't need to copy Xilinx files into src folder, they will be added to your project from the BSP.

 

TestSD.c

Link to comment
Share on other sites

Hi @Notarobot,

I want to read data from a .txt file on SD card which are basically pixel values of rgb image. I observed that I cannot just copy that text file in SD card and read it. So, I first created a .bin file using f_open command, once created, I than converted the contents of my text file into binary and copied them into the .bin file created by the command. but now if I plug back the SD card and try to read the same file, it fails at f_open function.

 

Commands for creating file are commented out in the attached screenshot

 image.thumb.png.6770936869d3c9b4f59389265ee46352.png

 

 

 

Link to comment
Share on other sites

hi @Notarobot,

i'm sorry if I didn't make sense. 

The problem that I was facing was that the contents of text file (generated by MATLAB) that I was trying to read from SD card had numeric data. whenever I read the data from SD card It got converted into ASCII in read buffer, whereas I wanted decimal values in the buffer so that I can store them into memory. but if I somehow converted my textfile contents into Unicode (the format that xil_write generates in output file), PS would read them perfectly as decimal numbers. I was unable to convert my file contents into that format since data were separated by commas and the data was very big.

I found the solution to my problem, I simply have MATLAB to convert the decimal number in array to Unicode and then output them to a txt file without including commas b/w values. using following command lines

X_uni=native2unicode(X_deci);

dlmwrite('r.txt',X_uni,'delimiter','');

 

Thank you for your concern.

Link to comment
Share on other sites

Hi  @shahbaz @Notarobot @jpeyron

I was trying to do the same thing by using the test code TestSD.c but I was getting the following error,

I don't understand why it is giving error in the f_mkfs function. I have given the path name correctly.

If I comment the f_mkfs function, I get error in f_open function just like @shahbaz mentioned, but the solution to the same wasn't mentioned here. I just wrote .txt file onto the sd card and tried to read it but it didn't work. Secondly if I try to run both read write and open on the formatted FAT32 SD card still it shows the same error. Please help me with this

 

 

sserror.PNG

Link to comment
Share on other sites

Hi @tanvi127

1. In the example app TesSD.c the block containing f_mkfs function was commented because it never worked on Zybo board. It appears that you've changed that code.

2. Looking at your screenshot I've noticed red dot in "Problems" Tab indicating that you have code errors. This can't be f_mkfs failure. I would recommend cleaning this error.

Please note that for best results SD cards should be formatted with the application distributed for free by SD Association.

Good luck!

Link to comment
Share on other sites

On 11/20/2019 at 9:08 AM, tanvi127 said:

Hi,

 

So the example code worked in a previous version of Vivado (2014.4) and not in 2016.2, I'm not sure why that happened or if it affects the way the sd card is read in any way....

1. Since it is such a simple code, most likely the issue is not with Vivado version but with your project. The best way would be recreating the project in the new version from scratch.

2. When you get positive outcome from someone's post, please, indicate that this is a solution. It would allow others to learn, plus would encourage more help.

Thanks!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...