Can I use the Teensy to emulate a SD memory card (to deliver a virtual block device)

Status
Not open for further replies.
The closest project I can find anywhere is this one http://webpages.uncc.edu/~jmconrad/ECGR6185-2008-01/notes/SD_CARD_DISPLAY_MICROCONTROLLER.pdf / ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2007/209/Davaine-209.zip .

The Raspberry Pi forum has a thread on the same topic, asking how to do this: https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=135915 .

If SPI slave is the communication mode, then the Teensy 3.5 at least has the proper support for it, its CPU manual https://cache.nxp.com/files/microcontrollers/doc/data_sheet/K64P144M120SF5.pdf page 56+ clarifies that SPI slave mode is supported.

Do you have further pointers on how to materialize this?
 
If you want to make some widget that looks to a PC, camera etc. as if it was a real SD card, you need to present a 4-bit SDIO interface. As far as I know, SDIO in slave mode isn't possible with a Teensy. You need a real or emulated flash memory controller device as used in SD cards.

If your host device expects to use the 1-bit SPI mode, the Teensy can be a SPI slave, so that might be possible with the right code. I don't know your application but I had the impression that few if any modern commercial devices use 1-bit SPI for SD card access because it is so slow. These days that kind of interface is mostly just the hobbyist field, like people using Arduinos as data loggers.
 
Last edited:
JBeale, thank you very much for your response.

Would you mind providing more concrete suggestions (particular chips and any other resources) to how I could emulate an SD card as inexpensively as possible?

Let's call it a DIY programmable sd-card to sd-card adapter/proxy, or a hardware SD card emulator.

(Actually buying SD cards and then flashing them with homemade firmware, as done by Bunnie at MIT (https://www.youtube.com/watch?v=r3GDPwIuRKI / https://www.bunniestudios.com/blog/?p=3554), could perhaps be done, but it would seem like a very dirty solution to me. Some kind of ARM board like Teensy, properly plugged in to SD, would seem like a clean solution though.)

Thank you very much for your consideration.
 
JBeale, thanks a lot for responding again.

I have five followup Q:s. I hope these are final.

1) By "4-bit" do you mean "4 parallell data transfer lanes [one per separate physical connectors]"?

2) What about the ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2007/209/Davaine-209.zip project which I references above here, which emulates an MMC card via the SDIO interface.

The http://webpages.uncc.edu/~jmconrad/ECGR6185-2008-01/notes/SD_CARD_DISPLAY_MICROCONTROLLER.pdf slides say they used the Luminary Micro LMS3811 which uses the "LM3S811" CPU, and its whitepaper http://www.ti.com/lit/ds/symlink/lm3s811.pdf , and bottom of page 39 says it features "Synchronous Serial Interface (SSI) [which] is a four-wire bi-directional full and low-speed communications interface".

Is this four-bit SDIO interface you're talking about?

3) Are you aware of any particular /other/ very small and inexpensive computers that would be suitable to use to emulate SD?

4) Re the Teensy, Teensy 3.5's manual is https://cache.nxp.com/files/microcontrollers/doc/data_sheet/K64P144M120SF5.pdf - page 1 says the chip has "Three SPI modules", and page 56+ clarifies it "The DMA Serial Peripheral Interface (DSPI) provides a synchronous serial bus with master and slave operations.".

So the issue here is that it has three separate 1-bit SPI buses, which indeed can be run in slave mode though -

So this is totally useless for SD card emulation purposes?

5) Could you emulate an SD card by bit-banging? Maybe the Teensy could do some hundred KB/sec that way :)

Thanks!!
Tink
 
JBeale, thanks a lot for responding again.

I have five followup Q:s. I hope these are final.

1) By "4-bit" do you mean "4 parallell data transfer lanes [one per separate physical connectors]"?

2) What about the ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2007/209/Davaine-209.zip project which I references above here, which emulates an MMC card via the SDIO interface.

The http://webpages.uncc.edu/~jmconrad/ECGR6185-2008-01/notes/SD_CARD_DISPLAY_MICROCONTROLLER.pdf slides say they used the Luminary Micro LMS3811 which uses the "LM3S811" CPU, and its whitepaper http://www.ti.com/lit/ds/symlink/lm3s811.pdf , and bottom of page 39 says it features "Synchronous Serial Interface (SSI) [which] is a four-wire bi-directional full and low-speed communications interface".

Is this four-bit SDIO interface you're talking about?

3) Are you aware of any particular /other/ very small and inexpensive computers that would be suitable to use to emulate SD?

4) Re the Teensy, Teensy 3.5's manual is https://cache.nxp.com/files/microcontrollers/doc/data_sheet/K64P144M120SF5.pdf - page 1 says the chip has "Three SPI modules", and page 56+ clarifies it "The DMA Serial Peripheral Interface (DSPI) provides a synchronous serial bus with master and slave operations.".

So the issue here is that it has three separate 1-bit SPI buses, which indeed can be run in slave mode though -

So this is totally useless for SD card emulation purposes?

5) Could you emulate an SD card by bit-banging? Maybe the Teensy could do some hundred KB/sec that way :)

Thanks!!
Tink

if you go to https://en.wikipedia.org/wiki/Secure_Digital#Transfer_modes
you find the descriptions on the different access modes.
As you already opened the K64 document, go down to sdio and find the description on how K64/66 use sdio to access the SD cards.

fast sd card access use 4-bit SD card access mode and K64/66 provide the interface for doing this.
 
The SDIO interface to a SD is a 4-bit wide bus. It is like SPI except there are 4 bits in parallel instead of only 1 as with normal SPI. Teensy 3.5/3.6 has the SDIO controller hardware to talk with a SD card. That is host mode, not device mode like the controller inside an actual SD-card. The 3 separate normal SPI ports don't provide a 4 bit interface, even if they were synchronized. Sure, in theory you can always do bit-banging, at some relatively slow rate.

I am not an expert on SD and have no familiarity with the SDIO spec myself. There may be hard timing restrictions which would prevent bitbanging from working in practice unless you use a FPGA or dedicated chip. The opencores project I linked to mentioned including a simple simulation of a SD card for testing purposes. I haven't checked the circuit cellar project but if that works, maybe that's a good place to start. Good luck!
 
Status
Not open for further replies.
Back
Top