Quantcast
Channel: XESS
Viewing all articles
Browse latest Browse all 14

Accessing the XuLA2 MicroSD Card

$
0
0

When the XuLA2 was released, I still didn't have an easy-to-use controller module to interface the FPGA with the SD Flash card. But now I do and you can get it here.

Here's a block diagram that shows the various control signals and datapaths for the SD card controller module.

FPGA-Based SD Card Controller Block Diagram

After looking at the diagram, maybe you're thinking that "easy-to-use" isn't the best adjective to apply to this module. But it's really pretty simple:

Set-up:

First of all, you have to give the controller a clock signal on the clk_i input with a higher frequency than the serial clock sent to the SD card through the sclk_o output. You can set generic parameters for the controller to tell it the master clock frequency (100 MHz), the SCLK frequency for initialization (400 KHz), the SCLK frequency for normal operation (25 MHz), the size of data sectors in the Flash memory (512 bytes), and the type of card (either SD or SDHC). I typically use a 100 MHz clock if I'm running an SD card with a 25 Mbps serial data stream.

Initialize it:

Pulsing the reset_i input high and then bringing it low again will make the controller initialize the SD card so it will work in SPI mode. Basically, it sends the card the commands CMD0, CMD8, and then ACMD41 (which is CMD55 followed by CMD41). The busy_o output will be high during the initialization and will go low once it is done.

After the initialization command sequence, the SD card will send back an R1 response byte. If only the IDLE bit of the R1 response is set, then the controller will repeatedly re-try the ACMD41 command while busy_o remains high.

If any other bit of the R1 response is set, then an error occurred. The controller will stall, lower busy_o, and output the R1 response code on the error_o bus. You'll have to pulse reset_i to unfreeze the controller.

If the R1 response is all zeroes (i.e., no errors occurred during the initialization), then the controller will lower busy_o and wait for a read or write operation from the host. The controller will only accept new operations when busy_o is low.

Write data:

To write a data block to the SD card, the address of a block is placed on the addr_i input bus and the wr_i input is raised. The address and write strobe can be removed once busy_o goes high to indicate the write operation is underway. The data to be written to the SD card is passed as follows:

  1. The controller requests a byte of data by raising the hndShk_o output.
  2. The host applies the next byte to the data_i input bus and raises the hndShk_i input.
  3. The controller accepts the byte and lowers the hndShk_o output.
  4. The host lowers the hndShk_i input.

This sequence of steps is repeated until all BLOCK_SIZE_G bytes of the data block are passed from the host to the controller. Once all the data is passed, the sector on the SD card will be written and the busy_o output will be lowered.

Read data:

To read a block of data from the SD card, the address of a block is placed on the addr_i input bus and the rd_i input is raised. The address and read strobe can be removed once busy_o goes high to indicate the read operation is underway. The data read from the SD card is passed to the host as follows:

  1. The controller raises the hndShk_o output when the next data byte is available.
  2. The host reads the byte from the data_o output bus and raises the hndShk_i input.
  3. The controller lowers the hndShk_o output.
  4. The host lowers the hndShk_i input.

This sequence of steps is repeated until all BLOCK_SIZE_G bytes of the data block are passed from the controller to the host. Once all the data is read, the busy_o output will be lowered.

Handle errors:

If an error is detected during either a read or write operation, then the controller will stall, lower busy_o, and output an error code on the error_o bus. You'll have to pulse reset_i to unfreeze the controller. That may seem a bit excessive, but it does guarantee that you can't ignore any errors that occur.

The SD card controller was successfully tested with a 2GB Sandisk SD card, a 4GB Sandisk SDHC card, and a 4GB Kingston SDHC card. The controller module was also ported to the original XuLA and tested using the setup shown below.

Setup for XuLA - SD Card Test


Viewing all articles
Browse latest Browse all 14

Trending Articles