• 0
sgandhi

FAT32 with Zybo Z7

Question

Hello,

I have been working on reading a .txt file from the micro sd card on the Zybo Z7 board from the PS side. The version of Vivado I use is 2018.1 and the sd card belongs to Kingston (8 GB). I have created a block design in Vivado that just contains the Zynq PS block. I have attached the file below for the reference.  In the customization, I select SD0 (40-45 pin) and the pin 47. I also select UART. Reset of the parameters are left unchanged. 

After exporting the design to the sdk, I create hello world project and modify the main.c with the code for the sd card. I have attached the main.c below for the reference.

I also enabled the xilffs in the BSP for Generic fat32 file system.

However, when I run the code it seems that f_mount works correctly. But, the f_open, f_read and f_close give errors as following:

Connected to COM6 at 115200
Starting the read from SD card...
Mounting done successfully : 0
Opening Failure : 3
Reading Failure : 9
1118696
Closing Failure : 9

The mounting operation returns the value 0 means FR_OK is 0 (succeeded). Whereas, f_open returns (3) i.e. FR_NOT_READY and f_read and f_close returns (9) means FR_INVALID_OBJECT. 

It does appear that the f_open failure causes the read and close functions to fail.!

Also, I am storing the read data in a buffer which prints some garbage value I suppose!

As a starting step, I have a test1.txt in the SD card which has 1 byte data : 5. That's all...

Can anyone help me with this?

 

Regards,

Shyama.

zynq_blockdesign.png

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Hi @sgandhi,

Looking at you main.c did you tried using 1 instead of 0 in the f_mount function

like this:   f_mount(&fatfs, Path, 1);

best regards,

Jon

Share this post


Link to post
Share on other sites
  • 0
43 minutes ago, jpeyron said:

Hi @sgandhi,

Looking at you main.c did you tried using 1 instead of 0 in the f_mount function

like this:   f_mount(&fatfs, Path, 1);

best regards,

Jon

Yes I did try but it doesn't work.!

Share this post


Link to post
Share on other sites
  • 0

@sgandhi,

Have you tried attaching some form of ILA or scope to the SD CMD wire and seeing what's taking place there?  Every part of the interaction should be visible by just snooping that wire and its associated clock wire.

Dan

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
9 hours ago, D@n said:

@sgandhi,

Have you tried attaching some form of ILA or scope to the SD CMD wire and seeing what's taking place there?  Every part of the interaction should be visible by just snooping that wire and its associated clock wire.

Dan

Hello @jpeyronand  @D@n,

I figured out that there was a problem in the block design parameter for MIO configuration. The voltage needed is 1.8V and not 3.3V. Presence of level shifter is suppose to take care of 3.3V from 1.8V. Also, I made a mistake is enabling the pull up for pin 47 (card detect). The pull up was to be disabled.

I was having a 2D array in the text file and now the processor is able to access this data. However, now I want that PS reads the data from the SD card and stores it in the DDR memory. I think I am half the way and need to figure out how to put this data starting from a specific location of DDR from 0x100000 to 0x3FF00000. 

There is direct interface from the Zynq PS IP to the DDR however some customization needs to be done in the block design for DDR parameters! What parameters are to be taken care of ? What exactly do I add to SDK code so PS stores the data to DDR? Do I only need to write the 2D buffer data specifying an address of DDR or some sort of initialization is to be done?

 

Regards,

Shyama.

Edited by sgandhi
error solved!

Share this post


Link to post
Share on other sites
  • 0

Hello @D@n, @jpeyron,

 

I am able to read the 2D array from the file but there is a problem!

Let's say the content in the .txt file is:

0 \tab 0 \tab 0 \tab 0

0 \tab 1 \tab 0 \tab 0

....

and so on...... (may be a million rows based on my input data file). [\tab is tabular space provided]

 

However, when I read this file, I receive the ASCII characters in the SDK terminal window! 

So, I get the output as :

48 9 48 9 48 9 48 13 10

48 9 49 9 48 9 48 13 10

.....

so on......

It takes 0 as 48 (ASCII), 1 as 49 and tab as 9. It also adds 13 and 10 as carriage return and line feed ... So while reading the file as 2D array I have to declare array using number of rows present but columns as 9!!! 

Now let's say if the number at some place in the file is "13" so I get the output printed as 49 51 (ASCII values of 1 and 3!!!!). So, in this case the second dimension of the array as 9 is not sufficient!! 

I have such a text file to be read from the SD card with approx a million rows and 4 columns. Every entry is a number starting from 0 and maximum possibility of 33000. 

How do I deal with this problem?

Share this post


Link to post
Share on other sites
  • 0

@sgandhi,

Welcome to data processing.  The sad reality is that text files aren't good for this kind of thing.  It's not an FPGA particular thing, but rather a basic reality.  1) Text files tend to take up too much space, and 2) they require processing to get the data into a format usable by an algorithm.

One way to solve this problem, which I've done in the past with great success, is to rearrange the file so that's it's a binary file containing a large homogeneous area of elements all of the same type.  In my case, I wanted a file that could be easily ingested (or produced) by MATLAB.  I chose a binary format that had a header, followed by an NxM dimensional matrix of all single-precision floats.  (You can choose whatever base type you want, but single-precision floats were useful for my application.)  The header started with three fields: 1) First, there was a short marker to declare that this was the file type.  I used 4-capital text letters for this marker.  That was then followed by the 2) number of columns in the table, and then 3) the offset to the start of the table.  This allowed me to place information about the data in further header fields, while still allowing the processor to skip directly from the beginning header to the data in question.  Further, because the data was all of the same type, I could just about copy it directly into memory without doing any transformations, and to then operate on it there.

It did help that the data was produced on a system with the same endianness as the system it was read from ...

Dan

 

Share this post


Link to post
Share on other sites
  • 0
On 8/9/2019 at 5:56 AM, D@n said:

@sgandhi,

Welcome to data processing.  The sad reality is that text files aren't good for this kind of thing.  It's not an FPGA particular thing, but rather a basic reality.  1) Text files tend to take up too much space, and 2) they require processing to get the data into a format usable by an algorithm.

One way to solve this problem, which I've done in the past with great success, is to rearrange the file so that's it's a binary file containing a large homogeneous area of elements all of the same type.  In my case, I wanted a file that could be easily ingested (or produced) by MATLAB.  I chose a binary format that had a header, followed by an NxM dimensional matrix of all single-precision floats.  (You can choose whatever base type you want, but single-precision floats were useful for my application.)  The header started with three fields: 1) First, there was a short marker to declare that this was the file type.  I used 4-capital text letters for this marker.  That was then followed by the 2) number of columns in the table, and then 3) the offset to the start of the table.  This allowed me to place information about the data in further header fields, while still allowing the processor to skip directly from the beginning header to the data in question.  Further, because the data was all of the same type, I could just about copy it directly into memory without doing any transformations, and to then operate on it there.

It did help that the data was produced on a system with the same endianness as the system it was read from ...

Dan

 

Hello @D@n, @jpeyron,

It worked. I got a .bin file from the MATLAB and then used Xilinx SDK to read a .bin file using 32 bit unsigned format.

I am having a 2D array with 1 million rows and 4 columns. With each element represented as 32-bit unsigned number, the total size becomes ~15 MB. However, the maximum value in the array is 313,193 which can be represented with 19 bits only. However, I wish to work with multiple of 8-bits i.e., using 20 bits to represent each elements will give me 20 x 4 = 80 bits for each row instead of 19 x 4 = 76 (which is not a multiple of 8!).

When I tried to generate a .bin file with each element of the array represented as 20 bits in MATLAB, the file is created successfully. For one million rows and each row of 80 bits, the total file size turns out to be 10,000,020 bytes (~9.53 MB). 

However, now having this file in the SD flash card, I want to change my code so that I have a  2D array declared as uint20, something like this! Now, this comes in the class of arbitrary precision data types and not the standard data types!

My question is does SDK support arbitrary data types? If yes, which header file contains the definition? and how do I use them? (I am aware that HLS supports the arbitrary data types but not aware about the SDK).

 

Thanks,

Shyama.

Share this post


Link to post
Share on other sites
  • 0
19 minutes ago, jpeyron said:

Hi @sgandhi,

I'm only aware of using HLS for arbitrary data types.  You can use the HLS IP in SDK as described in this  xilinx forum thread

best regards,

Jon

Hello @jpeyron,

Don't you think for just an arbitrary data type for a 2D array in SDK, it would be a hectic task to start from HLS? 

It seems to me that there has to be some way to deal with it in SDK.

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