MicroSD SPI mode mount fails after some 10 hours in ESP32S2

vigyanabikshu
Posts: 4
Joined: Mon Apr 12, 2021 4:30 pm

MicroSD SPI mode mount fails after some 10 hours in ESP32S2

Postby vigyanabikshu » Sat Feb 05, 2022 4:50 pm

SDCard mount fails after some 10 hours. Reinsert SDCard works again without any problem. Below is my mount code. Will be a problem of SDCard holder rust ?

ESP32S2 pins used: IO10, IO11, IO12, IO13 . internal pullup enabled

Code: Select all

// Mount SD Card
int SD_Mount(){
  GPIO_SetDigitalIn(PIN_NUM_MOSI);
  
  esp_err_t ret;
  esp_vfs_fat_sdmmc_mount_config_t mount_config = {
    .format_if_mount_failed = true,
    .max_files = 5,
    .allocation_unit_size = 16 * 1024
  };
  ESP_LOGI(TAG, "Initializing SD card");
  ESP_LOGI(TAG, "Using SPI peripheral");
  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,
  };
  ret = spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CHAN);
  if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Failed to initialize bus.");
        return 0;
  }
  // 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;

  ret = esp_vfs_fat_sdspi_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 0;
  }

  // Card has been initialized, print its properties
  sdmmc_card_print_info(stdout, card);
  
  //test();
  
  return 1;
}

Who is online

Users browsing this forum: No registered users and 28 guests