
Ok, I've got a v1.0 release of working code now at 50 MHz!
Many thanks to Hamster for the help!
You can find the code (with readme) here: http://www.rulecity.com/browsetmp/sd_card_writer-17Feb2013.7z
Please feel free to suggest improvements to the stupid bone-headed newbie VHDL mistakes I make!
--------------------------------------------------------
VHDL SD card writer v1.0
By Matt Ownby (http://www.daphne-emu.com and http://www.laserdisc-replacement.com)
16 Feb 2013
This is VHDL code (for the Papillio One FPGA board) that shows how to write to an SD card in a high-speed mode.
Features:
- Uses 4-bit SD mode, not 1-bit SPI mode (faster)
- Uses 50 MHz "high speed" mode, not 25 MHz "normal speed" mode (also faster)
- Logs to Papillio USB serial port (230400 bps) so you can see what is going on
Requirements:
- An SDHC card (older probably won't work) that supports high-speed aka 50 MHz mode.
How to use:
- Get the pins of an SD card (or adapter) somehow connected to Papillio pins. Not discussed here as you are expected to have enough expertise to figure this out on your own
What you will see on serial port (230400 bps) if everything is working correctly (this is very terse since string handling is a pain in VHDL):
-
C00
C08
C55
A41
C55
A41
C55
A41
C55
A41
C55
A41
C55
A41
C55
A41
C55
A41
C55
A41
C02
C03
C07
C55
A06
C06
C24
C13
S
Explanation of above data:
"-" gets sent on reset, it means the process is starting over
"C00" is the reset command sent to the SD card. It expects no response.
"C08" is the voltage-request command and is only supported on newer cards. The Papillio requests normal 3.3V operation. If I/O is not working, or if the SD card does not support this command, this is the last line you will see.
"C55/A41" is the init command. It usually needs to be repeated over and over again until initialization is finished which is normal.
"C02" is the "get SD card CID" command. It is required otherwise I wouldn't bother sending it.
"C03" is the "get SD card's relative address" command. It is also required.
"C07" puts the SD card into transfer mode.
"C55/A06" switches the SD card from a 1-bit bus into a 4-bit bus (4x speed increase).
"C06" switches the SD card from 25 MHz mode to 50 MHz mode (2x speed increase). If you see an "E" after this, it means that the CRC check failed (this happened to me occasionally during development).
"C24" starts writing a single 512 byte block at address 0 (beginning of card).
"C13" requests the card's status and is optional but it makes me feel better to see it working since at this point we are communicating at 50 MHz.
"S" means 'success' and means that the SD card responded that the write operation was completely successful. If you see an "E" here it means that the CRC check probably failed.
If you see anything with "X" in front of it, it means that an unexpected response was received and the unexpected response has been dumped out in ASCII hex format. This is for troubleshooting purposes.
There are no comments to display.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.