Page 1 of 1

How to use SD_MMC.setPins()?

Posted: Fri Oct 21, 2022 6:55 am
by techtoys
Hi

I am trying to use IO4 as SD_MMC's D0 to avoid conflict of ESP32 bootstrap with IO2 which is the default SD_DATA0 pin of SD_MMC driver.

My original wiring was:
SD_CMD : IO15 with 10k pullup
SD_CLK : IO14
SD_DATA0 : IO2 (with 10k pullup after code download)

The original wiring works OK but I needed to solder a 10K pullup to IO2 everytime I downloaded a new code and it is very tedious.

I came up with an idea to use SD_MMC.setPins() to use IO4 as the SD_DATA0 with a permanent 10K pullup. The new wiring is :
SD_CMD : IO15 with 10k pullup
SD_CLK : IO14
SD_DATA0 : IO4 with 10k pullup

IO2 is now unconnected so that there is no bootstrap issue.

My code to set IO4 as SD_DATA0 is:

Code: Select all

      
      if(!SD_MMC.setPins(14, 15, 4))///SD_CLK=14, SD_CMD=15, SD_D0=4
      {
        Serial.println("Set pin failed!");
      }
      while(!SD_MMC.begin("/cdcard", true)){ ///We are using pins SD_DATA0 and _DATA1 only
          Serial.println("Card Mount Failed");
          delay(500);
      }
Unfortunately, SD_MMC.setPins() does not work as expected with "Set pin failed!" messages followed by ("Card Mount Failed").

Is there anything I have missed?

John

Re: How to use SD_MMC.setPins()?

Posted: Fri Oct 21, 2022 11:25 am
by ESP_igrr
Hi John,

This function is intended for the ESP32-S3 chip, where SDMMC pins can be freely configured using the GPIO Matrix.

On the ESP32 this function can still be called, but it will only succeed if you pass the actual pins of SDMMC slot 1.
(If you don't call this function on the ESP32, it's not a problem, the same pins will be used.)

Basically, it's not possible to customise SDMMC pins on an ESP32.

Re: How to use SD_MMC.setPins()?

Posted: Fri Oct 21, 2022 8:01 pm
by lbernstone
I think if you set the logging to verbose, you will get a message ("SDMMCFS: specified pins are not supported by this chip.") that would at least give you a bit more reason why setPins is failing.

Re: How to use SD_MMC.setPins()?

Posted: Sat Oct 22, 2022 4:56 pm
by techtoys
Thank you for the replies. I will keep the conventional practice of soldering a 10K pullup to use a mmc card on IO2 when the code is released. In future hardware it may be possibe to put an analog switch in series of the pullup resistor in normal close position. The switch is disconnected when a USB cable is detected. The cost is a slightly more complex hw design but it will make code download more simple.