Skip to content

Commit f5ebc3b

Browse files
committed
esp32/sdcard: Add support for SDMMC power control with internal LDO.
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>
1 parent 78ff170 commit f5ebc3b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

ports/esp32/machine_sdcard.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
#if SOC_SDMMC_HOST_SUPPORTED
3737
#include "driver/sdmmc_host.h"
38+
#if SOC_SDMMC_IO_POWER_EXTERNAL && defined(MICROPY_HW_SDMMC_LDO_CHAN_ID)
39+
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
40+
#endif
3841
#endif
3942
#include "driver/sdspi_host.h"
4043
#include "sdmmc_cmd.h"
@@ -310,6 +313,14 @@ static mp_obj_t machine_sdcard_make_new(const mp_obj_type_t *type, size_t n_args
310313
self->host = _temp_host;
311314
}
312315
#endif
316+
#if SOC_SDMMC_IO_POWER_EXTERNAL && defined(MICROPY_HW_SDMMC_LDO_CHAN_ID)
317+
sd_pwr_ctrl_ldo_config_t ldo_config = {
318+
.ldo_chan_id = MICROPY_HW_SDMMC_LDO_CHAN_ID,
319+
};
320+
sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
321+
check_esp_err(sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle));
322+
self->host.pwr_ctrl_handle = pwr_ctrl_handle;
323+
#endif
313324

314325
DEBUG_printf(" Calling host.init()");
315326

@@ -431,6 +442,11 @@ static mp_obj_t sd_deinit(mp_obj_t self_in) {
431442
// SD card used a (dedicated) SPI bus, so free that SPI bus.
432443
spi_bus_free(self->host.slot);
433444
}
445+
#if SOC_SDMMC_IO_POWER_EXTERNAL && defined(MICROPY_HW_SDMMC_LDO_CHAN_ID)
446+
if (self->host.pwr_ctrl_handle) {
447+
check_esp_err(sd_pwr_ctrl_del_on_chip_ldo(self->host.pwr_ctrl_handle));
448+
}
449+
#endif
434450
self->flags &= ~SDCARD_CARD_FLAGS_HOST_INIT_DONE;
435451
}
436452

0 commit comments

Comments
 (0)