Check ERROR when can't mount SD card
Posted: Sun May 01, 2022 3:51 pm
Hi all, I'm working with SD card. When I push SD card in slot, it work fine. I want to LOG some error mess when SD card don't exist. I test this code and the result is my module reboot
Help me with this problem, I need to know when SD card isn't inserted and of course others function still have to work fine
Thanks for your interest
Here my sdcard_mount() func:
And log:
Help me with this problem, I need to know when SD card isn't inserted and of course others function still have to work fine
Thanks for your interest
Here my sdcard_mount() func:
- static void sdcard_mount()
- {
- /*sd_card part code*/
- 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
- };
- sdmmc_card_t* card;
- const char mount_point[] = MOUNT_POINT;
- ESP_LOGI(TAG, "Initializing SD card");
- ESP_LOGI(TAG, "Using SPI peripheral");
- sdmmc_host_t host = SDSPI_HOST_DEFAULT();
- spi_bus_config_t bus_cfg = {
- .mosi_io_num = PIN_NUM_MOSI,
- .miso_io_num = PIN_NUM_MISO,
- .sclk_io_num = PIN_NUM_CLK,
- .quadwp_io_num = -1,
- .quadhd_io_num = -1,
- .max_transfer_sz = 4000,
- };
- esp_err_t ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CHAN);
- if (ret != ESP_OK) {
- ESP_LOGE(TAG, "Failed to initialize bus.");
- // ESP_ERROR_CHECK(ret);
- }
- // 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.
- sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
- slot_config.gpio_cs = PIN_NUM_CS;
- slot_config.host_id = host.slot;
- esp_err_t err = esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config, &card);
- //mount_card = card;
- if(err != ESP_OK){
- if (err == 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(err));
- }
- // ESP_ERROR_CHECK(ret);
- }
- sdmmc_card_print_info(stdout, card);
- ESP_ERROR_CHECK(start_file_server("/sdcard"));
- //vTaskDelete(NULL);
- }
- I (00:00:00.394) MQTT_DAQ: Initializing SD card
- I (00:00:00.394) MQTT_DAQ: Using SPI peripheral
- I (917) wifi:new:<11,0>, old:<1,0>, ap:<255,255>, sta:<11,0>, prof:1
- I (917) wifi:state: init -> auth (b0)
- I (00:00:00.411) gpio: GPIO[14]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
- E (00:00:00.441) vfs_fat_sdmmc: sdmmc_card_init failed (0x107).
- I (00:00:00.441) gpio: GPIO[14]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
- E (00:00:00.447) MQTT_DAQ: Failed to initialize the card (ESP_ERR_TIMEOUT). Make sure SD card lines have pull-up resistors in place.
- I (967) wifi:state: auth -> assoc (0)
- Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
- 0x400d8b7f: gpio_task at d:\sistrain\project\esp_\esp_imm\build/../main/main.c:681
- 0x4008e1f6: vPortTaskWrapper at C:/Espressif/frameworks/esp-idf-v4.4/components/freertos/port/xtensa/port.c:131