Skip to content

Commit dc0f7e6

Browse files
committed
feat(usb_wireless_disk): support 4bit sdcard
1 parent 38107bc commit dc0f7e6

File tree

2 files changed

+66
-15
lines changed

2 files changed

+66
-15
lines changed

examples/usb/device/usb_msc_wireless_disk/main/Kconfig.projbuild

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ menu "USB MSC Device Demo"
22

33
choice DEVELOPMENT_BOARD_SELECTION
44
prompt "Select the development board you are using"
5-
default ESP32_S3_USB_OTG if IDF_TARGET_ESP32S3
5+
default ESP32_S3_GENERIC if IDF_TARGET_ESP32S3
66
default ESP32_S2_GENERIC if IDF_TARGET_ESP32S2
77
help
88
Select this option to choose the board for the example.
@@ -46,44 +46,83 @@ menu "USB MSC Device Demo"
4646
config DISK_BLOCK_SIZE
4747
int "disk block size used for format"
4848
depends on USE_EXTERNAL_SDCARD
49-
default 512
49+
default 8192
5050

5151
menu "SD Card PIN CONFIG"
5252

5353
config SDCARD_SPI_CS_PIN
5454
int "SD Card SPI CS pin"
5555
depends on SDCARD_INTFC_SPI
56-
default 34
56+
default 34 if ESP32_S3_USB_OTG
57+
default 10
5758

5859
config SDCARD_SPI_CLK_PIN
5960
int "SD Card SPI CLK pin"
6061
depends on SDCARD_INTFC_SPI
61-
default 36
62+
default 36 if ESP32_S3_USB_OTG
63+
default 12
6264

6365
config SDCARD_SPI_DI_PIN
6466
int "SD Card SPI DI pin"
6567
depends on SDCARD_INTFC_SPI
66-
default 35
68+
default 35 if ESP32_S3_USB_OTG
69+
default 11
6770

6871
config SDCARD_SPI_DO_PIN
6972
int "SD Card SPI DO pin"
7073
depends on SDCARD_INTFC_SPI
71-
default 37
74+
default 37 if ESP32_S3_USB_OTG
75+
default 13
7276

73-
config SDCARD_SDIO_DO_PIN
74-
int "SD Card SDIO DO pin"
77+
config SDCARD_SDIO_D0_PIN
78+
int "SD Card SDIO D0 pin"
7579
depends on SDCARD_INTFC_SDIO
76-
default 37
80+
default 37 if ESP32_S3_USB_OTG
81+
default 13
7782

7883
config SDCARD_SDIO_CMD_PIN
7984
int "SD Card SDIO CMD pin"
8085
depends on SDCARD_INTFC_SDIO
81-
default 35
86+
default 35 if ESP32_S3_USB_OTG
87+
default 11
8288

8389
config SDCARD_SDIO_CLK_PIN
8490
int "SD Card SDIO CLK pin"
8591
depends on SDCARD_INTFC_SDIO
86-
default 36
92+
default 36 if ESP32_S3_USB_OTG
93+
default 12
94+
95+
choice SDCARD_SDIO_DATA_WIDTH
96+
prompt "SDIO Data Width"
97+
depends on SDCARD_INTFC_SDIO
98+
default SDCARD_SDIO_DATA_WIDTH_1
99+
help
100+
Select SDIO bus width: 1-line or 4-line.
101+
102+
config SDCARD_SDIO_DATA_WIDTH_1
103+
bool "1-line mode"
104+
105+
config SDCARD_SDIO_DATA_WIDTH_4
106+
bool "4-line mode"
107+
endchoice
108+
109+
config SDCARD_SDIO_D1_PIN
110+
int "SD Card SDIO D1 pin (for 4-line)"
111+
depends on SDCARD_INTFC_SDIO && SDCARD_SDIO_DATA_WIDTH_4
112+
default 38 if ESP32_S3_USB_OTG
113+
default 14
114+
115+
config SDCARD_SDIO_D2_PIN
116+
int "SD Card SDIO D2 pin (for 4-line)"
117+
depends on SDCARD_INTFC_SDIO && SDCARD_SDIO_DATA_WIDTH_4
118+
default 33 if ESP32_S3_USB_OTG
119+
default 9
120+
121+
config SDCARD_SDIO_D3_PIN
122+
int "SD Card SDIO D3 pin (for 4-line)"
123+
depends on SDCARD_INTFC_SDIO && SDCARD_SDIO_DATA_WIDTH_4
124+
default 34 if ESP32_S3_USB_OTG
125+
default 10
87126
endmenu
88127
endchoice
89128

examples/usb/device/usb_msc_wireless_disk/main/app_main.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ static const char *TAG = "usb_msc_wireless";
2828
#elif defined(CONFIG_SDCARD_INTFC_SDIO) && defined(SOC_SDMMC_HOST_SUPPORTED)
2929
#define SDCARD_SDIO_CLK_PIN CONFIG_SDCARD_SDIO_CLK_PIN
3030
#define SDCARD_SDIO_CMD_PIN CONFIG_SDCARD_SDIO_CMD_PIN
31-
#define SDCARD_SDIO_DO_PIN CONFIG_SDCARD_SDIO_DO_PIN
31+
#define SDCARD_SDIO_D0_PIN CONFIG_SDCARD_SDIO_D0_PIN
32+
#if CONFIG_SDCARD_SDIO_DATA_WIDTH_4
33+
#define SDCARD_SDIO_DATA_WIDTH 4
34+
#define SDCARD_SDIO_D1_PIN CONFIG_SDCARD_SDIO_D1_PIN
35+
#define SDCARD_SDIO_D2_PIN CONFIG_SDCARD_SDIO_D2_PIN
36+
#define SDCARD_SDIO_D3_PIN CONFIG_SDCARD_SDIO_D3_PIN
37+
#else
3238
#define SDCARD_SDIO_DATA_WIDTH 1
39+
#endif
3340
#include "driver/sdmmc_host.h"
3441
#else
3542
#error "Not supported interface"
@@ -53,7 +60,7 @@ static esp_err_t init_fat(sdmmc_card_t **card_handle, const char *base_path)
5360
ESP_LOGI(TAG, "using internal flash");
5461
const esp_vfs_fat_mount_config_t mount_config = {
5562
.format_if_mount_failed = true,
56-
.max_files = 9,
63+
.max_files = 5,
5764
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE
5865
};
5966
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
@@ -102,15 +109,20 @@ static esp_err_t init_fat(sdmmc_card_t **card_handle, const char *base_path)
102109
#elif defined(CONFIG_SDCARD_INTFC_SDIO) && defined(SOC_SDMMC_HOST_SUPPORTED)
103110
ESP_LOGI(TAG, "Using SDIO Interface");
104111
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
112+
host.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
105113

106114
// This initializes the slot without card detect (CD) and write protect (WP) signals.
107115
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
108116
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
109117
slot_config.clk = SDCARD_SDIO_CLK_PIN;
110118
slot_config.cmd = SDCARD_SDIO_CMD_PIN;
111-
slot_config.d0 = SDCARD_SDIO_DO_PIN;
112-
// To use 1-line SD mode, change this to 1:
119+
slot_config.d0 = SDCARD_SDIO_D0_PIN;
113120
slot_config.width = SDCARD_SDIO_DATA_WIDTH;
121+
#if CONFIG_SDCARD_SDIO_DATA_WIDTH_4
122+
slot_config.d1 = SDCARD_SDIO_D1_PIN;
123+
slot_config.d2 = SDCARD_SDIO_D2_PIN;
124+
slot_config.d3 = SDCARD_SDIO_D3_PIN;
125+
#endif
114126
// Enable internal pullup on enabled pins. The internal pullup
115127
// are insufficient however, please make sure 10k external pullup are
116128
// connected on the bus. This is for debug / example purpose only.

0 commit comments

Comments
 (0)