esp32/sdcard: Add support for SDMMC power control with internal LDO.#18985
esp32/sdcard: Add support for SDMMC power control with internal LDO.#18985sfe-SparkFro wants to merge 2 commits intomicropython:masterfrom
Conversation
A board can #define MICROPY_HW_SDMMC_LDO_CHAN_ID in mpconfigboard.h for an internal LDO to control power to the SDMMC GPIO pins. This is needed to use SDIO 3.0, because the IO level has to switch between 3.3V and 1.8V. Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
The ESP32-P4-Function-EV-Board uses LDO 4 for controlling SDMMC GPIO power. This is required to use SD cards with this board. Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
|
Code size report: |
[https://github.com//pull/18538] Is the driver duplicated? |
|
Ah, I was not aware of that feature, thanks! Hmm, the tricky thing here is that the SDIO 3.0 spec requires the GPIO voltage to dynamically change between 3.3V and 1.8V, though I admittedly don't know when the voltage is meant to change back and forth. That's handled by the ESP-IDF when you set Perhaps What do you think? |
|
Ok, I did some reading, and my suggestion of optionally passing an So this actually means the user needs to not create the |
To more directly answer your question - no, this PR is not a duplicate of the |
|
Thank you for your response. I asked this question because I often encounter issues with objects failing to initialize after repeated soft reboots during development, and I can see this point reflected in your reply as well. Therefore, I have the same concern about the module implicitly initializing the LDO, as it could lead to multiple issues stacking up and making it difficult to determine which step went wrong (one action triggering two objects initially). However, I believe this can be addressed by clearly explaining it in the documentation. |
Is that possibly related to #19008? In general, the same code should execute the same way after a soft reboot. If it doesn't, it's probably a bug. FWIW I've tested this PR with soft reboots and it works fine on my end. |
Summary
Fixes #18984.
Testing
Before this change, the following error was thrown when trying to mount an SD card:
After this change, the SD card mounts just fine:
Trade-offs and Alternatives
This PR changes
ESP32_GENERIC_P4to assume LDO 4 is used for powering the SD card, which may not be true for all boards. This board definition is meant to be generic, so I can see arguments for not doing this. However without this change, an SD card cannot be used with the ESP32-P4-Function-EV-Board at all. Since the ESP32-P4-Function-EV-Board is what's depicted on the MicroPython download page, I would argue in favor of keeping this change.A possible alternative is for the LDO to be specified as an argument in
machine.SDCard()instead of the board definition. However for a given board, the LDO is a fixed parameter, so IMO it really should live in the board definition to avoid extra tedium with manually specifying the LDO in user code; I see the generic board definition as an exception.Generative AI
I did not use generative AI tools when creating this PR.