I'm testing sd_card example (1-line mode). My hardware is:
GPIO2->D0
GPIO15->CMD
GPIO14->CLK
I have also GPIO12 used for CD (not configured) without 10Kohm pullup but since I use 1-line mode it should not be a problem.D1-D2-D3 of SD card are pullup with 10kohm.
I modified the code as below.
Code: Select all
ESP_LOGI(TAG, "Using SDMMC peripheral");
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
// To use 1-line SD mode, uncomment the following line:
host.flags = SDMMC_HOST_FLAG_1BIT;
// This initializes the slot without card detect (CD) and write protect (WP) signals.
// 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();
//slot_config.gpio_cd = GPIO_NUM_12;
slot_config.width = 1;
// 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(GPIO_NUM_2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
gpio_set_pull_mode(GPIO_NUM_15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
//gpio_set_pull_mode(GPIO_NUM_12, GPIO_PULLUP_ONLY); // CD
#else
ESP_LOGI(TAG, "Using SPI peripheral");
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
slot_config.gpio_miso = PIN_NUM_MISO;
slot_config.gpio_mosi = PIN_NUM_MOSI;
slot_config.gpio_sck = PIN_NUM_CLK;
slot_config.gpio_cs = PIN_NUM_CS;
// This initializes the slot without card detect (CD) and write protect (WP) signals.
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
#endif //USE_SPI_MODE
// Options for mounting the filesystem.
// If format_if_mount_failed is set to true, SD card will be partitioned and
// formatted in case when mounting fails.
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = true,
.max_files = 3,
.allocation_unit_size = 0//16 * 1024
};
// Use settings defined above to initialize SD card and mount FAT filesystem.
// Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
// Please check its source code and implement error recovery when developing
// production applications.
sdmmc_card_t* card;
err = esp_vfs_fat_sdmmc_mount("/S", &host, &slot_config, &mount_config, &card);
ESP_LOGI(TAG, "esp_vfs_fat_sdmmc_mount:%d", err);
if (err != ESP_OK) {
if (err == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount filesystem. "
"If you want the card to be formatted, set format_if_mount_failed = true.");
} else {
ESP_LOGE(TAG, "Failed to initialize the card (%s). "
"Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(err));
}
return;
}
// Card has been initialized, print its properties
sdmmc_card_print_info(stdout, card);
Code: Select all
ESP_LOGI(TAG, "Opening file");
FILE* f = fopen("/S/hello.txt", "w");
if (f != NULL)
{
int ret = fwrite("Test file", 1, strlen("Test file"), f);
fclose(f);
ESP_LOGI(TAG, "File written:%d", ret);
}
Code: Select all
E (290) sdmmc_cmd: sdmmc_write_sectors_dma: sdmmc_send_cmd returned 0x109
E (300) diskio_sdmmc: sdmmc_write_blocks failed (265)
E (300) sdmmc_cmd: sdmmc_write_sectors_dma: sdmmc_send_cmd returned 0x109
E (310) diskio_sdmmc: sdmmc_write_blocks failed (265)
The info reported by "sdmmc_card_print_info(stdout, card)" function are:
Code: Select all
Name: SU02G
Type: SDSC
Speed: default speed
Size: 1886MB
CSD: ver=0, sector_size=512, capacity=3862528 read_bl_len=10
SCR: sd_spec=2, bus_width=5
Thanks.