乐鑫技术交流
直播中

孔朱磊

8年用户 1043经验值
私信 关注
[问答]

ESP32S3无法挂载EMMC芯片怎么处理?

硬件:ESP32-S3-DevKitC-1
环境:ubuntu+vscode
IDF版本:v4.4
问题描述:
我想使用一个8线的mmc芯片作为外部存储,但是当我稍微修改例程后,发现无法挂载文件系统
代码:

  • #include
  • #include
  • #include
  • #include
  • #include "esp_err.h"
  • #include "esp_log.h"
  • #include "esp_vfs_fat.h"
  • #include "driver/sdspi_host.h"
  • #include "driver/spi_common.h"
  • #include "sdmmc_cmd.h"
  • #include "sdkconfig.h"
  • // #include "driver/gpio.h"

  • #include "driver/sdmmc_host.h"

  • static const char *TAG = "SD_EMMC";

  • #define MOUNT_POINT "/sdcard"

  • void MY_emmc_test(void)
  • {

  •     // sdmmc_host_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 = {

  •         .format_if_mount_failed = true,

  •         .max_files = 5,
  •         .allocation_unit_size = 16 * 1024,
  •     };
  •     sdmmc_card_t *card;
  •     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.slot = SDMMC_HOST_SLOT_0;
  •     host.flags = SDMMC_HOST_FLAG_8BIT;

  •     // 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();
  •     // On chips where the GPIOs used for SD card can be configured, set them in
  •     // the slot_config structure:
  •     sdmmc_slot_config_t slot_config =
  •         {
  •             .clk = GPIO_NUM_17,
  •             .cmd = GPIO_NUM_8,
  •             .d0 = GPIO_NUM_14,
  •             .d1 = GPIO_NUM_13,
  •             .d2 = GPIO_NUM_12,
  •             .d3 = GPIO_NUM_11,
  •             .d4 = GPIO_NUM_10,
  •             .d5 = GPIO_NUM_9,
  •             .d6 = GPIO_NUM_46,
  •             .d7 = GPIO_NUM_3,
  •             .cd = SDMMC_SLOT_NO_CD,
  •             .wp = SDMMC_SLOT_NO_WP,
  •             .width = SDMMC_SLOT_WIDTH_DEFAULT,
  •             .flags = 0,
  •         };


  •     //slot_config.RST is GPIO_NUM_18;RST always hign level;
  •     gpio_set_level(GPIO_NUM_18, 1);

  •     // To use 1-line SD mode, change this to 1:
  •     slot_config.width = 8;

  •     // 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;

  •    // sdmmc_host_init_slot(SDMMC_HOST_SLOT_0, &slot_config);
  •     // sdmmc_card_init(&host, &card);
  •     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.");
  •         }
  •         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));
  •         }
  •         return;
  •     }
  •     ESP_LOGI(TAG, "Filesystem mounted");

  •     // Card has been initialized, print its properties
  •     sdmmc_card_print_info(stdout, card);

  •     // Use POSIX and C standard library functions to work with files:

  •     // First create a file.
  •     const char *file_hello = MOUNT_POINT "/hello.txt";

  •     ESP_LOGI(TAG, "Opening file %s", file_hello);
  •     FILE *f = fopen(file_hello, "w");
  •     if (f == NULL)
  •     {
  •         ESP_LOGE(TAG, "Failed to open file for writing");
  •         return;
  •     }
  •     fprintf(f, "Hello %s!n", card->cid.name);
  •     fclose(f);
  •     ESP_LOGI(TAG, "File written");

  •     const char *file_foo = MOUNT_POINT "/foo.txt";

  •     // Check if destination file exists before renaming
  •     struct stat st;
  •     if (stat(file_foo, &st) == 0)
  •     {
  •         // Delete it if it exists
  •         unlink(file_foo);
  •     }

  •     // Rename original file
  •     ESP_LOGI(TAG, "Renaming file %s to %s", file_hello, file_foo);
  •     if (rename(file_hello, file_foo) != 0)
  •     {
  •         ESP_LOGE(TAG, "Rename failed");
  •         return;
  •     }

  •     // Open renamed file for reading
  •     ESP_LOGI(TAG, "Reading file %s", file_foo);
  •     f = fopen(file_foo, "r");
  •     if (f == NULL)
  •     {
  •         ESP_LOGE(TAG, "Failed to open file for reading");
  •         return;
  •     }

  •     // Read a line from file
  •     char line[64;
  •     fgets(line, sizeof(line), f);
  •     fclose(f);

  •     // Strip newline
  •     char *pos = strchr(line, 'n');
  •     if (pos)
  •     {
  •         *pos = '';
  •     }
  •     ESP_LOGI(TAG, "Read from file: '%s'", line);

  •     // All done, unmount partition and disable SDMMC peripheral
  •     esp_vfs_fat_sdcard_unmount(mount_point, card);
  •     ESP_LOGI(TAG, "Card unmounted");
  • }



使用以上代码后串口打印的信息是:Code: [Select all] [Expand/Collapse]

  • I (0) cpu_start: App cpu up.
  • I (222) cpu_start: Pro cpu start user code
  • I (222) cpu_start: cpu freq: 160000000
  • I (222) cpu_start: Application information:
  • I (225) cpu_start: Project name:     main
  • I (230) cpu_start: App version:      3577b0a-dirty
  • I (235) cpu_start: Compile time:     Nov 24 2021 13:39:56
  • I (241) cpu_start: ELF file SHA256:  1ac03af898982e4b...
  • I (247) cpu_start: ESP-IDF:          v4.4-dev-3235-g3e370c4296-dirty
  • I (254) heap_init: Initializing. RAM available for dynamic allocation:
  • I (262) heap_init: At 3FC94B58 len 0004B4A8 (301 KiB): D/IRAM
  • I (268) heap_init: At 3FCE0000 len 0000EE34 (59 KiB): STACK/DRAM
  • I (275) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
  • I (281) spiram: Adding pool of 2048K of external SPI memory to heap allocator
  • I (289) spi_flash: detected chip: generic
  • I (293) spi_flash: flash io: dio
  • I (298) cpu_start: Starting scheduler on PRO CPU.
  • I (0) cpu_start: Starting scheduler on APP CPU.
  • I (328) spiram: Reserving pool of 64K of internal memory for DMA/internal allocations
  • I (328) SD_EMMC: Initializing SD card
  • I (338) SD_EMMC: Using SDMMC peripheral
  • I (338) SD_EMMC: Mounting filesystem
  • I (348) gpio: GPIO[17]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
  • I (358) gpio: GPIO[8]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
  • I (368) gpio: GPIO[14]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
  • I (368) gpio: GPIO[13]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
  • I (378) gpio: GPIO[12]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
  • I (388) gpio: GPIO[11]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
  • I (398) gpio: GPIO[10]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
  • I (408) gpio: GPIO[9]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
  • I (418) gpio: GPIO[46]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
  • I (428) gpio: GPIO[3]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
  • I (498) gpio: GPIO[11]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
  • E (498) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x109
  • E (508) diskio_sdmmc: sdmmc_read_blocks failed (265)
  • W (508) vfs_fat_sdmmc: failed to mount card (1)
  • E (518) vfs_fat_sdmmc: mount_to_vfs failed (0xffffffff).
  • E (518) SD_EMMC: Failed to mount filesystem. If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option.

                                                                                                                                                                                                                                                   

回帖(1)

建立建利12

2024-6-19 16:54:42
要解决ESP32S3无法挂载EMMC芯片的问题,我们可以按照以下步骤进行排查和处理:

1. 确保硬件连接正确:首先检查EMMC芯片与ESP32-S3-DevKitC-1之间的连接是否正确。确保SPI数据线、时钟线、片选线和电源线都已正确连接。

2. 检查电源:确保EMMC芯片的电源电压与ESP32S3兼容。通常,EMMC芯片需要3.3V电源。

3. 检查SPI配置:在代码中,确保SPI配置正确。例如,检查SPI端口、时钟速率、数据位宽等参数是否与EMMC芯片兼容。

4. 初始化SPI:在代码中,确保正确初始化SPI。例如:

```c
spi_bus_config_t bus_cfg = {
    .mosi_io_num = MOSI_PIN,
    .miso_io_num = MISO_PIN,
    .sclk_io_num = SCLK_PIN,
    .quadwp_io_num = -1,
    .quadhd_io_num = -1,
    .max_transfer_sz = 6*1024,
};
ESP_ERROR_CHECK(spi_bus_initialize(host, &bus_cfg, SPI_DMA_CH_AUTO));
```

5. 初始化SDSPI主机:在代码中,确保正确初始化SDSPI主机。例如:

```c
sdspi_device_config_t device_cfg = {
    .host = host,
    .card_detect_pin = CARD_DETECT_PIN,
    .wp_pin = WP_PIN,
    .gpio_cs = CS_PIN,
    .caps = SDMMC_CARD_CAPS_DEFAULT(),
    .slot = HSPI_HOST_SLOT,
};
ESP_ERROR_CHECK(sdspi_host_init_device(&device_cfg));
```

6. 挂载文件系统:在代码中,确保正确挂载文件系统。例如:

```c
static const char *TAG = "example";
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
    .format_if_mount_failed = false,
    .max_files = 5,
    .allocation_unit_size = 16 * 1024
};
esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &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 format_if_mount_failed = true.");
    } else {
        ESP_LOGE(TAG, "Failed to initialize the card (%s). "
                 "Make sure SD card lines have been connected correctly.",
                 esp_err_to_name(ret));
    }
    return;
}
ESP_LOGI(TAG, "Mounted FAT filesystem");
```

7. 检查错误日志:如果以上步骤都正确无误,但问题仍未解决,请查看错误日志,以便找到具体问题所在。

8. 更新ESP-IDF版本:如果问题仍然存在,可以尝试更新ESP-IDF版本到最新版本,以确保兼容性和修复已知问题。

通过以上步骤,应该能够解决ESP32S3无法挂载EMMC芯片的问题。如果问题仍然存在,请提供更多详细信息,以便进一步分析和解决问题。
举报

更多回帖

×
20
完善资料,
赚取积分