From 36db47624b6f50c02727c54f1e2ecf93f069da23 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Tue, 17 Mar 2026 20:33:55 +0100 Subject: [PATCH 1/2] Fix for LilyGO T-HMI SD card --- Devices/lilygo-thmi/lilygo,thmi.dts | 2 ++ .../bindings/espressif,esp32-sdmmc.yaml | 10 +++++++++- .../include/tactility/drivers/esp32_sdmmc.h | 2 ++ .../source/drivers/esp32_sdmmc_fs.cpp | 20 +++++++++++-------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Devices/lilygo-thmi/lilygo,thmi.dts b/Devices/lilygo-thmi/lilygo,thmi.dts index a83a31db2..301f52553 100644 --- a/Devices/lilygo-thmi/lilygo,thmi.dts +++ b/Devices/lilygo-thmi/lilygo,thmi.dts @@ -28,6 +28,8 @@ pin-clk = <&gpio0 12 GPIO_FLAG_NONE>; pin-cmd = <&gpio0 11 GPIO_FLAG_NONE>; pin-d0 = <&gpio0 13 GPIO_FLAG_NONE>; + pin-d3 = <&gpio0 10 GPIO_FLAG_NONE>; bus-width = <1>; + pullups; }; }; diff --git a/Platforms/platform-esp32/bindings/espressif,esp32-sdmmc.yaml b/Platforms/platform-esp32/bindings/espressif,esp32-sdmmc.yaml index 7dbdabef9..e2acf679f 100644 --- a/Platforms/platform-esp32/bindings/espressif,esp32-sdmmc.yaml +++ b/Platforms/platform-esp32/bindings/espressif,esp32-sdmmc.yaml @@ -50,4 +50,12 @@ properties: enable-uhs: type: boolean default: false - description: Enable UHS mode \ No newline at end of file + description: Enable UHS mode + pullups: + type: boolean + default: false + description: Enable internal pullups for SDMMC pins + on-chip-ldo-chan: + type: int + default: -1 + description: On-chip LDO channel for SD power (e.g. 4 for LDO4). Set to -1 to disable. \ No newline at end of file diff --git a/Platforms/platform-esp32/include/tactility/drivers/esp32_sdmmc.h b/Platforms/platform-esp32/include/tactility/drivers/esp32_sdmmc.h index 152b42559..40beb383f 100644 --- a/Platforms/platform-esp32/include/tactility/drivers/esp32_sdmmc.h +++ b/Platforms/platform-esp32/include/tactility/drivers/esp32_sdmmc.h @@ -28,6 +28,8 @@ struct Esp32SdmmcConfig { uint8_t bus_width; bool wp_active_high; bool enable_uhs; + bool pullups; + int32_t on_chip_ldo_chan; }; /** diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdmmc_fs.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdmmc_fs.cpp index 9387d7568..664d9b917 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_sdmmc_fs.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_sdmmc_fs.cpp @@ -78,20 +78,23 @@ static error_t mount(void* data) { sdmmc_host_t host = SDMMC_HOST_DEFAULT(); #if SOC_SD_PWR_CTRL_SUPPORTED - sd_pwr_ctrl_ldo_config_t ldo_config = { - .ldo_chan_id = 4, // LDO4 is typically used for SDMMC on ESP32-S3 - }; - esp_err_t pwr_err = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &fs_data->pwr_ctrl_handle); - if (pwr_err != ESP_OK) { - LOG_E(TAG, "Failed to create SD power control driver, err=0x%x", pwr_err); - return ERROR_NOT_SUPPORTED; + if (config->on_chip_ldo_chan != -1) { + sd_pwr_ctrl_ldo_config_t ldo_config = { + .ldo_chan_id = (uint32_t)config->on_chip_ldo_chan, + }; + esp_err_t pwr_err = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &fs_data->pwr_ctrl_handle); + if (pwr_err != ESP_OK) { + LOG_E(TAG, "Failed to create SD power control driver, err=0x%x", pwr_err); + return ERROR_NOT_SUPPORTED; + } + host.pwr_ctrl_handle = fs_data->pwr_ctrl_handle; } - host.pwr_ctrl_handle = fs_data->pwr_ctrl_handle; #endif uint32_t slot_config_flags = 0; if (config->enable_uhs) slot_config_flags |= SDMMC_SLOT_FLAG_UHS1; if (config->wp_active_high) slot_config_flags |= SDMMC_SLOT_FLAG_WP_ACTIVE_HIGH; + if (config->pullups) slot_config_flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP; sdmmc_slot_config_t slot_config = { .clk = to_native_pin(config->pin_clk), @@ -124,6 +127,7 @@ static error_t mount(void* data) { fs_data->pwr_ctrl_handle = nullptr; } #endif + sdmmc_card_print_info(stdout, fs_data->card); return ERROR_UNDEFINED; } From 1a6cc814a5fcb493b1eb2136bf5d5c4d34234776 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Tue, 17 Mar 2026 20:47:29 +0100 Subject: [PATCH 2/2] Fixes --- Platforms/platform-esp32/source/drivers/esp32_sdmmc_fs.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdmmc_fs.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdmmc_fs.cpp index 664d9b917..6dbcb3785 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_sdmmc_fs.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_sdmmc_fs.cpp @@ -78,7 +78,8 @@ static error_t mount(void* data) { sdmmc_host_t host = SDMMC_HOST_DEFAULT(); #if SOC_SD_PWR_CTRL_SUPPORTED - if (config->on_chip_ldo_chan != -1) { + // Treat non-positive values as disabled to remain safe with zero-initialized configs. + if (config->on_chip_ldo_chan > 0) { sd_pwr_ctrl_ldo_config_t ldo_config = { .ldo_chan_id = (uint32_t)config->on_chip_ldo_chan, }; @@ -127,10 +128,10 @@ static error_t mount(void* data) { fs_data->pwr_ctrl_handle = nullptr; } #endif - sdmmc_card_print_info(stdout, fs_data->card); return ERROR_UNDEFINED; } + sdmmc_card_print_info(stdout, fs_data->card); LOG_I(TAG, "Mounted %s", fs_data->mount_path.c_str()); return ERROR_NONE;