Project strategic objective:
Make Wixel open/ create /read/write/ change /delete/ files, saved on the SD Card in FAT32 ( may be exFAT ) format. Connect Wixel to the PC as USB Mass Storage Device, for access to Wixel created files.
Current part of project objectives:
- Initialize SD Card.
- Connect Wixel to the PC by USB like a Flash Drive.
Project source files:pololu_wixel_msd.rar (597 KB)
For connection SD Card and Wixel we use SPI. Electrical connections are shown in the figure below.
Its so simple because supply voltage jf the Wixel and SD Card is same = 3,3V. So, no need to use any convertors.
In Internet you can find a lot of material about how to initialize SD card, but for a better understanding of the process, I recommend to read this document: sdcard.org/downloads/pls/si … t1_410.pdf in the part where it says about the the SPI mode. Special attention should be paid to the figure 7.2, because this is the algorithm to initialize the card.
So,
The first step of initialization is setup connection with SD Card by SPI(module spi0_master.c). It performs the function init_spi(). Parameters(Frequency, Polarity, Phase) are set up by testing, since they may differ for different types of SD Cards.
Second step is SD Card initialization (module diskio.c). At this stage I took as basis PetitFS library ( elm-chan.org/fsw/ff/00index_p.html ) written by Great Master ChaN. But I had to modify the code because it did not work as-is. The difference you can see by comparing my files and Petit FS source files.
Well. Now we can read/write data blocks from/to SD Card. But what to do with this?
Now we must access the SD Card data for PC by the USB Interface. At this stage we don’t care to know how does FAT32 works. Our Wixel should only perform the ReadBlock/WriteBlock commands coming from the PC.
USB protocol is described in detail in the specifications. Look at it ( usb.org/developers/docs/usb_20_070113.zip - usb_20.pdf ) to understand the basic principles of USB. It is very hard to understand, but very simple to use. In short: because Wixel seems like a SCSI disk on the handshake stage, so PC begins to send to the Wixel simple SCSI commands. The task of the Wixel is just to process this commands. These features provide in module usb_msd.c
It works! Very slow, but works.
But, the primary objective has not been reached yet. Now PC read/write on SD Card, however, we need to Wixel read/write itself.
So, it is time to understanding FAT32.
Key issues:
1. I was able to initialize the SD Card SDHC type 2. however, a SD Card SDHC 4 and SDXC failed to initialize.
2. USB speed very low (read on 160-200 kbit/s, write faster – 500-700 kbit/sec (depend on files length))
Key questions:
1.How to increase the read/write speed? Are there similar SoC like C2511 but with High-Speed USB interface?
2. Where can I find SD Card SDXC and SDHC 4 specifications?
Project in progress ########################################################
Welcome to cooperation!