EmbDev.net

Forum: FPGA, VHDL & Verilog How To Read A SD Card


von Adrian H. (adrian3)


Rate this post
useful
not useful
Could anyone help me with how to read a SD card.

My development board can be seen here: 
https://dropwow.com/product/1238976
except my FPGA chip is a EP4CE10F17C8N

I would like to read hex data from the SD card (Example: 03 09 0C).

I can program the FPGA (in Verilog) to output to a VGA monitor (800x600 
resolution) a 16 colour VGA image which is stored in a .txt file 
(something like 80x100 pixels). However, if I try to "Compile Design" in 
verilog a full screen image (800x600) this takes such a long time.

Therefore, I would like to store a background image (800x600 pixels) on 
a SD card and get the FPGA to read the SD card and output the RGB values 
to a VGA monitor (the format of the background file will be that the 
value of each pixel in the file will be a pointer to a colour palette).

If anyone could help me with reading a SD card, that would be brilliant.

von Adrian H. (adrian3)


Rate this post
useful
not useful
If this helps, I am using the following code to load my data file;

     output reg [4:0] red;
     output reg [5:0] green;
     output reg [4:0] blue;

     reg [15:0] my_memory [0:7371]; //16 bits wide: 76 x 97 pixels = 
7372
     initial $readmemh("Data.txt", my_memory);
     integer j;

Integer j is used later to retrieve the data from RAM to output the 
colour palette to a VGA monitor;

     if(my_memory[j] == 7)
  begin
       red <= 5'b10100;
       green <= 6'b110000;
       blue <= 5'b11000;
        end

von Duke Scarring (Guest)


Rate this post
useful
not useful
Adrian H. wrote:
> readmemh
readmemh works only for simulation and sometimes for the initialisation 
of RAM content (depends on the vendor/tool combination).

To access a SD-card you need an SPI master and a state machine (or CPU) 
which handle the SD-card protocol.

Duke

von Adrian H. (adrian3)


Rate this post
useful
not useful
Using readmemh works fine when I program the FPGA development board 
using Quartus Prime Lite Edition version 18.1.

Could you be a bit more specific regarding why readnenh works only for 
simulation and sometimes for the initialisation of RAM content (depends 
on the vendor/tool combination).

The SPI master and a state machine (or CPU) method to read a SD card 
appears to be to advanced for me. However, if anyone has any code I 
would like to give it a go.

I have also come across another way to load a text file or an image file 
into a FPGA. This is to initialize it as the initial values of the block 
memory:
use Mega-Function in the MegaWizard Plug-In Manager in Quartus II to 
initialize a block memory with the text file or image-converted binary 
text file in the MIF format. Does anyone have any thoughts on this 
method and if this way would take less time to "Compile Design".

von Duke Scarring (Guest)


Rate this post
useful
not useful
Adrian H. wrote:
> Using readmemh works fine when I program the FPGA development board
> using Quartus Prime Lite Edition version 18.1.
You can program your FPGA with readmemh from hard disk? RLY?

Adrian H. wrote:
>   reg [15:0] my_memory [0:7371];
>   initial $readmemh("Data.txt", my_memory);
This is the initialisation of RAM (my_memory). If this work in Quartus 
than your tool support this way of initialisation and everything is 
fine.

Adrian H. wrote:
> I have also come across another way to load a text file or an image file
> into a FPGA. This is to initialize it as the initial values of the block
> memory:
> use Mega-Function in the MegaWizard Plug-In Manager in Quartus II to
> initialize a block memory with the text file or image-converted binary
> text file in the MIF format. Does anyone have any thoughts on this
> method and if this way would take less time to "Compile Design".
This is an alternativ tool dependend way to update your memory content.
I would not expect much faster compile times, but just give it a try.

Adrian H. wrote:
> If anyone could help me with reading a SD card, that would be brilliant.
At first just search how the microcontroller guys do SD-card access, to 
see how it works.

Duke

von Adrian H. (adrian3)


Rate this post
useful
not useful
Many thanks for your reply, it is very much appreciated.

In the documentation that came with my development board it states: From 
JTAG download SOF file to FPGA chip,or download jic file to SPI FLASH 
M25P64 or EPCS 64 save FPGA program.

Being a newbie to FPGA, could you please advise if i am understanding 
the following correctly;

1. From JTAG download SOF file to FPGA chip

I have the FPGA connected to my laptop via the JTAG / USB Blaster and i 
am programming the volatile memory (with a sof file) on the board using 
Quartus Prime. After a hard reset of the board the FPGA requires 
re-programming. What method do you call this (eg. simulation etc.)

Could you try to explain the other 2 methods to program the FPGA;

2. Download jic file to SPI FLASH M25P64
3. EPCS 64 save FPGA program

I think i understand item 1 above and have an understanding that the 
FPGA can also be programmed using POF files (for flash devices).

Am i getting confused with what i am trying to achieve: Programming the 
FPGA using a sof file which reads a raw data file from my laptops 
hardrive to produce 800x600 super VGA image takes a long time to compile 
the code for programming. Therefore, my approach was to store the raw 
data file on a SD card (accessible by the FPGA) to save compiling time 
prior to programming. Or, is a better approach to have all my code on a 
SD card and when the FPGA is powered up (with the SD card inserted) it 
boots / programs from the card (no laptop connected).

I am also thinking that the development board i have does not have 
documentation suitable for a beginner to FPGA. I know this is going off 
the subject, but do you have any suggestions on a particular board that 
has good documentation and preferably well documented on the internet 
(example code).

Sorry for the long reply.

von Adrian H. (adrian3)


Rate this post
useful
not useful
Ok, still struggling to even get started with this.

I have tried: 
https://infraledblog.wordpress.com/2016/02/17/nios-ii-writing-and-reading-files-from-sd-cards-part-1/

Can follow this until trying to add the SD Card Interface. This does not 
even show up, all I can see under Universal Program: Memory: is SRAM 
Controller and SSRAM Controller. A search also shows nothing.

Does anyone have any ideas (I have NIOS II 18.1 installed) or links to a 
website that may help.

Many thanks,

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.