Skip to content

Commit 20313f8

Browse files
committed
feat(storage): Update emmc and perf_benchmark example to work with ESP32-P4
1 parent 7154cd3 commit 20313f8

File tree

8 files changed

+103
-44
lines changed

8 files changed

+103
-44
lines changed

examples/storage/.build-test-rules.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ examples/storage/emmc:
1313
- esp_driver_sdmmc
1414
- esp_driver_sdspi
1515
enable:
16-
- if: IDF_TARGET == "esp32s3"
17-
reason: only support on esp32s3
16+
- if: IDF_TARGET in ["esp32s3", "esp32p4"]
17+
reason: only support on esp32s3 and esp32p4
18+
disable_test:
19+
- if: IDF_TARGET == "esp32p4"
20+
temporary: true
21+
reason: lack of runners
1822

1923
examples/storage/partition_api/partition_find:
2024
depends_components:

examples/storage/emmc/README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
| Supported Targets | ESP32-S3 |
2-
| ----------------- | -------- |
1+
| Supported Targets | ESP32-P4 | ESP32-S3 |
2+
| ----------------- | -------- | -------- |
33

44
# eMMC chip example (with SDMMC Host)
55

@@ -22,34 +22,34 @@ This example supports eMMC chips.
2222

2323
## Hardware
2424

25-
This example requires an ESP32-S3 development board and an eMMC chip. Default connections can be found in next chapter. The standard ESP32S3 devkits do not have an eMMC integrated. Considering the signal integrity issues, we suggesting you make your custom PCB board with ESP32-S3 module and an eMMC chip. The signal integrity issues will be more important, when the bus is working under higher speeds. This includes but not limited to increasing the frequency, switching to DDR mode. We will talk a bit more about signal integrity issues in a following chapter.
25+
This example requires an ESP32-S3 or ESP32-P4 development board and an eMMC chip. Default connections can be found in next chapter. Standard devkits do not have an eMMC integrated. Considering the signal integrity issues, we suggesting you make your custom PCB board with an ESP module and an eMMC chip. The signal integrity issues will be more important, when the bus is working under higher speeds. This includes but not limited to increasing the frequency, switching to DDR mode. We will talk a bit more about signal integrity issues in a following chapter.
2626

2727
It is possible to connect an eMMC breakout adapter, but note that cable connections will decrease the signal integrity, leading communication timing violations. When in this condition, you may need to use a lower clock frequency, or switch to SDR mode.
2828

29-
Pull-up resistors is needed. As the SD specification and the eMMC datasheet clarify, minimum 10k pull-up resistors are required for the bus IOs to protect the IOs against bus floating issue. Note these pull-up resistors are needed, even if the pin is not used (For example, you use 1-line-mode, the pull-up resistor is still required for the D1 pin).
29+
Pull-up resistors are needed. As specified in the SD specification and the eMMC datasheet, a minimum of 10k pull-up resistors are required on the bus I/Os to protect against bus floating issues. Note that these pull-up resistors are necessary even if a pin is not used. For example, if you are using 1-line mode, a pull-up resistor is still required on the D1 pin.
3030

3131

32-
### Pin assignments for ESP32-S3
32+
### Pin assignments
3333

34-
On ESP32-S3, SDMMC peripheral is connected to GPIO pins using GPIO matrix. This allows arbitrary GPIOs to be used to connect an SD card. In this example, GPIOs can be configured in two ways:
34+
On ESP32-S3 and ESP32-P4, SDMMC peripheral is connected to GPIO pins using GPIO matrix. This allows arbitrary GPIOs to be used to connect an SD card. In this example, GPIOs can be configured in two ways:
3535

3636
1. Using menuconfig: Run `idf.py menuconfig` in the project directory and open "eMMC Example Configuration" menu.
3737
2. In the source code: See the initialization of ``sdmmc_slot_config_t slot_config`` structure in the example code.
3838

3939
The table below lists the default pin assignments.
4040

41-
ESP32-S3 pin | eMMC pin | Notes
42-
--------------|-------------|------------
43-
GPIO34 | CLK | 10k pullup
44-
GPIO33 | CMD | 10k pullup
45-
GPIO37 | D0 | 10k pullup
46-
GPIO38 | D1 | not used in 1-line mode; but card's D1 pin must have a 10k pullup
47-
GPIO39 | D2 | not used in 1-line mode; but card's D2 pin must have a 10k pullup
48-
GPIO36 | D3 | not used in 1-line mode, but card's D3 pin must have a 10k pullup
49-
GPIO35 | D4 | not used in 1/4-line mode, but card's D4 pin must have a 10k pullup
50-
GPIO40 | D5 | not used in 1/4-line mode, but card's D5 pin must have a 10k pullup
51-
GPIO42 | D6 | not used in 1/4-line mode, but card's D6 pin must have a 10k pullup
52-
GPIO41 | D7 | not used in 1/4-line mode, but card's D7 pin must have a 10k pullup
41+
ESP32-S3 pin | ESP32-P4 pin | eMMC pin | Notes
42+
--------------|----------------|-------------|-------
43+
GPIO34 | GPIO43 | CLK | 10k pullup
44+
GPIO33 | GPIO44 | CMD | 10k pullup
45+
GPIO37 | GPIO39 | D0 | 10k pullup
46+
GPIO38 | GPIO40 | D1 | not used in 1-line mode; but card's D1 pin must have a 10k pullup
47+
GPIO39 | GPIO41 | D2 | not used in 1-line mode; but card's D2 pin must have a 10k pullup
48+
GPIO36 | GPIO42 | D3 | not used in 1-line mode, but card's D3 pin must have a 10k pullup
49+
GPIO35 | GPIO45 | D4 | not used in 1/4-line mode, but card's D4 pin must have a 10k pullup
50+
GPIO40 | GPIO46 | D5 | not used in 1/4-line mode, but card's D5 pin must have a 10k pullup
51+
GPIO42 | GPIO47 | D6 | not used in 1/4-line mode, but card's D6 pin must have a 10k pullup
52+
GPIO41 | GPIO48 | D7 | not used in 1/4-line mode, but card's D7 pin must have a 10k pullup
5353

5454

5555
### Line modes

examples/storage/emmc/main/Kconfig.projbuild

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,34 @@ menu "eMMC Example Configuration"
2828
config EXAMPLE_PIN_CMD
2929
int "CMD GPIO number"
3030
default 33 if IDF_TARGET_ESP32S3
31+
default 44 if IDF_TARGET_ESP32P4
3132

3233
config EXAMPLE_PIN_CLK
3334
int "CLK GPIO number"
3435
default 34 if IDF_TARGET_ESP32S3
36+
default 43 if IDF_TARGET_ESP32P4
3537

3638
config EXAMPLE_PIN_D0
3739
int "D0 GPIO number"
3840
default 37 if IDF_TARGET_ESP32S3
41+
default 39 if IDF_TARGET_ESP32P4
3942

4043
if EXAMPLE_EMMC_BUS_WIDTH_4 || EXAMPLE_EMMC_BUS_WIDTH_8
4144

4245
config EXAMPLE_PIN_D1
4346
int "D1 GPIO number"
4447
default 38 if IDF_TARGET_ESP32S3
48+
default 40 if IDF_TARGET_ESP32P4
4549

4650
config EXAMPLE_PIN_D2
4751
int "D2 GPIO number"
4852
default 39 if IDF_TARGET_ESP32S3
53+
default 41 if IDF_TARGET_ESP32P4
4954

5055
config EXAMPLE_PIN_D3
5156
int "D3 GPIO number"
5257
default 36 if IDF_TARGET_ESP32S3
58+
default 42 if IDF_TARGET_ESP32P4
5359

5460
endif # EXAMPLE_EMMC_BUS_WIDTH_4 || EXAMPLE_EMMC_BUS_WIDTH_8
5561

@@ -58,18 +64,26 @@ menu "eMMC Example Configuration"
5864
config EXAMPLE_PIN_D4
5965
int "D4 GPIO number"
6066
default 35 if IDF_TARGET_ESP32S3
67+
default 45 if IDF_TARGET_ESP32P4
68+
default -1
6169

6270
config EXAMPLE_PIN_D5
6371
int "D5 GPIO number"
6472
default 40 if IDF_TARGET_ESP32S3
73+
default 46 if IDF_TARGET_ESP32P4
74+
default -1
6575

6676
config EXAMPLE_PIN_D6
6777
int "D6 GPIO number"
6878
default 42 if IDF_TARGET_ESP32S3
79+
default 47 if IDF_TARGET_ESP32P4
80+
default -1
6981

7082
config EXAMPLE_PIN_D7
7183
int "D7 GPIO number"
7284
default 41 if IDF_TARGET_ESP32S3
85+
default 48 if IDF_TARGET_ESP32P4
86+
default -1
7387

7488
endif # EXAMPLE_EMMC_BUS_WIDTH_8
7589

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
CONFIG_EXAMPLE_FORMAT_IF_MOUNT_FAILED=y
2+
CONFIG_ESP_TASK_WDT_INIT=n

examples/storage/perf_benchmark/main/Kconfig.projbuild

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ menu "Performance Benchmark Example Configuration"
167167
Otherwise the card may enter SPI mode,
168168
the only way to recover from which is to cycle power to the card.
169169

170+
config EXAMPLE_SDMMC_BUS_WIDTH_8
171+
bool "8 lines (D0 - D7)"
172+
depends on IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32P4
173+
170174
config EXAMPLE_SDMMC_BUS_WIDTH_4
171175
bool "4 lines (D0 - D3)"
172176

@@ -191,7 +195,7 @@ menu "Performance Benchmark Example Configuration"
191195
default 37 if IDF_TARGET_ESP32S3
192196
default 39 if IDF_TARGET_ESP32P4
193197

194-
if EXAMPLE_SDMMC_BUS_WIDTH_4
198+
if EXAMPLE_SDMMC_BUS_WIDTH_4 || EXAMPLE_SDMMC_BUS_WIDTH_8
195199

196200
config EXAMPLE_PIN_D1
197201
int "D1 GPIO number"
@@ -208,7 +212,31 @@ menu "Performance Benchmark Example Configuration"
208212
default 34 if IDF_TARGET_ESP32S3
209213
default 42 if IDF_TARGET_ESP32P4
210214

211-
endif # EXAMPLE_SDMMC_BUS_WIDTH_4
215+
endif # EXAMPLE_SDMMC_BUS_WIDTH_4 || EXAMPLE_SDMMC_BUS_WIDTH_8
216+
217+
if EXAMPLE_SDMMC_BUS_WIDTH_8
218+
219+
config EXAMPLE_PIN_D4
220+
int "D4 GPIO number"
221+
default 35 if IDF_TARGET_ESP32S3
222+
default 45 if IDF_TARGET_ESP32P4
223+
224+
config EXAMPLE_PIN_D5
225+
int "D5 GPIO number"
226+
default 40 if IDF_TARGET_ESP32S3
227+
default 46 if IDF_TARGET_ESP32P4
228+
229+
config EXAMPLE_PIN_D6
230+
int "D6 GPIO number"
231+
default 42 if IDF_TARGET_ESP32S3
232+
default 47 if IDF_TARGET_ESP32P4
233+
234+
config EXAMPLE_PIN_D7
235+
int "D7 GPIO number"
236+
default 41 if IDF_TARGET_ESP32S3
237+
default 48 if IDF_TARGET_ESP32P4
238+
239+
endif # EXAMPLE_SDMMC_BUS_WIDTH_8
212240

213241
endif # SOC_SDMMC_USE_GPIO_MATRIX
214242

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## IDF Component Manager Manifest File
22
dependencies:
3-
joltwallet/littlefs: "~=1.16.0"
3+
joltwallet/littlefs: "~=1.20.0"

examples/storage/perf_benchmark/main/perf_benchmark_example_main.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -22,6 +22,9 @@
2222
#include "esp_vfs_fat.h"
2323
#include "esp_spiffs.h"
2424
#include "wear_levelling.h"
25+
#if SOC_SDMMC_IO_POWER_EXTERNAL
26+
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
27+
#endif
2528

2629
#include "esp_littlefs.h"
2730

@@ -91,6 +94,16 @@ void app_main(void)
9194
test_sd_littlefs();
9295
#endif // CONFIG_EXAMPLE_TEST_SD_CARD_LITTLEFS
9396

97+
// Deinitialize the power control driver if it was used
98+
#if CONFIG_EXAMPLE_SD_PWR_CTRL_LDO_INTERNAL_IO
99+
esp_err_t ret = sd_pwr_ctrl_del_on_chip_ldo(host_g.pwr_ctrl_handle);
100+
if (ret != ESP_OK) {
101+
ESP_LOGE(TAG, "Failed to delete the on-chip LDO power control driver");
102+
ESP_ERROR_CHECK(ret);
103+
}
104+
host_g.pwr_ctrl_handle = NULL;
105+
#endif
106+
94107
#endif // CONFIG_EXAMPLE_TEST_SD_CARD
95108
}
96109

examples/storage/perf_benchmark/main/perf_benchmark_example_sd_utils.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -31,11 +31,11 @@ sdspi_device_config_t slot_config_g;
3131
#endif // CONFIG_EXAMPLE_USE_SDSPI
3232

3333
#ifdef CONFIG_EXAMPLE_USE_SDMMC
34-
void init_sd_config(sdmmc_host_t *out_host, sdmmc_slot_config_t *out_slot_config, int freq_khz) {
34+
void init_sd_config(sdmmc_host_t *out_host, sdmmc_slot_config_t *out_slot_config, int freq_khz)
3535
#else // CONFIG_EXAMPLE_USE_SDMMC
36-
void init_sd_config(sdmmc_host_t *out_host, sdspi_device_config_t *out_slot_config, int freq_khz) {
36+
void init_sd_config(sdmmc_host_t *out_host, sdspi_device_config_t *out_slot_config, int freq_khz)
3737
#endif // CONFIG_EXAMPLE_USE_SDSPI
38-
38+
{
3939
// For SoCs where the SD power can be supplied both via an internal or external (e.g. on-board LDO) power supply.
4040
// When using specific IO pins (which can be used for ultra high-speed SDMMC) to connect to the SD card
4141
// and the internal LDO power supply, we need to initialize the power supply first.
@@ -66,7 +66,9 @@ void init_sd_config(sdmmc_host_t *out_host, sdspi_device_config_t *out_slot_conf
6666
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
6767

6868
// Set bus width to use:
69-
#ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
69+
#ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_8
70+
slot_config.width = 8;
71+
#elif CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
7072
slot_config.width = 4;
7173
#else
7274
slot_config.width = 1;
@@ -78,11 +80,17 @@ void init_sd_config(sdmmc_host_t *out_host, sdspi_device_config_t *out_slot_conf
7880
slot_config.clk = CONFIG_EXAMPLE_PIN_CLK;
7981
slot_config.cmd = CONFIG_EXAMPLE_PIN_CMD;
8082
slot_config.d0 = CONFIG_EXAMPLE_PIN_D0;
81-
#ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
83+
#if CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4 || CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_8
8284
slot_config.d1 = CONFIG_EXAMPLE_PIN_D1;
8385
slot_config.d2 = CONFIG_EXAMPLE_PIN_D2;
8486
slot_config.d3 = CONFIG_EXAMPLE_PIN_D3;
85-
#endif // CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
87+
#endif // CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4 || CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_8
88+
#ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_8
89+
slot_config.d4 = CONFIG_EXAMPLE_PIN_D4;
90+
slot_config.d5 = CONFIG_EXAMPLE_PIN_D5;
91+
slot_config.d6 = CONFIG_EXAMPLE_PIN_D6;
92+
slot_config.d7 = CONFIG_EXAMPLE_PIN_D7;
93+
#endif // CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_8
8694
#endif // CONFIG_SOC_SDMMC_USE_GPIO_MATRIX
8795

8896
// Enable internal pullups on enabled pins. The internal pullups
@@ -120,7 +128,8 @@ void init_sd_config(sdmmc_host_t *out_host, sdspi_device_config_t *out_slot_conf
120128
*out_slot_config = slot_config;
121129
}
122130

123-
esp_err_t init_sd_card(sdmmc_card_t **out_card) {
131+
esp_err_t init_sd_card(sdmmc_card_t **out_card)
132+
{
124133
esp_err_t ret = ESP_OK;
125134
sdmmc_card_t* card = (sdmmc_card_t *)malloc(sizeof(sdmmc_card_t));
126135
if (card == NULL) {
@@ -155,25 +164,15 @@ esp_err_t init_sd_card(sdmmc_card_t **out_card) {
155164
return ret;
156165
}
157166

158-
void deinit_sd_card(sdmmc_card_t **card) {
167+
void deinit_sd_card(sdmmc_card_t **card)
168+
{
159169
// Unmount SD card
160170
#ifdef CONFIG_EXAMPLE_USE_SDMMC
161171
sdmmc_host_deinit();
162172
#else // CONFIG_EXAMPLE_USE_SDMMC
163173
sdspi_host_deinit();
164174
#endif // CONFIG_EXAMPLE_USE_SDSPI
165175

166-
// Deinitialize the power control driver if it was used
167-
#if CONFIG_EXAMPLE_SD_PWR_CTRL_LDO_INTERNAL_IO
168-
sd_pwr_ctrl_handle_t pwr_ctrl_handle = (*card)->host.pwr_ctrl_handle;
169-
esp_err_t ret = sd_pwr_ctrl_del_on_chip_ldo(pwr_ctrl_handle);
170-
if (ret != ESP_OK) {
171-
ESP_LOGE(TAG, "Failed to delete the on-chip LDO power control driver");
172-
ESP_ERROR_CHECK(ret);
173-
}
174-
pwr_ctrl_handle = NULL;
175-
#endif
176-
177176
free(*card);
178177
*card = NULL;
179178
}

0 commit comments

Comments
 (0)