some background to my story to begin with: I went to a store and asked for a bluetooth fm transmitter for my car and the guy sold me something that only plays from an SD card and I didn't even bother to check it. So I'm sitting here trying to hack it into playing audio from bluetooth. I thought that it would use an ic to read from the SD and export audio into another ic that sends the sound to the fm antenna but as it turns out it uses a single ic for everything (even for driving the little LCD screen). So I thought that I could emulate an SD card with a microcontroller or even better a RaspberryPi and dynamically change the contents of the "SD" on the go. I remembered that when I was trying out online streaming sound my software created an mp3 file that continued writing the currently streaming audio and in that way it kept playing. So if I could "stream" a file like that into the emulated SD card and have my little FM transmitter play it I could actually create a little radio station for my car. Is something like that possible? How could I emulate an SD?


closed as too broad by Chris Stratton, JRE, Finbarr, Lior Bilia, Sparky256 Jan 2 at 22:40

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ It's not easy. There are guys who had examined cards by etching them. Nothing useful. Keep in mind that many licences like navigation maps, industrial controllers use SD cards for licensing products, well you not gonna find any such emulator, because it's too dificult to implement, IMO. \$\endgroup\$ – Marko Buršič Aug 11 '18 at 16:08
  • 1
    \$\begingroup\$ Even if you could emulate a card, you generally can't modify a file system while someone else is reading it. You'd be confined to giving them data in the chunks they ask for, when they ask for it, and in a way consistent with the metadata and headers already read. So you could change the content on the fly if you stayed ahead of buffer fills, but probably not the duration, etc. \$\endgroup\$ – Chris Stratton Aug 11 '18 at 16:18
  • \$\begingroup\$ Thank you for your answers... I know it's a very difficult task if not impossible as Turbo J answered. \$\endgroup\$ – Frank F. Aug 11 '18 at 16:24
  • 2
    \$\begingroup\$ I don't get the description. What is that your device actually does and what you expect it to do? If it plays from SD card, why don't you insert SD card and be done with it? What data storage you were planning on using? Some bluetooth player? I don't see much difference between uploading files to bluetooth player and to SD card. \$\endgroup\$ – Maple Aug 11 '18 at 22:03
  • \$\begingroup\$ @Maple my device plays mp3 files from an SD card and I want it to play music from my phone via bluetooth. \$\endgroup\$ – Frank F. Aug 12 '18 at 11:27

Is something like that possible?

Not with any arduino compatible MCUs or the Raspberry Pi. To properly emulate a card you would need to support the SD protocol in one-bit mode up to 25MHz - waaay too fast for any microcontroller without special hardware support. No arduino is known to have this hardware.

It might be just doable with an FPGA - but the required SD specs are not exactly open, either.

  • \$\begingroup\$ Too bad, I was actually very hyped about this project even though it's not worth it... Thanks for the answer \$\endgroup\$ – Frank F. Aug 11 '18 at 16:19
  • \$\begingroup\$ @TurboJ This is patently not true, there are many SD card implementations for Arduino and other MCUs. You don't need to run at 25MHz at all. Depending on the Class you want to emulate you may indeed need multiple lanes and high frequency clocking, but all cards will support the Rev 1 spec at 12.5MHz and a single lane as a fallback. en.wikipedia.org/wiki/Secure_Digital \$\endgroup\$ – Jack Creasey Aug 11 '18 at 17:40
  • \$\begingroup\$ Plainly wrong: The host side works on Arduino just fine, but not the card side. And the card side needs to work at least at 25 MHz, see chapter 3.9.6 in the simplified spec. \$\endgroup\$ – Turbo J Aug 11 '18 at 19:20
  • \$\begingroup\$ Note that the host drives the clock, and thus defines how fast the card must supply its data. Most (simple SPI) SD implementations that I am aware of simply switch to "up to 25MHz clock rate" once the card is properly detected. \$\endgroup\$ – Turbo J Aug 11 '18 at 19:22
  • 2
    \$\begingroup\$ You are right, the Speed Classes don't count. But the SPI interface can work at essentially any speed. Most small MCU implementations set speeds from 1MHz to 16MHz depending on their clock divide capability with 25MHz being the absolute maximum for default speed and 50MHz for Fast cards. So we get back to the basic problem with your post which says you 'must' support 25 MHz ….whereas almost any frequency above 400kHz (and at or below CSR (Tran_Speed)) will work in SPI mode. \$\endgroup\$ – Jack Creasey Aug 11 '18 at 21:40

Emulating a raw SD/MMC interface is not the base problem for you. Creating a hardware interface is relatively easy and there are multiple FPGA implementations out there. If your player can read V1.0 SD cards, then you can run 1 lane at 12.5Mhz, which could easily use something like an Arduino SPI interface. Raspberry Pi would be a greater challenge, though you might be able to boot from USB and hack the SD card interface (a huge low level driver challenge) hardware.

The real problem (after you've built the raw interface) is that you have media which is dual access with no way to sync the contents for the player side.

  1. The device you plug the SD card into (emulated or not) will read the card and probably hold some small part of the file system metadata in ram as it functions. In your case the player only reads from the SD card, but even so it will have to manage streaming the file system segments into memory to play the music.
  2. You want to come behind the scenes and dynamically add data to the file system, but the player does not know the file system is changing.

If you were to dynamically load data on your dual port SD card emulator, you'd have to fake an eject/insert to get the player to re-read the filing system. That would be possible but again you are left with the potential for misreading if you alter the FS content unknown to the reader.
You could be incredibly lucky and the player holds almost no file system metadata in ram, so does re-read and scan the FS directory for each item it plays. You could ascertain this by monitoring the reads to the SD card. Following the command structure is quite a task on it's own, and not doable without a logic analyzer.
There is help, and you could start here for a simple view of the transactions.

  • \$\begingroup\$ Thank you for your answer! My thoughts were based my (little) knowledge of how streaming online works but what I understand from your post is that my device (propably) loads the (mp3) file or big chunks of it into the RAM and then plays it and it will have problems with the file being incomplete. How does VLC for example work though? Because I'm able to play file like this (for example i found this stream mp3.stream.tb-group.fm/tb.mp3 ) from an audio widget in HTML and from VLC. What are the differences? \$\endgroup\$ – Frank F. Aug 12 '18 at 11:41
  • \$\begingroup\$ It's unlikely that your devices is much more than 1 or 2 (blocks) segments ahead of the data it needs. Ram buffering may only be a few k'. Understanding audio formats and compression is a longer discussion, but you could start here: en.wikipedia.org/wiki/Comparison_of_audio_coding_formats Remember we work for points here, so if the answer is useful vote for it. \$\endgroup\$ – Jack Creasey Aug 12 '18 at 17:15

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