Pololu Wixel with SD Card as USB Mass Storage Device

Show everyone what you've built! Don't forget pictures of your creations.

Pololu Wixel with SD Card as USB Mass Storage Device

Postby VolAnd » Tue Jul 09, 2013 9:12 pm

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:
Wixel-SD project source files
(597.39 KiB) Downloaded 119 times

For connection SD Card and Wixel we use SPI. Electrical connections are shown in the figure below.

wixel_sd.jpg (138.01 KiB) Viewed 3242 times

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: https://www.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.

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 ( http://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 ( http://www.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!
User avatar
Posts: 4
Joined: Mon Jul 08, 2013 9:05 pm
Location: Russia St-Petersburg

Re: Pololu Wixel with SD Card as USB Mass Storage Device

Postby DavidEGrayson » Wed Jul 10, 2013 9:47 am


Thank you for sharing your project here! It is cool that you were able to get everything working.

I have added your app to the list of Wixel apps on the forum, and we are also planning on adding it to the Community Projects page.

Full speed USB is 12 Mbps (not counting all the protocol overhead), so I think the USB connection is probably not preventing you from making read and write speeds to be faster. I don't know if this is possible or if you already implemented it, but it would be good if the USB transfers can happen in parallel with reading/writing data from the card.

For high-speed USB, there are probably some ARM-based microcontrollers from ST or NXP that can do it. It is unlikely that they would have a radio built-in though, like the CC2511.

I am not sure if it does high-speed USB or not, but the mbed acts a USB mass storage device.

Pololu Employee
Posts: 2743
Joined: Thu Apr 03, 2008 11:30 am
Location: Las Vegas, NV

Re: Pololu Wixel with SD Card as USB Mass Storage Device

Postby VolAnd » Thu Jul 11, 2013 5:17 am

Hi, David

You're right.
Full-speed USB not a reason for low read/write speed in this case.

In accordance with the http://www.ti.com/lit/ds/symlink/cc2511f32.pdf :

" The maximum baud rate for SPI master mode and thus SCK frequency is F/8
If SPI master mode does not need to receive data, the maximum SPI rate is F/2"

F is the system clock frequency. F=24Mhz

F/8 =24000000/8=3000000= 3 Mbit/s.
So, use High-speed USB does not make sense.

But I got read data speed on the order below - 0,3Mbit/s. :-(
User avatar
Posts: 4
Joined: Mon Jul 08, 2013 9:05 pm
Location: Russia St-Petersburg

Return to Share Your Projects

Who is online

Users browsing this forum: No registered users and 1 guest