When I tested example project of SD CARD, it is totally fine.
However, I failed to compile with thoese erros.
I also included thoes files
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"
ESP-IDF: v4.4.3
Code: Select all
/main/sdcard.c:72:25: error: invalid initializer
main/sdcard.c:77:5: error: unknown type name 'sdmmc_slot_config_t'; did you mean 'sdspi_slot_config_t'?
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
^~~~~~~~~~~~~~~~~~~
sdspi_slot_config_t
main/sdcard.c:77:39: error: implicit declaration of function 'SDMMC_SLOT_CONFIG_DEFAULT'; did you mean 'SDSPI_SLOT_CONFIG_DEFAULT'? [-Werror=implicit-function-declaration]
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
^~~~~~~~~~~~~~~~~~~~~~~~~
SDSPI_SLOT_CONFIG_DEFAULT
main/sdcard.c:81:16: error: request for member 'width' in something not a structure or union
slot_config.width = 4;
^
main/sdcard.c:88:39: warning: extra tokens at end of #ifdef directive
#ifdef CONFIG_SOC_SDMMC_USE_GPIO_MATR IX
^~
main/sdcard.c:102:16: error: request for member 'flags' in something not a structure or union
slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
^
main/sdcard.c:102:26: error: 'SDMMC_SLOT_FLAG_INTERNAL_PULLUP' undeclared (first use in this function); did you mean 'SDMMC_HOST_FLAG_DEINIT_ARG'?
slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SDMMC_HOST_FLAG_DEINIT_ARG
Code: Select all
void sdcard_init()
{
esp_err_t ret;
// 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 = {
#ifdef CONFIG_EXAMPLE_FORMAT_IF_MOUNT_FAILED
.format_if_mount_failed = true,
#else
.format_if_mount_failed = false,
#endif // EXAMPLE_FORMAT_IF_MOUNT_FAILED
.max_files = 5,
.allocation_unit_size = 16 * 1024};
const char mount_point[] = MOUNT_POINT;
ESP_LOGI(TAG, "Initializing SD card");
// Use settings defined above to initialize SD card and mount FAT filesystem.
// Note: esp_vfs_fat_sdmmc/sdspi_mount is all-in-one convenience functions.
// Please check its source code and implement error recovery when developing
// production applications.
ESP_LOGI(TAG, "Using SDMMC peripheral");
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
host.max_freq_khz = SDMMC_FREQ_PROBING;
// 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();
// Set bus width to use:
#ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
slot_config.width = 4;
#else
slot_config.width = 1;
#endif
// On chips where the GPIOs used for SD card can be configured, set them in
// the slot_config structure:
#ifdef CONFIG_SOC_SDMMC_USE_GPIO_MATR IX
slot_config.clk = CONFIG_EXAMPLE_PIN_CLK;
slot_config.cmd = CONFIG_EXAMPLE_PIN_CMD;
slot_config.d0 = CONFIG_EXAMPLE_PIN_D0;
#ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
slot_config.d1 = CONFIG_EXAMPLE_PIN_D1;
slot_config.d2 = CONFIG_EXAMPLE_PIN_D2;
slot_config.d3 = CONFIG_EXAMPLE_PIN_D3;
#endif // CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4
#endif // CONFIG_SOC_SDMMC_USE_GPIO_MATRIX
// 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;
ESP_LOGI(TAG, "Mounting filesystem");
ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK)
{
if (ret == ESP_FAIL)
{
ESP_LOGE(TAG, "Failed to mount filesystem. "
"If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option.");
setSdCardStatus(false);
}
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(ret));
setSdCardStatus(false);
}
return;
}
ESP_LOGI(TAG, "Filesystem mounted");
setSdCardStatus(true);
// Card has been initialized, print its properties
sdmmc_card_print_info(stdout, card);
}