Jump to content
  • 0

Read from MicroSD in HDL, Write on PC


dcc

Question

I am using a Nexys 4 DDR board and want to use the microSD as an external memory to read from. right now:

  • I am using HDL only
  • Want to read from SD in SPI mode as a continues loop
  • Want to write to Micro SD offline via PC

I have an HDL code, and I am able to write to and then read-back  from the SD inside the HDL correctly, but have no idea how a data file on my computer can be turned into something on SD that  I can read properly in FPGA

Questions:

  • What file format am I supposed to use for the  SD card? (FAT32? )
  • What tool to use? I am using HxD  http://mh-nexus.de/en/hxd/
  • I wrote a random file to the SD using the HxD, when I initiate read in FPGA, I see data, but don't know what it is! Maybe I only need to figure the address for beginning of my data???

Thanks in advance.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

Hi @dcc,

I'm not certain how you are verifying that the HDL is writing to and then reading back from the SD card in a normal formatting style, but in general FAT32 is a widely used format for SD cards that has existing material for it.

I am uncertain why you are using a special tool to write to the SD card though; from what I can tell the tool is Windows compatible, so why not just use the Notepad program which comes with Windows and save a .txt file with the data you are interested in reading to the SD card or just using Windows Explorer (the file manager) to move the file of interest onto the SD card? If you do have a header in your file, you will need to take account for that, though I do not know what you mean by "random file" in this case.

Thanks,
JColvin

Link to comment
Share on other sites

Hi @JColvin,

 

Thanks for the response ... 

I managed to figure it out eventually ... It's an HDL only project. Using Chipscope I was seeing that I could write different data (up/down count, etc) starting from address 0 and read that back correctly, but every time I opened the same SD on PC it wanted to format it. I was messing with the file system (which I don't need actually).

HxD allows you to "opendisk" regardless of the file system, and also raw disk edit ... I found it on an MIT course. It's does the job.

best,

DCC

image.thumb.png.bbed52eb22960f6ad0fc5e5014df9ada.png

 

 

Link to comment
Share on other sites

@dcc,

This is really the backwards way to get something like this going.  You should be proving your design in simulation before jumping into a design on hardware.

Let me offer you an alternative.

  1. Here is a Verilog driver for talking to an SD card using SPI.  If you have already chosen to use the AXI bus, you can find an AXI-lite to WB bridge here that will allow you to talk to this core.
  2. Even if you already have a driver you like, this documentation for this one describes how to set up the SD card to where you can talk to it, and provides examples of how to read and write sectors.
  3. Even better, there's a piece of C++ code which can be used as a simulator with Verilator.  (Not sure if this would work with MicroBlaze or not.)  You can then use Linux tools, such as mkfatfs and such, to create a file with a FAT format that you can use as a "simulated" SD card.  When the simulation isn't running, you can mount the card on your system and check out/modify the files, and so know that things will work (based upon your experience with simulation) once you finally switch to hardware.  Indeed, if you are willing to accept the risks, you could even interact with your SD card from the simulation environment itself.
  4. If you want an example of a set up that would control the SD card interface from a ZipCPU, you can check out the ZBasic repository which has such a simulation integrated into it.  Indeed, there's even an sdtest.c program that can be used for that purpose.
  5. As for reading and comprehending the FAT filesystem, there's a FATFS repository that is supposedly good for use with embedded software.  I haven't tried it, so I can't comment upon it that much.
  6. Alternatively, if you can control how the file system is laid out, you should be able to place a file of (nearly) arbitrary length a couple of sectors into the FS, and force the file to be use contiguous sectors.  If you do that, then you've dealt with the most complicated parts about reading from the SD card.

Just my two cents, and some thoughts and ideas along the way.

Dan

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...