Check ERROR when can't mount SD card

Thanh Quang
Posts: 4
Joined: Sat Nov 27, 2021 2:48 am

Check ERROR when can't mount SD card

Postby Thanh Quang » 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 :D
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:
  1. static void sdcard_mount()
  2. {
  3.     /*sd_card part code*/
  4.     esp_vfs_fat_sdmmc_mount_config_t mount_config = {
  5. //#ifdef CONFIG_EXAMPLE_FORMAT_IF_MOUNT_FAILED
  6.         .format_if_mount_failed = true,
  7. //#else
  8. //        .format_if_mount_failed = false,
  9. //#endif // EXAMPLE_FORMAT_IF_MOUNT_FAILED
  10.         .max_files = 5,
  11.         .allocation_unit_size = 16 * 1024
  12.     };
  13.     sdmmc_card_t* card;
  14.     const char mount_point[] = MOUNT_POINT;
  15.     ESP_LOGI(TAG, "Initializing SD card");
  16.  
  17.     ESP_LOGI(TAG, "Using SPI peripheral");
  18.  
  19.     sdmmc_host_t host = SDSPI_HOST_DEFAULT();
  20.     spi_bus_config_t bus_cfg = {
  21.         .mosi_io_num = PIN_NUM_MOSI,
  22.         .miso_io_num = PIN_NUM_MISO,
  23.         .sclk_io_num = PIN_NUM_CLK,
  24.         .quadwp_io_num = -1,
  25.         .quadhd_io_num = -1,
  26.         .max_transfer_sz = 4000,
  27.     };
  28.  
  29.     esp_err_t ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CHAN);
  30.     if (ret != ESP_OK) {
  31.         ESP_LOGE(TAG, "Failed to initialize bus.");
  32.         // ESP_ERROR_CHECK(ret);
  33.     }
  34.  
  35.     // This initializes the slot without card detect (CD) and write protect (WP) signals.
  36.     // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
  37.     sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
  38.     slot_config.gpio_cs = PIN_NUM_CS;
  39.     slot_config.host_id = host.slot;
  40.     esp_err_t err = esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config, &card);
  41.     //mount_card = card;
  42.  
  43.     if(err != ESP_OK){
  44.         if (err == ESP_FAIL) {
  45.             ESP_LOGE(TAG, "Failed to mount filesystem. "
  46.                 "If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option.");
  47.         } else {
  48.             ESP_LOGE(TAG, "Failed to initialize the card (%s). "
  49.                 "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(err));
  50.         }
  51.         // ESP_ERROR_CHECK(ret);
  52.     }
  53.     sdmmc_card_print_info(stdout, card);
  54.    
  55.     ESP_ERROR_CHECK(start_file_server("/sdcard"));
  56.     //vTaskDelete(NULL);
  57. }
And log:
  1. I (00:00:00.394) MQTT_DAQ: Initializing SD card
  2. I (00:00:00.394) MQTT_DAQ: Using SPI peripheral
  3. I (917) wifi:new:<11,0>, old:<1,0>, ap:<255,255>, sta:<11,0>, prof:1
  4. I (917) wifi:state: init -> auth (b0)
  5. I (00:00:00.411) gpio: GPIO[14]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
  6. E (00:00:00.441) vfs_fat_sdmmc: sdmmc_card_init failed (0x107).
  7. I (00:00:00.441) gpio: GPIO[14]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
  8. 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.
  9. I (967) wifi:state: auth -> assoc (0)
  10. Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
  11.  
  12. 0x400d8b7f: gpio_task at d:\sistrain\project\esp_\esp_imm\build/../main/main.c:681
  13.  
  14. 0x4008e1f6: vPortTaskWrapper at C:/Espressif/frameworks/esp-idf-v4.4/components/freertos/port/xtensa/port.c:131

Who is online

Users browsing this forum: No registered users and 118 guests