Skip to content

Commit 28786d0

Browse files
committed
feat(sdmmc): supported UHS-I SDR104 (200 MHz) on ESP32-P4 rev3
1 parent aae5071 commit 28786d0

File tree

8 files changed

+56
-1539
lines changed

8 files changed

+56
-1539
lines changed

components/esp_driver_sdmmc/src/sd_host_sdmmc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ static esp_err_t sd_host_slot_sdmmc_configure(sd_host_slot_handle_t slot, const
217217
if (config->freq_hz == SDMMC_FREQ_SDR104 * 1000) {
218218
unsigned chip_version = efuse_hal_chip_revision();
219219
ESP_LOGD(TAG, "chip_version: %d", chip_version);
220-
if (!ESP_CHIP_REV_ABOVE(chip_version, 200)) {
221-
ESP_RETURN_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, TAG, "UHS-I SDR104 is not supported on ESP32P4 chips prior than v2.0");
220+
if (!ESP_CHIP_REV_ABOVE(chip_version, 300)) {
221+
ESP_RETURN_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, TAG, "UHS-I SDR104 is not supported on ESP32P4 chips prior than v3.0");
222222
}
223223
}
224224
#endif

components/sdmmc/sd_pwr_ctrl/sd_pwr_ctrl_by_on_chip_ldo.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ esp_err_t sd_pwr_ctrl_new_on_chip_ldo(const sd_pwr_ctrl_ldo_config_t *configs, s
3838
ESP_GOTO_ON_FALSE(ctx, ESP_ERR_NO_MEM, err, TAG, "no mem for on-chip ldo control driver context");
3939

4040
esp_ldo_channel_config_t chan_cfg = {
41+
.voltage_mv = 3300,
4142
.chan_id = configs->ldo_chan_id,
4243
.flags.adjustable = true, // the SDMMC power control driver will adjust the voltage later according to different speed mode
4344
};

components/soc/esp32p4/register/hw_ver3/soc/sdmmc_eco5_struct.h

Lines changed: 0 additions & 1457 deletions
This file was deleted.

components/soc/esp32p4/register/hw_ver3/soc/sdmmc_struct.h

Lines changed: 6 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -484,63 +484,6 @@ typedef union {
484484
uint32_t val;
485485
} sdhost_cmd_reg_t;
486486

487-
488-
/** Group: Response data register */
489-
/** Type of resp0 register
490-
* Response data register
491-
*/
492-
typedef union {
493-
struct {
494-
/** response0_reg : RO; bitpos: [31:0]; default: 0;
495-
* Bit[31:0] of response.
496-
*/
497-
uint32_t response0_reg:32;
498-
};
499-
uint32_t val;
500-
} sdhost_resp0_reg_t;
501-
502-
503-
/** Group: Long response data register */
504-
/** Type of resp1 register
505-
* Long response data register
506-
*/
507-
typedef union {
508-
struct {
509-
/** response1_reg : RO; bitpos: [31:0]; default: 0;
510-
* Bit[63:32] of long response.
511-
*/
512-
uint32_t response1_reg:32;
513-
};
514-
uint32_t val;
515-
} sdhost_resp1_reg_t;
516-
517-
/** Type of resp2 register
518-
* Long response data register
519-
*/
520-
typedef union {
521-
struct {
522-
/** response2_reg : RO; bitpos: [31:0]; default: 0;
523-
* Bit[95:64] of long response.
524-
*/
525-
uint32_t response2_reg:32;
526-
};
527-
uint32_t val;
528-
} sdhost_resp2_reg_t;
529-
530-
/** Type of resp3 register
531-
* Long response data register
532-
*/
533-
typedef union {
534-
struct {
535-
/** response3_reg : RO; bitpos: [31:0]; default: 0;
536-
* Bit[127:96] of long response.
537-
*/
538-
uint32_t response3_reg:32;
539-
};
540-
uint32_t val;
541-
} sdhost_resp3_reg_t;
542-
543-
544487
/** Group: Masked interrupt status register */
545488
/** Type of mintsts register
546489
* Masked interrupt status register
@@ -606,22 +549,7 @@ typedef union {
606549
* Bit 1 (RE): Response error;
607550
* Bit 0 (CD): Card detect.
608551
*/
609-
uint32_t cd:1;
610-
uint32_t re:1;
611-
uint32_t cmd_done:1;
612-
uint32_t dto:1;
613-
uint32_t txdr:1;
614-
uint32_t rxdr:1;
615-
uint32_t rcrc:1;
616-
uint32_t dcrc:1;
617-
uint32_t rto:1;
618-
uint32_t drto:1;
619-
uint32_t hto:1;
620-
uint32_t frun:1;
621-
uint32_t hle:1;
622-
uint32_t sbi_bci:1;
623-
uint32_t acd:1;
624-
uint32_t ebe:1;
552+
uint32_t int_status_raw:16;
625553
/** sdio_interrupt_raw : R/W; bitpos: [17:16]; default: 0;
626554
* Interrupt from SDIO card, one bit for each card. Bit[17:16] correspond to card1 and
627555
* card0, respectively. Setting a bit clears the corresponding interrupt bit and
@@ -920,10 +848,10 @@ typedef union {
920848
*/
921849
uint32_t volt:2;
922850
uint32_t reserved_0:14;
923-
/** ddr: R/W; bitpos: [17:16]; default: 0;
924-
* DDR mode selection, 1 bit for each card.
925-
* 0: Non-DDR mode.
926-
* 1: DDR mode.
851+
/** ddr : R/W; bitpos: [17:16]; default: 0;
852+
* DDR mode selection,1 bit for each card.
853+
* 0-Non-DDR mode.
854+
* 1-DDR mode.
927855
*/
928856
uint32_t ddr:2;
929857
uint32_t reserved_18:14;
@@ -1444,7 +1372,7 @@ typedef struct sdmmc_dev_t {
14441372
volatile sdhost_intmask_reg_t intmask;
14451373
volatile uint32_t cmdarg;
14461374
volatile sdhost_cmd_reg_t cmd;
1447-
volatile uint32_t resp[4]; ///< Response from card
1375+
volatile uint32_t resp[4];
14481376
volatile sdhost_mintsts_reg_t mintsts;
14491377
volatile sdhost_rintsts_reg_t rintsts;
14501378
volatile sdhost_status_reg_t status;

docs/en/api-reference/peripherals/sdmmc_host.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Overview
7474
.. only:: esp32p4
7575

7676
- :c:macro:`SDMMC_HOST_SLOT_1` is routed via GPIO Matrix. This means that any GPIO may be used for each of the SD card signals. It is for non UHS-I usage.
77-
- :c:macro:`SDMMC_HOST_SLOT_0` is dedicated to UHS-I mode, which is not yet supported in the driver.
77+
- :c:macro:`SDMMC_HOST_SLOT_0` is dedicated to UHS-I mode.
7878

7979
On {IDF_TARGET_NAME}, SDMMC host requires an external power supply for the IO voltage. Please refer to :ref:`pwr-ctrl` for details.
8080

@@ -87,6 +87,7 @@ SDMMC Host driver supports the following speed modes:
8787

8888
- Default Speed (20 MHz): 1-line or 4-line with SD cards, and 1-line, 4-line, or 8-line with 3.3 V eMMC
8989
- High Speed (40 MHz): 1-line or 4-line with SD cards, and 1-line, 4-line, or 8-line with 3.3 V eMMC
90+
:SOC_SDMMC_UHS_I_SUPPORTED: - UHS-I 1.8 V, SDR104 (200 MHz): 4-line with SD cards
9091
:SOC_SDMMC_UHS_I_SUPPORTED: - UHS-I 1.8 V, SDR50 (100 MHz): 4-line with SD cards
9192
:SOC_SDMMC_UHS_I_SUPPORTED: - UHS-I 1.8 V, DDR50 (50 MHz): 4-line with SD cards
9293
- High Speed DDR (40 MHz): 4-line with 3.3 V eMMC

docs/zh_CN/api-reference/peripherals/sdmmc_host.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ SDMMC 主机驱动
7474
.. only:: esp32p4
7575

7676
- 卡槽 :c:macro:`SDMMC_HOST_SLOT_1` 通过 GPIO 交换矩阵路由,即任何 GPIO 都可以用于每个 SD 卡信号。这适用于非 UHS-I 用途。
77-
- 卡槽 :c:macro:`SDMMC_HOST_SLOT_0` 专用于 UHS-I 模式,驱动程序中尚不支持该模式
77+
- 卡槽 :c:macro:`SDMMC_HOST_SLOT_0` 专用于 UHS-I 模式。
7878

7979
在 {IDF_TARGET_NAME} 上,SDMMC 主机需要外部电源为 IO 电压供电。详情请参阅 :ref:`pwr-ctrl`。
8080

@@ -87,6 +87,7 @@ SDMMC 主机驱动支持以下速率模式:
8787

8888
- 默认速率 (20 MHz):对于 SD 卡,支持 1 线或 4 线传输;对于 3.3 V eMMC,支持 1 线、4 线或 8 线传输。
8989
- 高速模式 (40 MHz):对于 SD 卡,支持 1 线或 4 线传输;对于 3.3 V eMMC,支持 1 线、4 线或 8 线传输。
90+
:SOC_SDMMC_UHS_I_SUPPORTED: - UHS-I 1.8 V, SDR104 模式 (200 MHz):支持 4 线 SD 卡传输。
9091
:SOC_SDMMC_UHS_I_SUPPORTED: - UHS-I 1.8 V SDR50 模式 (100 MHz):支持 4 线 SD 卡传输。
9192
:SOC_SDMMC_UHS_I_SUPPORTED: - UHS-I 1.8 V DDR50 模式 (50 MHz):支持 4 线 SD 卡传输。
9293
- 高速 DDR 模式 (40 MHz):对于 3.3 V eMMC,支持 4 线传输。

examples/storage/sd_card/sdmmc/main/Kconfig.projbuild

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ menu "SD/MMC Example Configuration"
4747
depends on SOC_SDMMC_UHS_I_SUPPORTED
4848
endchoice
4949

50+
config EXAMPLE_PIN_CARD_POWER_RESET
51+
int
52+
depends on SOC_SDMMC_IO_POWER_EXTERNAL
53+
prompt "Card Power Reset"
54+
default 45
55+
5056
config EXAMPLE_PIN_CMD
5157
int
5258
prompt "CMD GPIO number" if SOC_SDMMC_USE_GPIO_MATRIX

examples/storage/sd_card/sdmmc/main/sd_card_example_main.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "esp_vfs_fat.h"
1515
#include "sdmmc_cmd.h"
1616
#include "driver/sdmmc_host.h"
17+
#include "driver/gpio.h"
1718
#include "sd_test_io.h"
1819
#if SOC_SDMMC_IO_POWER_EXTERNAL
1920
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
@@ -98,6 +99,38 @@ static esp_err_t s_example_read_file(const char *path)
9899
return ESP_OK;
99100
}
100101

102+
#if CONFIG_EXAMPLE_PIN_CARD_POWER_RESET
103+
static esp_err_t s_example_reset_card_power(void)
104+
{
105+
esp_err_t ret = ESP_FAIL;
106+
gpio_config_t io_conf = {
107+
.mode = GPIO_MODE_OUTPUT,
108+
.pin_bit_mask = (1ULL<<CONFIG_EXAMPLE_PIN_CARD_POWER_RESET),
109+
};
110+
ret = gpio_config(&io_conf);
111+
if (ret != ESP_OK) {
112+
ESP_LOGE(TAG, "Failed to config GPIO");
113+
return ret;
114+
}
115+
116+
ret = gpio_set_level(CONFIG_EXAMPLE_PIN_CARD_POWER_RESET, 1);
117+
if (ret != ESP_OK) {
118+
ESP_LOGE(TAG, "Failed to set GPIO level");
119+
return ret;
120+
}
121+
122+
vTaskDelay(100 / portTICK_PERIOD_MS);
123+
124+
ret = gpio_set_level(CONFIG_EXAMPLE_PIN_CARD_POWER_RESET, 0);
125+
if (ret != ESP_OK) {
126+
ESP_LOGE(TAG, "Failed to set GPIO level");
127+
return ret;
128+
}
129+
130+
return ESP_OK;
131+
}
132+
#endif // CONFIG_EXAMPLE_PIN_CARD_POWER_RESET
133+
101134
void app_main(void)
102135
{
103136
esp_err_t ret;
@@ -161,6 +194,10 @@ void app_main(void)
161194
host.pwr_ctrl_handle = pwr_ctrl_handle;
162195
#endif
163196

197+
#if CONFIG_EXAMPLE_PIN_CARD_POWER_RESET
198+
ESP_ERROR_CHECK(s_example_reset_card_power());
199+
#endif
200+
164201
// This initializes the slot without card detect (CD) and write protect (WP) signals.
165202
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
166203
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();

0 commit comments

Comments
 (0)