examples: sdmmc: set slot width and pins explicitly

... and prefer SDMMC_SLOT_FLAG_INTERNAL_PULLUP over explicitly setting
pullups on pins.
This commit is contained in:
Ivan Grokhotkov 2021-05-06 08:48:21 +02:00
parent 2c8f413059
commit 47685f901d

View File

@ -52,17 +52,24 @@ void app_main(void)
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
// To use 1-line SD mode, uncomment the following line:
// slot_config.width = 1;
// To use 1-line SD mode, change this to 1:
slot_config.width = 4;
// GPIOs 15, 2, 4, 12, 13 should have external 10k pull-ups.
// Internal pull-ups are not sufficient. However, enabling internal pull-ups
// does make a difference some boards, so we do that here.
gpio_set_pull_mode(15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
gpio_set_pull_mode(2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
gpio_set_pull_mode(4, GPIO_PULLUP_ONLY); // D1, needed in 4-line mode only
gpio_set_pull_mode(12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only
gpio_set_pull_mode(13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes
// On chips where the GPIOs used for SD card can be configured, set them in
// the slot_config structure:
#ifdef SOC_SDMMC_USE_GPIO_MATRIX
slot_config.clk = GPIO_NUM_14;
slot_config.cmd = GPIO_NUM_15;
slot_config.d0 = GPIO_NUM_2;
slot_config.d1 = GPIO_NUM_4;
slot_config.d2 = GPIO_NUM_12;
slot_config.d3 = GPIO_NUM_13;
#endif
// Enable internal pullups on enabled pins. The internal pullups
// are insufficient however, please make sure 10k external pullups are
// connected on the bus. This is for debug / example purpose only.
slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);