Electrical – Is it possible to emulate an SD as a slave

microcontrollersdstorage

What I want to do is put a dummy SD card (the connector going directly to the device with a cable going to a micro controller) into a device so that when the device tries to write a file the micro controller can intercept it and write it to another location, and then when the device wants to read it you can emulate the files that are supposed to be there except that they are stored on the micro controllers side.

Is there such a project that already exists? Is this even possible (i assume so as thats how most USB sticks work, kind of)? What would I need to do this project?

Best Answer

what I want to do is more of a work around for not being able to connect multiple cameras to an MCU, so what I want to do is emulate the SD cards that cheap point and shoot cameras use to save the images. So I wire up the triggers of the cameras to the MCU and grab the images directly from the SD slot in each camera

Simple solutions:

  • Use USB cameras connected to a USB host MCU like Raspberry Pi
  • Use WiFi or LAN cameras
  • Use a WiFi-enabled SD card

Complicated solution:

From the point of view of the camera, your device must behave exactly like a SD card. The camera will probably cache some of the contents of the card, including filesystem metadata, so there is no hope to have one card with one filesystem connected to several cameras, nor to be able to modify the contents of the emulated SD while it is attached to the camera.

Also the device should respond to commands whenever the camera sends them, since the camera expects the SD to be ready. This could be a problem because there doesn't seem to be a simple way for the card to tell the camera that it is busy and send a command later. So if you use a naive approach like this, and your micro is talking to the SD card, and the camera decides to talk to it at the same time, that won't work. If there is no switch on the bus then there will be a collision, and if there is a switch the camera will try to talk to the SD card while the switch has connected the card to the micro instead, so the camera will probably decide there is no SD card, so GTFO.

If I had to do this, I'd probably put a tiny FPGA between the camera and the SD card, that can receive and buffer commands sent from the camera to the card, then forward them to the SD card when the micro isn't accessing it. So the FPGA would act like a SD switch, allowing the camera to read and write and the micro to read, but not at the same time of course. I guess if the camera sends a command to the FPGA while the micro is busy with the card, the FPGA should buffer the command while the micro finishes, then take control of the SD, forward the command to it, and let the SD and camera talk together.

This sounds like a very complex project, especially considering the simple off the shelf competing solutions.