0
\$\begingroup\$

I am using a microcontroller (PIC32MZ) to transfer the data from an SD Card to USB, with this configuration:

schematic

simulate this circuit – Schematic created using CircuitLab

I managed to have everything working using Harmony v1.09 framework, and I could get a transfer rate of about 1.5MBytes/s, which is pretty good, but...when using SD Cards with large memory, this rate still looks to slow. For example, it requires 6h to transfer 32GB!!!!

Looking at the components one by one, I can't see why the transfer rate is not higher:

  • The actual card I am using for my test reached the speed of 20MBytes/s when plugged into my computer. It probably used 4 wires, but then it would be around 5MBytes/s on each wire
  • The PIC can support High Speed USB, which has a transfer rate of 60MBytes/s (480Mbits/s)
  • The SPI bus between the card and the micro is running at 50MHz, which corresponds to a maximum rate of 6.25MBytes/s

Why can't I get at least something closer to 5MBytes/s, which seems to be the lowest rate of the system? What is the bottleneck here? Is it possible to improve it?

Datasheets:

\$\endgroup\$
  • 1
    \$\begingroup\$ The bottleneck is somewhere in your black box. Without knowing anything about what is inside, how should we know how to improve it. \$\endgroup\$ – Tom Carpenter Nov 17 '16 at 9:28
  • \$\begingroup\$ @Tom Carpenter Which part is a black box for you? I can provide more information on it. Do you have any suggestion on an alternative component that would be less "black"? \$\endgroup\$ – Edesign Nov 17 '16 at 9:34
  • 2
    \$\begingroup\$ @Edesign your microcontroller! A microcontroller is just a small computer. Now, we don't know your firmware, we have no idea of how you handle USB and SPI data transfers, we don't know the PC-side driver for your device... all you're saying is that "hey, I have this car that goes from Mumbai to Moscow, and all the road are rated for 200km/h travel, why is it taking me so long", without mentioning the details of the car, the person driving that car, the traffic situation, your route... \$\endgroup\$ – Marcus Müller Nov 17 '16 at 9:59
1
\$\begingroup\$

The SPI bus between the card and the micro is running at 50MHz, which corresponds to a maximum rate of 6.25MBytes/s

The SD card spec only allows up to 25 MHz in SPI mode - I would not risk higher speeds in case one uses different cards.

But this could yield about 3MByte/sec. Note that you may need to use multi block transfers for maximum throughput as there would be gaps for command activies otherwise. Most MCU example code only use single block transfers for simplicity.

\$\endgroup\$
  • \$\begingroup\$ Thank you for the ideas. My card seems to work at 50MHz (high speed mode), but there is no speed improvement compared to 25MHz, so I will probably follow your advice. The multi block transfer seems to be activated already by the Harmony driver. \$\endgroup\$ – Edesign Nov 18 '16 at 8:20
0
\$\begingroup\$

Agree with Turbo J to get close to your max (spi limit) you must use mutli block rd/write .

Most usb middle-ware an code example commonly do simple single packet and blocking usb to sd write. To sustain the full data rate on SPI and reach the last missing % you must do parallel sd access and usb or you will always have gap on SD that is the time for usb to send next part of the write data (at 480MBps data rate). It's 5%-10% of the SPI bandwidth loss assuming 25-50Mbps.

A 4 data lanes sd controller interface will help greatly but your mcu don't have it I guess.

note that Sd cards can be slow do not expect to get 6MB/s out of a class 2 device even class 6 may just do 6MB/s.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.