From 326740779e5a8cfb2f9be953a1bc917850e624f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:47:13 +0200 Subject: [PATCH 01/16] feat(sdmmc): Add support for P4 --- cores/esp32/esp32-hal-periman.c | 3 ++ cores/esp32/esp32-hal-periman.h | 15 ++++--- .../SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino | 37 ++++++++++++----- .../SD_MMC/examples/SDMMC_time/SDMMC_time.ino | 1 + libraries/SD_MMC/src/SD_MMC.cpp | 41 +++++++++++++++++-- libraries/SD_MMC/src/SD_MMC.h | 7 +++- 6 files changed, 83 insertions(+), 21 deletions(-) diff --git a/cores/esp32/esp32-hal-periman.c b/cores/esp32/esp32-hal-periman.c index 6ef3c3d984a..0225543f7d9 100644 --- a/cores/esp32/esp32-hal-periman.c +++ b/cores/esp32/esp32-hal-periman.c @@ -87,6 +87,9 @@ const char *perimanGetTypeName(peripheral_bus_type_t type) { case ESP32_BUS_TYPE_SDMMC_D1: return "SDMMC_D1"; case ESP32_BUS_TYPE_SDMMC_D2: return "SDMMC_D2"; case ESP32_BUS_TYPE_SDMMC_D3: return "SDMMC_D3"; +#if SOC_SDMMC_IO_POWER_EXTERNAL + case ESP32_BUS_TYPE_SDMMC_POWER: return "SDMMC_POWER"; +#endif #endif #if SOC_TOUCH_SENSOR_SUPPORTED case ESP32_BUS_TYPE_TOUCH: return "TOUCH"; diff --git a/cores/esp32/esp32-hal-periman.h b/cores/esp32/esp32-hal-periman.h index 217d62b8741..6c5400cb085 100644 --- a/cores/esp32/esp32-hal-periman.h +++ b/cores/esp32/esp32-hal-periman.h @@ -79,12 +79,15 @@ typedef enum { ESP32_BUS_TYPE_SPI_MASTER_SS, // IO is used as SPI master SS pin #endif #if SOC_SDMMC_HOST_SUPPORTED - ESP32_BUS_TYPE_SDMMC_CLK, // IO is used as SDMMC CLK pin - ESP32_BUS_TYPE_SDMMC_CMD, // IO is used as SDMMC CMD pin - ESP32_BUS_TYPE_SDMMC_D0, // IO is used as SDMMC D0 pin - ESP32_BUS_TYPE_SDMMC_D1, // IO is used as SDMMC D1 pin - ESP32_BUS_TYPE_SDMMC_D2, // IO is used as SDMMC D2 pin - ESP32_BUS_TYPE_SDMMC_D3, // IO is used as SDMMC D3 pin + ESP32_BUS_TYPE_SDMMC_CLK, // IO is used as SDMMC CLK pin + ESP32_BUS_TYPE_SDMMC_CMD, // IO is used as SDMMC CMD pin + ESP32_BUS_TYPE_SDMMC_D0, // IO is used as SDMMC D0 pin + ESP32_BUS_TYPE_SDMMC_D1, // IO is used as SDMMC D1 pin + ESP32_BUS_TYPE_SDMMC_D2, // IO is used as SDMMC D2 pin + ESP32_BUS_TYPE_SDMMC_D3, // IO is used as SDMMC D3 pin +#if SOC_SDMMC_IO_POWER_EXTERNAL + ESP32_BUS_TYPE_SDMMC_POWER, // IO is used as SDMMC POWER pin +#endif #endif #if SOC_TOUCH_SENSOR_SUPPORTED ESP32_BUS_TYPE_TOUCH, // IO is used as TOUCH pin diff --git a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino index 030caae759c..c374615019a 100644 --- a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino +++ b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino @@ -14,6 +14,7 @@ * Connections for ║ ║ ╔═══╩═║═║═══╗ ║ ║ ║ * full-sized ║ ║ ║ ╔═╝ ║ ║ ║ ║ ║ * SD card ║ ║ ║ ║ ║ ║ ║ ║ ║ + * ESP32-P4 Func EV | 40 39 GND 43 3V3 GND 44 43 42 | * ESP32-S3 DevKit | 21 47 GND 39 3V3 GND 40 41 42 | * ESP32-S3-USB-OTG | 38 37 GND 36 3V3 GND 35 34 33 | * ESP32 | 4 2 GND 14 3V3 GND 15 13 12 | @@ -42,6 +43,7 @@ #include "FS.h" #include "SD_MMC.h" +#ifdef CONFIG_IDF_TARGET_ESP32S3 // Default pins for ESP-S3 // Warning: ESP32-S3-WROOM-2 is using most of the default GPIOs (33-37) to interface with on-board OPI flash. // If the SD_MMC is initialized with default pins it will result in rebooting loop - please @@ -54,6 +56,18 @@ int d0 = 37; int d1 = 38; int d2 = 33; int d3 = 39; // GPIO 34 is not broken-out on ESP32-S3-DevKitC-1 v1.1 +int power = -1; // SDMMC IO power controlled internally + +#elif CONFIG_IDF_TARGET_ESP32P4 +// Pin definition for ESP32-P4 Function EV board V1.4 +int clk = 43; +int cmd = 44; +int d0 = 39; +int d1 = 40; +int d2 = 41; +int d3 = 42; +int power = 4; +#endif void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { Serial.printf("Listing directory: %s\n", dirname); @@ -211,16 +225,17 @@ void testFileIO(fs::FS &fs, const char *path) { void setup() { Serial.begin(115200); /* - // If you want to change the pin assignment on ESP32-S3 uncomment this block and the appropriate + // If you want to change the pin assignment or you get an error that some pins or power pin + // is not assigned on ESP32-S3/ESP32-P4 uncomment this block and the appropriate // line depending if you want to use 1-bit or 4-bit line. - // Please note that ESP32 does not allow pin change and will always fail. - //if(! SD_MMC.setPins(clk, cmd, d0)){ - //if(! SD_MMC.setPins(clk, cmd, d0, d1, d2, d3)){ - Serial.println("Pin change failed!"); - return; - } - */ - + // Please note that ESP32 does not allow pin change and setPins() will always fail. + //if(! SD_MMC.setPins(clk, cmd, d0, power)){ + //if(! SD_MMC.setPins(clk, cmd, d0, d1, d2, d3, power)){ + // Serial.println("Pin change failed!"); + // return; + //} + */ + if (!SD_MMC.begin()) { Serial.println("Card Mount Failed"); return; @@ -262,4 +277,6 @@ void setup() { Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024)); } -void loop() {} +void loop() { + delay(10); + } \ No newline at end of file diff --git a/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino b/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino index bd9f150f3e8..632856a034a 100644 --- a/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino +++ b/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino @@ -14,6 +14,7 @@ * Connections for ║ ║ ╔═══╩═║═║═══╗ ║ ║ ║ * full-sized ║ ║ ║ ╔═╝ ║ ║ ║ ║ ║ * SD card ║ ║ ║ ║ ║ ║ ║ ║ ║ + * ESP32-P4 Func EV | 40 39 GND 43 3V3 GND 44 43 42 | + POWER (4) * ESP32-S3 DevKit | 21 47 GND 39 3V3 GND 40 41 42 | * ESP32-S3-USB-OTG | 38 37 GND 36 3V3 GND 35 34 33 | * ESP32 | 4 2 GND 14 3V3 GND 15 13 12 | diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index 80cb150baa2..f8e8ef8c57e 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -32,6 +32,10 @@ #include "ff.h" #include "esp32-hal-periman.h" +#if SOC_SDMMC_IO_POWER_EXTERNAL +#include "sd_pwr_ctrl_by_on_chip_ldo.h" +#endif + using namespace fs; SDMMCFS::SDMMCFS(FSImplPtr impl) : FS(impl), _card(nullptr) { @@ -77,11 +81,11 @@ bool SDMMCFS::sdmmcDetachBus(void *bus_pointer) { return true; } -bool SDMMCFS::setPins(int clk, int cmd, int d0) { - return setPins(clk, cmd, d0, GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC); +bool SDMMCFS::setPins(int clk, int cmd, int d0, int power) { + return setPins(clk, cmd, d0, GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC, power); } -bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3) { +bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3, int power) { if (_card != nullptr) { log_e("SD_MMC.setPins must be called before SD_MMC.begin"); return false; @@ -94,6 +98,7 @@ bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3) { d1 = digitalPinToGPIONumber(d1); d2 = digitalPinToGPIONumber(d2); d3 = digitalPinToGPIONumber(d3); + power = digitalPinToGPIONumber(power); #ifdef SOC_SDMMC_USE_GPIO_MATRIX // SoC supports SDMMC pin configuration via GPIO matrix. Save the pins for later use in SDMMCFS::begin. @@ -103,6 +108,9 @@ bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3) { _pin_d1 = (int8_t)d1; _pin_d2 = (int8_t)d2; _pin_d3 = (int8_t)d3; +#ifdef SOC_SDMMC_IO_POWER_EXTERNAL + _pin_power = (int8_t)power; +#endif return true; #elif CONFIG_IDF_TARGET_ESP32 // ESP32 doesn't support SDMMC pin configuration via GPIO matrix. @@ -133,6 +141,9 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D2, SDMMCFS::sdmmcDetachBus); perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D3, SDMMCFS::sdmmcDetachBus); } +#ifdef SOC_SDMMC_IO_POWER_EXTERNAL + perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_POWER, SDMMCFS::sdmmcDetachBus); +#endif //mount sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); #ifdef SOC_SDMMC_USE_GPIO_MATRIX @@ -142,6 +153,12 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ log_e("SDMMCFS: some SD pins are not set"); return false; } +#ifdef SOC_SDMMC_IO_POWER_EXTERNAL + if (_pin_power == -1) { + log_e("SDMMCFS: power pin is not set"); + return false; + } +#endif slot_config.clk = (gpio_num_t)_pin_clk; slot_config.cmd = (gpio_num_t)_pin_cmd; @@ -186,6 +203,19 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ } _mode1bit = mode1bit; +#ifdef SOC_SDMMC_IO_POWER_EXTERNAL + sd_pwr_ctrl_ldo_config_t ldo_config = { + .ldo_chan_id = _pin_power, + }; + sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; + + if(sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle) != ESP_OK) { + log_e("Failed to create a new on-chip LDO power control driver"); + return false; + } + host.pwr_ctrl_handle = pwr_ctrl_handle; +#endif + esp_vfs_fat_sdmmc_mount_config_t mount_config = { .format_if_mount_failed = format_if_mount_failed, .max_files = maxOpenFiles, @@ -231,6 +261,11 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ goto err; } } +#ifdef SOC_SDMMC_IO_POWER_EXTERNAL + if (!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_SDMMC_POWER, (void *)(this), -1, -1)) { + goto err; + } +#endif return true; err: diff --git a/libraries/SD_MMC/src/SD_MMC.h b/libraries/SD_MMC/src/SD_MMC.h index a2bc12aed64..a619a6b6e44 100644 --- a/libraries/SD_MMC/src/SD_MMC.h +++ b/libraries/SD_MMC/src/SD_MMC.h @@ -44,13 +44,16 @@ class SDMMCFS : public FS { int8_t _pin_d1 = -1; int8_t _pin_d2 = -1; int8_t _pin_d3 = -1; +#ifdef SOC_SDMMC_IO_POWER_EXTERNAL + int8_t _pin_power = -1; +#endif uint8_t _pdrv = 0xFF; bool _mode1bit = false; public: SDMMCFS(FSImplPtr impl); - bool setPins(int clk, int cmd, int d0); - bool setPins(int clk, int cmd, int d0, int d1, int d2, int d3); + bool setPins(int clk, int cmd, int d0, int power = -1); + bool setPins(int clk, int cmd, int d0, int d1, int d2, int d3, int power = -1); bool begin( const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false, int sdmmc_frequency = BOARD_MAX_SDMMC_FREQ, uint8_t maxOpenFiles = 5 From 5b59ba45c6517d2470cb4cff22d8ae7a1cc0311d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:57:41 +0200 Subject: [PATCH 02/16] fix(board): Remove builtin led --- variants/esp32p4/pins_arduino.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/variants/esp32p4/pins_arduino.h b/variants/esp32p4/pins_arduino.h index 792146f5ca2..957644c966d 100644 --- a/variants/esp32p4/pins_arduino.h +++ b/variants/esp32p4/pins_arduino.h @@ -4,15 +4,6 @@ #include #include "soc/soc_caps.h" -#define PIN_NEOPIXEL 44 -// BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino -static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_NEOPIXEL; -#define BUILTIN_LED LED_BUILTIN // backward compatibility -#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN -// RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API rgbLedWrite() -#define RGB_BUILTIN LED_BUILTIN -#define RGB_BRIGHTNESS 64 - // BOOT_MODE 35 // BOOT_MODE2 36 pullup From e7ae98552aa470da87d0276a4208d196fba2c5fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:59:20 +0200 Subject: [PATCH 03/16] Update libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino Add missing note about power pin for P4 Co-authored-by: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> --- libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino index c374615019a..c012090399c 100644 --- a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino +++ b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino @@ -14,7 +14,7 @@ * Connections for ║ ║ ╔═══╩═║═║═══╗ ║ ║ ║ * full-sized ║ ║ ║ ╔═╝ ║ ║ ║ ║ ║ * SD card ║ ║ ║ ║ ║ ║ ║ ║ ║ - * ESP32-P4 Func EV | 40 39 GND 43 3V3 GND 44 43 42 | + * ESP32-P4 Func EV | 40 39 GND 43 3V3 GND 44 43 42 | + POWER (4) * ESP32-S3 DevKit | 21 47 GND 39 3V3 GND 40 41 42 | * ESP32-S3-USB-OTG | 38 37 GND 36 3V3 GND 35 34 33 | * ESP32 | 4 2 GND 14 3V3 GND 15 13 12 | From dd024ab65828c4fd923fe612c72f4b79500e31cd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Tue, 15 Oct 2024 19:19:52 +0000 Subject: [PATCH 04/16] ci(pre-commit): Apply automatic fixes --- cores/esp32/esp32-hal-periman.h | 14 ++++++------ .../SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino | 8 +++---- libraries/SD_MMC/src/SD_MMC.cpp | 22 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cores/esp32/esp32-hal-periman.h b/cores/esp32/esp32-hal-periman.h index 6c5400cb085..af525265f51 100644 --- a/cores/esp32/esp32-hal-periman.h +++ b/cores/esp32/esp32-hal-periman.h @@ -79,14 +79,14 @@ typedef enum { ESP32_BUS_TYPE_SPI_MASTER_SS, // IO is used as SPI master SS pin #endif #if SOC_SDMMC_HOST_SUPPORTED - ESP32_BUS_TYPE_SDMMC_CLK, // IO is used as SDMMC CLK pin - ESP32_BUS_TYPE_SDMMC_CMD, // IO is used as SDMMC CMD pin - ESP32_BUS_TYPE_SDMMC_D0, // IO is used as SDMMC D0 pin - ESP32_BUS_TYPE_SDMMC_D1, // IO is used as SDMMC D1 pin - ESP32_BUS_TYPE_SDMMC_D2, // IO is used as SDMMC D2 pin - ESP32_BUS_TYPE_SDMMC_D3, // IO is used as SDMMC D3 pin + ESP32_BUS_TYPE_SDMMC_CLK, // IO is used as SDMMC CLK pin + ESP32_BUS_TYPE_SDMMC_CMD, // IO is used as SDMMC CMD pin + ESP32_BUS_TYPE_SDMMC_D0, // IO is used as SDMMC D0 pin + ESP32_BUS_TYPE_SDMMC_D1, // IO is used as SDMMC D1 pin + ESP32_BUS_TYPE_SDMMC_D2, // IO is used as SDMMC D2 pin + ESP32_BUS_TYPE_SDMMC_D3, // IO is used as SDMMC D3 pin #if SOC_SDMMC_IO_POWER_EXTERNAL - ESP32_BUS_TYPE_SDMMC_POWER, // IO is used as SDMMC POWER pin + ESP32_BUS_TYPE_SDMMC_POWER, // IO is used as SDMMC POWER pin #endif #endif #if SOC_TOUCH_SENSOR_SUPPORTED diff --git a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino index c012090399c..96bb818cbd0 100644 --- a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino +++ b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino @@ -55,8 +55,8 @@ int cmd = 35; int d0 = 37; int d1 = 38; int d2 = 33; -int d3 = 39; // GPIO 34 is not broken-out on ESP32-S3-DevKitC-1 v1.1 -int power = -1; // SDMMC IO power controlled internally +int d3 = 39; // GPIO 34 is not broken-out on ESP32-S3-DevKitC-1 v1.1 +int power = -1; // SDMMC IO power controlled internally #elif CONFIG_IDF_TARGET_ESP32P4 // Pin definition for ESP32-P4 Function EV board V1.4 @@ -235,7 +235,7 @@ void setup() { // return; //} */ - + if (!SD_MMC.begin()) { Serial.println("Card Mount Failed"); return; @@ -279,4 +279,4 @@ void setup() { void loop() { delay(10); - } \ No newline at end of file +} diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index f8e8ef8c57e..ad001ea2d44 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -204,16 +204,16 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ _mode1bit = mode1bit; #ifdef SOC_SDMMC_IO_POWER_EXTERNAL - sd_pwr_ctrl_ldo_config_t ldo_config = { - .ldo_chan_id = _pin_power, - }; - sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; - - if(sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle) != ESP_OK) { - log_e("Failed to create a new on-chip LDO power control driver"); - return false; - } - host.pwr_ctrl_handle = pwr_ctrl_handle; + sd_pwr_ctrl_ldo_config_t ldo_config = { + .ldo_chan_id = _pin_power, + }; + sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; + + if (sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle) != ESP_OK) { + log_e("Failed to create a new on-chip LDO power control driver"); + return false; + } + host.pwr_ctrl_handle = pwr_ctrl_handle; #endif esp_vfs_fat_sdmmc_mount_config_t mount_config = { @@ -263,7 +263,7 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ } #ifdef SOC_SDMMC_IO_POWER_EXTERNAL if (!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_SDMMC_POWER, (void *)(this), -1, -1)) { - goto err; + goto err; } #endif return true; From 21d2b13a780a7c8d9f46c00326f6e1405aac4eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:22:09 +0200 Subject: [PATCH 05/16] feat(sdmmc): Option to set power channel --- .../SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino | 16 +-- libraries/SD_MMC/src/SD_MMC.cpp | 109 ++++++++++++------ libraries/SD_MMC/src/SD_MMC.h | 7 +- 3 files changed, 87 insertions(+), 45 deletions(-) diff --git a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino index 96bb818cbd0..4905fdb620a 100644 --- a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino +++ b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino @@ -14,7 +14,7 @@ * Connections for ║ ║ ╔═══╩═║═║═══╗ ║ ║ ║ * full-sized ║ ║ ║ ╔═╝ ║ ║ ║ ║ ║ * SD card ║ ║ ║ ║ ║ ║ ║ ║ ║ - * ESP32-P4 Func EV | 40 39 GND 43 3V3 GND 44 43 42 | + POWER (4) + * ESP32-P4 Func EV | 40 39 GND 43 3V3 GND 44 43 42 | SLOT 0 (IO_MUX) * ESP32-S3 DevKit | 21 47 GND 39 3V3 GND 40 41 42 | * ESP32-S3-USB-OTG | 38 37 GND 36 3V3 GND 35 34 33 | * ESP32 | 4 2 GND 14 3V3 GND 15 13 12 | @@ -55,10 +55,10 @@ int cmd = 35; int d0 = 37; int d1 = 38; int d2 = 33; -int d3 = 39; // GPIO 34 is not broken-out on ESP32-S3-DevKitC-1 v1.1 -int power = -1; // SDMMC IO power controlled internally +int d3 = 39; // GPIO 34 is not broken-out on ESP32-S3-DevKitC-1 v1.1 -#elif CONFIG_IDF_TARGET_ESP32P4 +#elif defined(CONFIG_IDF_TARGET_ESP32P4) && !defined(BOARD_HAS_SDMMC) +// define BOARD_HAS_SDMMC for ESP32-P4 Function EV board V1.4, as it uses SLOT 0 (IO_MUX) // Pin definition for ESP32-P4 Function EV board V1.4 int clk = 43; int cmd = 44; @@ -225,12 +225,12 @@ void testFileIO(fs::FS &fs, const char *path) { void setup() { Serial.begin(115200); /* - // If you want to change the pin assignment or you get an error that some pins or power pin - // is not assigned on ESP32-S3/ESP32-P4 uncomment this block and the appropriate + // If you want to change the pin assignment or you get an error that some pins + // are not assigned on ESP32-S3/ESP32-P4 uncomment this block and the appropriate // line depending if you want to use 1-bit or 4-bit line. // Please note that ESP32 does not allow pin change and setPins() will always fail. - //if(! SD_MMC.setPins(clk, cmd, d0, power)){ - //if(! SD_MMC.setPins(clk, cmd, d0, d1, d2, d3, power)){ + //if(! SD_MMC.setPins(clk, cmd, d0)){ + //if(! SD_MMC.setPins(clk, cmd, d0, d1, d2, d3)){ // Serial.println("Pin change failed!"); // return; //} diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index ad001ea2d44..cb26e7f1d0c 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -39,8 +39,7 @@ using namespace fs; SDMMCFS::SDMMCFS(FSImplPtr impl) : FS(impl), _card(nullptr) { -#if !defined(CONFIG_IDF_TARGET_ESP32P4) -#if defined(SOC_SDMMC_USE_GPIO_MATRIX) && defined(BOARD_HAS_SDMMC) +#if defined(SOC_SDMMC_USE_GPIO_MATRIX) && defined(BOARD_HAS_SDMMC) && !defined(CONFIG_IDF_TARGET_ESP32P4) _pin_clk = SDMMC_CLK; _pin_cmd = SDMMC_CMD; _pin_d0 = SDMMC_D0; @@ -49,9 +48,8 @@ SDMMCFS::SDMMCFS(FSImplPtr impl) : FS(impl), _card(nullptr) { _pin_d2 = SDMMC_D2; _pin_d3 = SDMMC_D3; #endif // BOARD_HAS_1BIT_SDMMC -#endif // !defined(CONFIG_IDF_TARGET_ESP32P4) -#elif SOC_SDMMC_USE_IOMUX && defined(BOARD_HAS_SDMMC) && defined(CONFIG_IDF_TARGET_ESP32) +#elif defined(SOC_SDMMC_USE_IOMUX) && defined(BOARD_HAS_SDMMC) && defined(CONFIG_IDF_TARGET_ESP32) _pin_clk = SDMMC_SLOT1_IOMUX_PIN_NUM_CLK; _pin_cmd = SDMMC_SLOT1_IOMUX_PIN_NUM_CMD; _pin_d0 = SDMMC_SLOT1_IOMUX_PIN_NUM_D0; @@ -61,7 +59,9 @@ SDMMCFS::SDMMCFS(FSImplPtr impl) : FS(impl), _card(nullptr) { _pin_d3 = SDMMC_SLOT1_IOMUX_PIN_NUM_D3; #endif // BOARD_HAS_1BIT_SDMMC -#elif SOC_SDMMC_USE_IOMUX && defined(BOARD_HAS_SDMMC) && defined(CONFIG_IDF_TARGET_ESP32P4) +// ESP32-P4 can use either IOMUX or GPIO matrix +#elif defined(BOARD_HAS_SDMMC) && defined(CONFIG_IDF_TARGET_ESP32P4) +#if defined(BOARD_SDMMC_SLOT) && (BOARD_SDMMC_SLOT == 0) _pin_clk = SDMMC_SLOT0_IOMUX_PIN_NUM_CLK; _pin_cmd = SDMMC_SLOT0_IOMUX_PIN_NUM_CMD; _pin_d0 = SDMMC_SLOT0_IOMUX_PIN_NUM_D0; @@ -70,6 +70,19 @@ SDMMCFS::SDMMCFS(FSImplPtr impl) : FS(impl), _card(nullptr) { _pin_d2 = SDMMC_SLOT0_IOMUX_PIN_NUM_D2; _pin_d3 = SDMMC_SLOT0_IOMUX_PIN_NUM_D3; #endif // BOARD_HAS_1BIT_SDMMC +#else + _pin_clk = SDMMC_CLK; + _pin_cmd = SDMMC_CMD; + _pin_d0 = SDMMC_D0; +#ifndef BOARD_HAS_1BIT_SDMMC + _pin_d1 = SDMMC_D1; + _pin_d2 = SDMMC_D2; + _pin_d3 = SDMMC_D3; +#endif // BOARD_HAS_1BIT_SDMMC +#endif // BOARD_SDMMC_SLOT_NO +#endif +#if defined(SOC_SDMMC_IO_POWER_EXTERNAL) && defined(BOARD_SDMMC_POWER_CHANNEL) + _power_channel = BOARD_SDMMC_POWER_CHANNEL; #endif } @@ -81,11 +94,11 @@ bool SDMMCFS::sdmmcDetachBus(void *bus_pointer) { return true; } -bool SDMMCFS::setPins(int clk, int cmd, int d0, int power) { - return setPins(clk, cmd, d0, GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC, power); +bool SDMMCFS::setPins(int clk, int cmd, int d0) { + return setPins(clk, cmd, d0, GPIO_NUM_NC, GPIO_NUM_NC, GPIO_NUM_NC); } -bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3, int power) { +bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3) { if (_card != nullptr) { log_e("SD_MMC.setPins must be called before SD_MMC.begin"); return false; @@ -98,9 +111,8 @@ bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3, int powe d1 = digitalPinToGPIONumber(d1); d2 = digitalPinToGPIONumber(d2); d3 = digitalPinToGPIONumber(d3); - power = digitalPinToGPIONumber(power); -#ifdef SOC_SDMMC_USE_GPIO_MATRIX +#if defined(SOC_SDMMC_USE_GPIO_MATRIX) && !defined(CONFIG_IDF_TARGET_ESP32P4) // SoC supports SDMMC pin configuration via GPIO matrix. Save the pins for later use in SDMMCFS::begin. _pin_clk = (int8_t)clk; _pin_cmd = (int8_t)cmd; @@ -108,9 +120,6 @@ bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3, int powe _pin_d1 = (int8_t)d1; _pin_d2 = (int8_t)d2; _pin_d3 = (int8_t)d3; -#ifdef SOC_SDMMC_IO_POWER_EXTERNAL - _pin_power = (int8_t)power; -#endif return true; #elif CONFIG_IDF_TARGET_ESP32 // ESP32 doesn't support SDMMC pin configuration via GPIO matrix. @@ -124,11 +133,40 @@ bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3, int powe return false; } return true; +#elif defined(CONFIG_IDF_TARGET_ESP32P4) +#if defined(BOARD_SDMMC_SLOT) && (BOARD_SDMMC_SLOT == 0) + // ESP32-P4 can use either IOMUX or GPIO matrix + bool pins_ok = + (clk == (int)SDMMC_SLOT0_IOMUX_PIN_NUM_CLK) && (cmd == (int)SDMMC_SLOT0_IOMUX_PIN_NUM_CMD) && (d0 == (int)SDMMC_SLOT0_IOMUX_PIN_NUM_D0) + && (((d1 == -1) && (d2 == -1) && (d3 == -1)) || ((d1 == (int)SDMMC_SLOT0_IOMUX_PIN_NUM_D1) && (d2 == (int)SDMMC_SLOT0_IOMUX_PIN_NUM_D2) && (d3 == (int)SDMMC_SLOT0_IOMUX_PIN_NUM_D3))); + if (!pins_ok) { + log_e("SDMMCFS: specified pins are not supported when using IOMUX (SDMMC SLOT 0)."); + return false; + } + return true; +#else + _pin_clk = (int8_t)clk; + _pin_cmd = (int8_t)cmd; + _pin_d0 = (int8_t)d0; + _pin_d1 = (int8_t)d1; + _pin_d2 = (int8_t)d2; + _pin_d3 = (int8_t)d3; + return true; +#endif #else #error SoC not supported #endif } +bool SDMMCFS::setPowerChannel(int power_channel) { + if (_card != nullptr) { + log_e("SD_MMC.setPowerChannel must be called before SD_MMC.begin"); + return false; + } + _power_channel = power_channel; + return true; +} + bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_failed, int sdmmc_frequency, uint8_t maxOpenFiles) { if (_card) { return true; @@ -141,24 +179,16 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D2, SDMMCFS::sdmmcDetachBus); perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_D3, SDMMCFS::sdmmcDetachBus); } -#ifdef SOC_SDMMC_IO_POWER_EXTERNAL - perimanSetBusDeinit(ESP32_BUS_TYPE_SDMMC_POWER, SDMMCFS::sdmmcDetachBus); -#endif //mount sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); -#ifdef SOC_SDMMC_USE_GPIO_MATRIX +#if (defined(SOC_SDMMC_USE_GPIO_MATRIX) && !defined(CONFIG_IDF_TARGET_ESP32P4)) || (defined(CONFIG_IDF_TARGET_ESP32P4) && ((defined(BOARD_SDMMC_SLOT) && (BOARD_SDMMC_SLOT == 1)) || !defined(BOARD_HAS_SDMMC))) + log_d("pin_cmd: %d, pin_clk: %d, pin_d0: %d, pin_d1: %d, pin_d2: %d, pin_d3: %d", _pin_cmd, _pin_clk, _pin_d0, _pin_d1, _pin_d2, _pin_d3); // SoC supports SDMMC pin configuration via GPIO matrix. // Check that the pins have been set either in the constructor or setPins function. if (_pin_cmd == -1 || _pin_clk == -1 || _pin_d0 == -1 || (!mode1bit && (_pin_d1 == -1 || _pin_d2 == -1 || _pin_d3 == -1))) { log_e("SDMMCFS: some SD pins are not set"); return false; } -#ifdef SOC_SDMMC_IO_POWER_EXTERNAL - if (_pin_power == -1) { - log_e("SDMMCFS: power pin is not set"); - return false; - } -#endif slot_config.clk = (gpio_num_t)_pin_clk; slot_config.cmd = (gpio_num_t)_pin_cmd; @@ -192,7 +222,18 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ sdmmc_host_t host = SDMMC_HOST_DEFAULT(); host.flags = SDMMC_HOST_FLAG_4BIT; +#if defined(CONFIG_IDF_TARGET_ESP32P4) && defined(BOARD_SDMMC_SLOT) && (BOARD_SDMMC_SLOT == 0) + host.slot = SDMMC_HOST_SLOT_0; + // reconfigure slot_config to remove all pins in order to use IO_MUX + slot_config = { + .cd = SDMMC_SLOT_NO_CD, + .wp = SDMMC_SLOT_NO_WP, + .width = 4, + .flags = 0, + }; +#else host.slot = SDMMC_HOST_SLOT_1; +#endif host.max_freq_khz = sdmmc_frequency; #ifdef BOARD_HAS_1BIT_SDMMC mode1bit = true; @@ -204,16 +245,16 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ _mode1bit = mode1bit; #ifdef SOC_SDMMC_IO_POWER_EXTERNAL - sd_pwr_ctrl_ldo_config_t ldo_config = { - .ldo_chan_id = _pin_power, - }; - sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; - - if (sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle) != ESP_OK) { - log_e("Failed to create a new on-chip LDO power control driver"); - return false; - } - host.pwr_ctrl_handle = pwr_ctrl_handle; + sd_pwr_ctrl_ldo_config_t ldo_config = { + .ldo_chan_id = _pin_power, + }; + sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; + + if(sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle) != ESP_OK) { + log_e("Failed to create a new on-chip LDO power control driver"); + return false; + } + host.pwr_ctrl_handle = pwr_ctrl_handle; #endif esp_vfs_fat_sdmmc_mount_config_t mount_config = { @@ -263,7 +304,7 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ } #ifdef SOC_SDMMC_IO_POWER_EXTERNAL if (!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_SDMMC_POWER, (void *)(this), -1, -1)) { - goto err; + goto err; } #endif return true; diff --git a/libraries/SD_MMC/src/SD_MMC.h b/libraries/SD_MMC/src/SD_MMC.h index a619a6b6e44..6016853266e 100644 --- a/libraries/SD_MMC/src/SD_MMC.h +++ b/libraries/SD_MMC/src/SD_MMC.h @@ -45,15 +45,16 @@ class SDMMCFS : public FS { int8_t _pin_d2 = -1; int8_t _pin_d3 = -1; #ifdef SOC_SDMMC_IO_POWER_EXTERNAL - int8_t _pin_power = -1; + int8_t _power_channel = -1; #endif uint8_t _pdrv = 0xFF; bool _mode1bit = false; public: SDMMCFS(FSImplPtr impl); - bool setPins(int clk, int cmd, int d0, int power = -1); - bool setPins(int clk, int cmd, int d0, int d1, int d2, int d3, int power = -1); + bool setPins(int clk, int cmd, int d0); + bool setPins(int clk, int cmd, int d0, int d1, int d2, int d3); + bool setPowerChannel(int power_channel); bool begin( const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false, int sdmmc_frequency = BOARD_MAX_SDMMC_FREQ, uint8_t maxOpenFiles = 5 From 41934e57e07c2293838ff18e96f78ab2b468f8a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:25:15 +0200 Subject: [PATCH 06/16] feat(sdmmc): Update pins_arduino.h --- variants/esp32p4/pins_arduino.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/variants/esp32p4/pins_arduino.h b/variants/esp32p4/pins_arduino.h index 957644c966d..c16693292ce 100644 --- a/variants/esp32p4/pins_arduino.h +++ b/variants/esp32p4/pins_arduino.h @@ -49,6 +49,8 @@ static const uint8_t T11 = 13; static const uint8_t T12 = 14; static const uint8_t T13 = 15; +/* ESP32-P4 EV Function board specific definitons */ +//ETH #define ETH_PHY_TYPE ETH_PHY_TLK110 #define ETH_PHY_ADDR 1 #define ETH_PHY_MDC 31 @@ -63,4 +65,19 @@ static const uint8_t T13 = 15; #define ETH_RMII_CLK 50 #define ETH_CLK_MODE EMAC_CLK_EXT_IN +//SDMMC +#define BOARD_HAS_SDMMC +#define BOARD_SDMMC_SLOT 0 +#define BOARD_SDMMC_POWER_CHANNEL 4 + +//WIFI - ESP32C6 +#define BOARD_HAS_SDIO_ESP_HOSTED +#define BOARD_SDIO_ESP_HOSTED_CLK 18 +#define BOARD_SDIO_ESP_HOSTED_CMD 19 +#define BOARD_SDIO_ESP_HOSTED_D0 14 +#define BOARD_SDIO_ESP_HOSTED_D1 15 +#define BOARD_SDIO_ESP_HOSTED_D2 16 +#define BOARD_SDIO_ESP_HOSTED_D3 17 +#define BOARD_SDIO_ESP_HOSTED_RESET 54 + #endif /* Pins_Arduino_h */ From 58b1967d48f4606c79e7bc3dfcfc2995754dd699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:26:24 +0200 Subject: [PATCH 07/16] feat(sdmmc): remove sdmmc power from periman --- cores/esp32/esp32-hal-periman.c | 3 --- cores/esp32/esp32-hal-periman.h | 3 --- 2 files changed, 6 deletions(-) diff --git a/cores/esp32/esp32-hal-periman.c b/cores/esp32/esp32-hal-periman.c index 0225543f7d9..6ef3c3d984a 100644 --- a/cores/esp32/esp32-hal-periman.c +++ b/cores/esp32/esp32-hal-periman.c @@ -87,9 +87,6 @@ const char *perimanGetTypeName(peripheral_bus_type_t type) { case ESP32_BUS_TYPE_SDMMC_D1: return "SDMMC_D1"; case ESP32_BUS_TYPE_SDMMC_D2: return "SDMMC_D2"; case ESP32_BUS_TYPE_SDMMC_D3: return "SDMMC_D3"; -#if SOC_SDMMC_IO_POWER_EXTERNAL - case ESP32_BUS_TYPE_SDMMC_POWER: return "SDMMC_POWER"; -#endif #endif #if SOC_TOUCH_SENSOR_SUPPORTED case ESP32_BUS_TYPE_TOUCH: return "TOUCH"; diff --git a/cores/esp32/esp32-hal-periman.h b/cores/esp32/esp32-hal-periman.h index af525265f51..217d62b8741 100644 --- a/cores/esp32/esp32-hal-periman.h +++ b/cores/esp32/esp32-hal-periman.h @@ -85,9 +85,6 @@ typedef enum { ESP32_BUS_TYPE_SDMMC_D1, // IO is used as SDMMC D1 pin ESP32_BUS_TYPE_SDMMC_D2, // IO is used as SDMMC D2 pin ESP32_BUS_TYPE_SDMMC_D3, // IO is used as SDMMC D3 pin -#if SOC_SDMMC_IO_POWER_EXTERNAL - ESP32_BUS_TYPE_SDMMC_POWER, // IO is used as SDMMC POWER pin -#endif #endif #if SOC_TOUCH_SENSOR_SUPPORTED ESP32_BUS_TYPE_TOUCH, // IO is used as TOUCH pin From e2ffbeefb0b9478522a8f479a6eb3bb621c4390c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:28:55 +0200 Subject: [PATCH 08/16] fix(sdmmc): use corrent variable --- libraries/SD_MMC/src/SD_MMC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index cb26e7f1d0c..ddc549bb412 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -246,7 +246,7 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ #ifdef SOC_SDMMC_IO_POWER_EXTERNAL sd_pwr_ctrl_ldo_config_t ldo_config = { - .ldo_chan_id = _pin_power, + .ldo_chan_id = _power_channel, }; sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; From f533457ddeac6b618dfb107962d03866f3233058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:32:33 +0200 Subject: [PATCH 09/16] fix(sdmmc): Remove periman --- libraries/SD_MMC/src/SD_MMC.cpp | 5 ----- variants/esp32p4/pins_arduino.h | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index ddc549bb412..7ac4fe48314 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -302,11 +302,6 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ goto err; } } -#ifdef SOC_SDMMC_IO_POWER_EXTERNAL - if (!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_SDMMC_POWER, (void *)(this), -1, -1)) { - goto err; - } -#endif return true; err: diff --git a/variants/esp32p4/pins_arduino.h b/variants/esp32p4/pins_arduino.h index c16693292ce..9daeec4e462 100644 --- a/variants/esp32p4/pins_arduino.h +++ b/variants/esp32p4/pins_arduino.h @@ -69,6 +69,7 @@ static const uint8_t T13 = 15; #define BOARD_HAS_SDMMC #define BOARD_SDMMC_SLOT 0 #define BOARD_SDMMC_POWER_CHANNEL 4 +#define BOARD_SDMMC_POWER_PIN 43 //WIFI - ESP32C6 #define BOARD_HAS_SDIO_ESP_HOSTED From a3968f4f29d41480ffbc1bfb039aa3583a6bb6a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:36:29 +0200 Subject: [PATCH 10/16] feat(sdmmc): Toggle power pin if defined --- libraries/SD_MMC/src/SD_MMC.cpp | 6 ++++++ variants/esp32p4/pins_arduino.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index 7ac4fe48314..71c3ddf4672 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -257,6 +257,12 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ host.pwr_ctrl_handle = pwr_ctrl_handle; #endif +#if defined(BOARD_SDMMC_POWER_PIN) + pinMode(BOARD_SDMMC_POWER_PIN, OUTPUT); + digitalWrite(BOARD_SDMMC_POWER_PIN, HIGH); + perimanSetPinBusExtraType(BOARD_SDMMC_POWER_PIN, "SDMMC_POWER"); +#endif + esp_vfs_fat_sdmmc_mount_config_t mount_config = { .format_if_mount_failed = format_if_mount_failed, .max_files = maxOpenFiles, diff --git a/variants/esp32p4/pins_arduino.h b/variants/esp32p4/pins_arduino.h index 9daeec4e462..18b10c853d3 100644 --- a/variants/esp32p4/pins_arduino.h +++ b/variants/esp32p4/pins_arduino.h @@ -69,7 +69,7 @@ static const uint8_t T13 = 15; #define BOARD_HAS_SDMMC #define BOARD_SDMMC_SLOT 0 #define BOARD_SDMMC_POWER_CHANNEL 4 -#define BOARD_SDMMC_POWER_PIN 43 +#define BOARD_SDMMC_POWER_PIN 45 //WIFI - ESP32C6 #define BOARD_HAS_SDIO_ESP_HOSTED From f8d198964f654eb211f64bc99eb9a11adca8dff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:41:42 +0200 Subject: [PATCH 11/16] feat(sdmmc): setPowerChannel available only when supported --- libraries/SD_MMC/src/SD_MMC.cpp | 2 ++ libraries/SD_MMC/src/SD_MMC.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index 71c3ddf4672..1552f3f630a 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -158,6 +158,7 @@ bool SDMMCFS::setPins(int clk, int cmd, int d0, int d1, int d2, int d3) { #endif } +#ifdef SOC_SDMMC_IO_POWER_EXTERNAL bool SDMMCFS::setPowerChannel(int power_channel) { if (_card != nullptr) { log_e("SD_MMC.setPowerChannel must be called before SD_MMC.begin"); @@ -166,6 +167,7 @@ bool SDMMCFS::setPowerChannel(int power_channel) { _power_channel = power_channel; return true; } +#endif bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_failed, int sdmmc_frequency, uint8_t maxOpenFiles) { if (_card) { diff --git a/libraries/SD_MMC/src/SD_MMC.h b/libraries/SD_MMC/src/SD_MMC.h index 6016853266e..b6fe13a0d24 100644 --- a/libraries/SD_MMC/src/SD_MMC.h +++ b/libraries/SD_MMC/src/SD_MMC.h @@ -54,7 +54,9 @@ class SDMMCFS : public FS { SDMMCFS(FSImplPtr impl); bool setPins(int clk, int cmd, int d0); bool setPins(int clk, int cmd, int d0, int d1, int d2, int d3); +#ifdef SOC_SDMMC_IO_POWER_EXTERNAL bool setPowerChannel(int power_channel); +#endif bool begin( const char *mountpoint = "/sdcard", bool mode1bit = false, bool format_if_mount_failed = false, int sdmmc_frequency = BOARD_MAX_SDMMC_FREQ, uint8_t maxOpenFiles = 5 From 96a513fd32d85d7178c85bc25e3bbc9ae8d5ebb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:20:33 +0200 Subject: [PATCH 12/16] feat(sdmmc): Toggle sd power pin for 200ms --- libraries/SD_MMC/src/SD_MMC.cpp | 10 +++++++++- variants/esp32p4/pins_arduino.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index 1552f3f630a..33995b9f299 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -260,8 +260,13 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ #endif #if defined(BOARD_SDMMC_POWER_PIN) +#ifndef BOARD_SDMMC_POWER_ON_LEVEL + #error "BOARD_SDMMC_POWER_ON_LEVEL not defined, please define it in pins_arduino.h" +#endif pinMode(BOARD_SDMMC_POWER_PIN, OUTPUT); - digitalWrite(BOARD_SDMMC_POWER_PIN, HIGH); + digitalWrite(BOARD_SDMMC_POWER_PIN, !BOARD_SDMMC_POWER_ON_LEVEL); + delay(200); + digitalWrite(BOARD_SDMMC_POWER_PIN, BOARD_SDMMC_POWER_ON_LEVEL); perimanSetPinBusExtraType(BOARD_SDMMC_POWER_PIN, "SDMMC_POWER"); #endif @@ -331,6 +336,9 @@ void SDMMCFS::end() { perimanClearPinBus(_pin_d2); perimanClearPinBus(_pin_d3); } + #if defined(BOARD_SDMMC_POWER_PIN) + perimanClearPinBus(BOARD_SDMMC_POWER_PIN); + #endif } } diff --git a/variants/esp32p4/pins_arduino.h b/variants/esp32p4/pins_arduino.h index 18b10c853d3..7554c68d206 100644 --- a/variants/esp32p4/pins_arduino.h +++ b/variants/esp32p4/pins_arduino.h @@ -70,6 +70,7 @@ static const uint8_t T13 = 15; #define BOARD_SDMMC_SLOT 0 #define BOARD_SDMMC_POWER_CHANNEL 4 #define BOARD_SDMMC_POWER_PIN 45 +#define BOARD_SDMMC_POWER_ON_LEVEL LOW //WIFI - ESP32C6 #define BOARD_HAS_SDIO_ESP_HOSTED From 3ff54920b4948df0a641f0663e2ac8f67fd0a467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:48:36 +0200 Subject: [PATCH 13/16] fix(example): Remove p4 pins as they are listed already --- libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino | 11 ----------- libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino index 4905fdb620a..e03f5ceb25e 100644 --- a/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino +++ b/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino @@ -56,17 +56,6 @@ int d0 = 37; int d1 = 38; int d2 = 33; int d3 = 39; // GPIO 34 is not broken-out on ESP32-S3-DevKitC-1 v1.1 - -#elif defined(CONFIG_IDF_TARGET_ESP32P4) && !defined(BOARD_HAS_SDMMC) -// define BOARD_HAS_SDMMC for ESP32-P4 Function EV board V1.4, as it uses SLOT 0 (IO_MUX) -// Pin definition for ESP32-P4 Function EV board V1.4 -int clk = 43; -int cmd = 44; -int d0 = 39; -int d1 = 40; -int d2 = 41; -int d3 = 42; -int power = 4; #endif void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { diff --git a/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino b/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino index 632856a034a..d1e933e4f4b 100644 --- a/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino +++ b/libraries/SD_MMC/examples/SDMMC_time/SDMMC_time.ino @@ -14,7 +14,7 @@ * Connections for ║ ║ ╔═══╩═║═║═══╗ ║ ║ ║ * full-sized ║ ║ ║ ╔═╝ ║ ║ ║ ║ ║ * SD card ║ ║ ║ ║ ║ ║ ║ ║ ║ - * ESP32-P4 Func EV | 40 39 GND 43 3V3 GND 44 43 42 | + POWER (4) + * ESP32-P4 Func EV | 40 39 GND 43 3V3 GND 44 43 42 | SLOT 0 (IO_MUX) * ESP32-S3 DevKit | 21 47 GND 39 3V3 GND 40 41 42 | * ESP32-S3-USB-OTG | 38 37 GND 36 3V3 GND 35 34 33 | * ESP32 | 4 2 GND 14 3V3 GND 15 13 12 | From 773e0a8a7a8482f898ffab31e0cf64d1892f624f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:57:46 +0200 Subject: [PATCH 14/16] feat(sdmmc): Check if power channel is specified --- libraries/SD_MMC/src/SD_MMC.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index 33995b9f299..ace9782a7c8 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -247,6 +247,9 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ _mode1bit = mode1bit; #ifdef SOC_SDMMC_IO_POWER_EXTERNAL + if(_power_channel == -1) { + log_i("On-chip power channel specified, use external power for SDMMC"); + } else { sd_pwr_ctrl_ldo_config_t ldo_config = { .ldo_chan_id = _power_channel, }; @@ -257,6 +260,7 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ return false; } host.pwr_ctrl_handle = pwr_ctrl_handle; + } #endif #if defined(BOARD_SDMMC_POWER_PIN) From f9a5271da16bec44b433a985a921d24468b5f3f5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:28:02 +0000 Subject: [PATCH 15/16] ci(pre-commit): Apply automatic fixes --- libraries/SD_MMC/src/SD_MMC.cpp | 25 +++++++++++++------------ variants/esp32p4/pins_arduino.h | 18 +++++++++--------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/libraries/SD_MMC/src/SD_MMC.cpp b/libraries/SD_MMC/src/SD_MMC.cpp index ace9782a7c8..4a0962ff7e4 100644 --- a/libraries/SD_MMC/src/SD_MMC.cpp +++ b/libraries/SD_MMC/src/SD_MMC.cpp @@ -49,7 +49,7 @@ SDMMCFS::SDMMCFS(FSImplPtr impl) : FS(impl), _card(nullptr) { _pin_d3 = SDMMC_D3; #endif // BOARD_HAS_1BIT_SDMMC -#elif defined(SOC_SDMMC_USE_IOMUX) && defined(BOARD_HAS_SDMMC) && defined(CONFIG_IDF_TARGET_ESP32) +#elif defined(SOC_SDMMC_USE_IOMUX) && defined(BOARD_HAS_SDMMC) && defined(CONFIG_IDF_TARGET_ESP32) _pin_clk = SDMMC_SLOT1_IOMUX_PIN_NUM_CLK; _pin_cmd = SDMMC_SLOT1_IOMUX_PIN_NUM_CMD; _pin_d0 = SDMMC_SLOT1_IOMUX_PIN_NUM_D0; @@ -80,7 +80,7 @@ SDMMCFS::SDMMCFS(FSImplPtr impl) : FS(impl), _card(nullptr) { _pin_d3 = SDMMC_D3; #endif // BOARD_HAS_1BIT_SDMMC #endif // BOARD_SDMMC_SLOT_NO -#endif +#endif #if defined(SOC_SDMMC_IO_POWER_EXTERNAL) && defined(BOARD_SDMMC_POWER_CHANNEL) _power_channel = BOARD_SDMMC_POWER_CHANNEL; #endif @@ -183,8 +183,9 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ } //mount sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); -#if (defined(SOC_SDMMC_USE_GPIO_MATRIX) && !defined(CONFIG_IDF_TARGET_ESP32P4)) || (defined(CONFIG_IDF_TARGET_ESP32P4) && ((defined(BOARD_SDMMC_SLOT) && (BOARD_SDMMC_SLOT == 1)) || !defined(BOARD_HAS_SDMMC))) - log_d("pin_cmd: %d, pin_clk: %d, pin_d0: %d, pin_d1: %d, pin_d2: %d, pin_d3: %d", _pin_cmd, _pin_clk, _pin_d0, _pin_d1, _pin_d2, _pin_d3); +#if (defined(SOC_SDMMC_USE_GPIO_MATRIX) && !defined(CONFIG_IDF_TARGET_ESP32P4)) \ + || (defined(CONFIG_IDF_TARGET_ESP32P4) && ((defined(BOARD_SDMMC_SLOT) && (BOARD_SDMMC_SLOT == 1)) || !defined(BOARD_HAS_SDMMC))) + log_d("pin_cmd: %d, pin_clk: %d, pin_d0: %d, pin_d1: %d, pin_d2: %d, pin_d3: %d", _pin_cmd, _pin_clk, _pin_d0, _pin_d1, _pin_d2, _pin_d3); // SoC supports SDMMC pin configuration via GPIO matrix. // Check that the pins have been set either in the constructor or setPins function. if (_pin_cmd == -1 || _pin_clk == -1 || _pin_d0 == -1 || (!mode1bit && (_pin_d1 == -1 || _pin_d2 == -1 || _pin_d3 == -1))) { @@ -247,17 +248,17 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ _mode1bit = mode1bit; #ifdef SOC_SDMMC_IO_POWER_EXTERNAL - if(_power_channel == -1) { + if (_power_channel == -1) { log_i("On-chip power channel specified, use external power for SDMMC"); } else { sd_pwr_ctrl_ldo_config_t ldo_config = { - .ldo_chan_id = _power_channel, + .ldo_chan_id = _power_channel, }; sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; - if(sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle) != ESP_OK) { - log_e("Failed to create a new on-chip LDO power control driver"); - return false; + if (sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle) != ESP_OK) { + log_e("Failed to create a new on-chip LDO power control driver"); + return false; } host.pwr_ctrl_handle = pwr_ctrl_handle; } @@ -265,7 +266,7 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_ #if defined(BOARD_SDMMC_POWER_PIN) #ifndef BOARD_SDMMC_POWER_ON_LEVEL - #error "BOARD_SDMMC_POWER_ON_LEVEL not defined, please define it in pins_arduino.h" +#error "BOARD_SDMMC_POWER_ON_LEVEL not defined, please define it in pins_arduino.h" #endif pinMode(BOARD_SDMMC_POWER_PIN, OUTPUT); digitalWrite(BOARD_SDMMC_POWER_PIN, !BOARD_SDMMC_POWER_ON_LEVEL); @@ -340,9 +341,9 @@ void SDMMCFS::end() { perimanClearPinBus(_pin_d2); perimanClearPinBus(_pin_d3); } - #if defined(BOARD_SDMMC_POWER_PIN) +#if defined(BOARD_SDMMC_POWER_PIN) perimanClearPinBus(BOARD_SDMMC_POWER_PIN); - #endif +#endif } } diff --git a/variants/esp32p4/pins_arduino.h b/variants/esp32p4/pins_arduino.h index 7554c68d206..5541e001840 100644 --- a/variants/esp32p4/pins_arduino.h +++ b/variants/esp32p4/pins_arduino.h @@ -67,19 +67,19 @@ static const uint8_t T13 = 15; //SDMMC #define BOARD_HAS_SDMMC -#define BOARD_SDMMC_SLOT 0 -#define BOARD_SDMMC_POWER_CHANNEL 4 -#define BOARD_SDMMC_POWER_PIN 45 +#define BOARD_SDMMC_SLOT 0 +#define BOARD_SDMMC_POWER_CHANNEL 4 +#define BOARD_SDMMC_POWER_PIN 45 #define BOARD_SDMMC_POWER_ON_LEVEL LOW //WIFI - ESP32C6 #define BOARD_HAS_SDIO_ESP_HOSTED -#define BOARD_SDIO_ESP_HOSTED_CLK 18 -#define BOARD_SDIO_ESP_HOSTED_CMD 19 -#define BOARD_SDIO_ESP_HOSTED_D0 14 -#define BOARD_SDIO_ESP_HOSTED_D1 15 -#define BOARD_SDIO_ESP_HOSTED_D2 16 -#define BOARD_SDIO_ESP_HOSTED_D3 17 +#define BOARD_SDIO_ESP_HOSTED_CLK 18 +#define BOARD_SDIO_ESP_HOSTED_CMD 19 +#define BOARD_SDIO_ESP_HOSTED_D0 14 +#define BOARD_SDIO_ESP_HOSTED_D1 15 +#define BOARD_SDIO_ESP_HOSTED_D2 16 +#define BOARD_SDIO_ESP_HOSTED_D3 17 #define BOARD_SDIO_ESP_HOSTED_RESET 54 #endif /* Pins_Arduino_h */ From a14824feffb263c41f90950582763731fc1ae8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:42:39 +0200 Subject: [PATCH 16/16] fix(ci): codespell fix --- variants/esp32p4/pins_arduino.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/esp32p4/pins_arduino.h b/variants/esp32p4/pins_arduino.h index 7554c68d206..8f90382d3e6 100644 --- a/variants/esp32p4/pins_arduino.h +++ b/variants/esp32p4/pins_arduino.h @@ -49,7 +49,7 @@ static const uint8_t T11 = 13; static const uint8_t T12 = 14; static const uint8_t T13 = 15; -/* ESP32-P4 EV Function board specific definitons */ +/* ESP32-P4 EV Function board specific definitions */ //ETH #define ETH_PHY_TYPE ETH_PHY_TLK110 #define ETH_PHY_ADDR 1