SdFat icon indicating copy to clipboard operation
SdFat copied to clipboard

Two SDIOs on RP2040

Open Stass48 opened this issue 8 months ago • 6 comments

Hello! I’m really sorry for the silly question — maybe someone has already asked this (but I couldn’t find it). 1. Could you please tell me if it’s possible to use two SD cards on a single RP2040 (for data copying and other tasks)? 2. Will other PIO-based interfaces, such as I2S, still work properly in this setup? 3. Will there still be any remaining PIO resources available on the controller with such a configuration?

I apologize if my questions seem too basic. I truly appreciate your help and willingness to discuss these topics. I remember our conversation a year ago — you helped me a lot back then. Thank you so much for everything!

Stass48 avatar Mar 11 '25 13:03 Stass48

  1. Could you please tell me if it’s possible to use two SD cards on a single RP2040 (for data copying and other tasks)?

You can use many SPI cards but only one SDIO card. There is not sufficient memory in a PIO block to add support for multiple cards on one PIO controller.

  1. Will other PIO-based interfaces, such as I2S, still work properly in this setup?
  2. Will there still be any remaining PIO resources available on the controller with such a configuration?

PIO SDIO uses one PIO block. RP2040 has two blocks, RP2350 has three blocks. SdFat checks for free PIO resources and reserves them. Some PIO interfaces libraries do not check/reserve PIO resources and will not work reliably.

greiman avatar Mar 11 '25 14:03 greiman

Thank you for your answer 🙏

You can use many SPI cards but only one SDIO card. There is not sufficient memory in a PIO block to add support for multiple cards on one PIO controller.

Does this apply only to the RP2040? Or does the RP2350 have the same issue with a lack of PIO memory?

Stass48 avatar Mar 11 '25 14:03 Stass48

Does this apply only to the RP2040? Or does the RP2350 have the same issue with a lack of PIO memory?

PIO blocks in the RP2350 have the same amount of memory as the RP2040.

I suspect there could be problems implementing more SDIO features in PIO. I was only able to implement the most basic SDIO features with PIO.

greiman avatar Mar 11 '25 14:03 greiman

Thank you, Bill. You're amazing!

Stass48 avatar Mar 11 '25 23:03 Stass48

@greiman Thank you for the amazing library! While I was trying to find out which resources the SDIO implementation requires, I found out that there might be a bug: PioSdioCard.cpp claims two state machines, but it only checks (twice) if the first one (g_sm0) was assigned successfully (in lines 284 + 289).

Furthermore, with regards to this issue, if I am correct about this two state machine assumption, doesn't that mean that the next two state machines on the same block can run another SDIO interface? You can reuse the same instructions on multiple SMs at once, by just referencing them to the same program offsets. So the only limitation would be to check whether there is already an instance of an SDIO interface active, and just return the same program offsets with the other two SMs of the same block. Also, if I understand the code correctly, it is already possible to run multiple interfaces on multiple blocks as well? So up to 4 SDIO cards on RP2040 and 6 on RP2350 (or with the current implementation 2 or 3 SDIO cards, one on each block?). I don't have a way to test this, as I am just about to order my first PCB with one SDIO card on it, but I think it should be possible.

bastian2001 avatar Mar 27 '25 13:03 bastian2001

I am currently making many mods in the programs. I will fix the check for assignment program.

The normal way to run multiple cards in on a single bus. I have done none of the code to handle this.

I also modify the PIO program in memory to embed a GPIO number here.

Actually the entire PioSdioCard.cpp file is currently full of global variables and static function. I am modifying much of this.

greiman avatar Mar 27 '25 14:03 greiman