• 0
shahbaz

How to read from SD card on ZYBO

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   

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

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!

 

Share this post


Link to post
Share on other sites
  • 0

Hi @shahbaz,

I do not see any reason why you can not read a file from a SD card. We have the pmod SD IP core here that will work with the SD card on the ZYBO that should be a good starting point for your project. 

thank you,

Jon

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites
  • 0

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

Edited by shahbaz

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites
  • 0

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

 

 

 

Edited by shahbaz
change of queury

Share this post


Link to post
Share on other sites
  • 0

Hi shahbaz,

I can't help you because information you provided is very sketchy.

Did the example work for you? Did you follow the file operations sequence of the TestSD example?

I suggest to spend some time learning how to work with the FAT file system. It is very simple.

 

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now