diff --git a/components/esp_peripherals/lib/sdcard/sdcard.c b/components/esp_peripherals/lib/sdcard/sdcard.c index 6388d1fcd..505996105 100644 --- a/components/esp_peripherals/lib/sdcard/sdcard.c +++ b/components/esp_peripherals/lib/sdcard/sdcard.c @@ -44,8 +44,9 @@ static const char *TAG = "SDCARD"; static int g_gpio = -1; +static sdmmc_card_t *card = NULL; -static void sdmmc_card_print_info(const sdmmc_card_t *card) +static void sdmmc_card_print_info(void) { ESP_LOGD(TAG, "Name: %s\n", card->cid.name); ESP_LOGD(TAG, "Type: %s\n", (card->ocr & SD_OCR_SDHC_CAP) ? "SDHC/SDXC" : "SDSC"); @@ -64,7 +65,6 @@ esp_err_t sdcard_mount(const char *base_path, periph_sdcard_mode_t mode) return ESP_FAIL; } - sdmmc_card_t *card = NULL; esp_err_t ret = ESP_FAIL; esp_vfs_fat_sdmmc_mount_config_t mount_config = { @@ -142,7 +142,7 @@ esp_err_t sdcard_mount(const char *base_path, periph_sdcard_mode_t mode) switch (ret) { case ESP_OK: // Card has been initialized, print its properties - sdmmc_card_print_info(card); + sdmmc_card_print_info(); ESP_LOGI(TAG, "CID name %s!\n", card->cid.name); break; @@ -163,9 +163,13 @@ esp_err_t sdcard_mount(const char *base_path, periph_sdcard_mode_t mode) } -esp_err_t sdcard_unmount(void) +esp_err_t sdcard_unmount(const char *base_path) { +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)) + esp_err_t ret = esp_vfs_fat_sdcard_unmount(base_path, card); +#else esp_err_t ret = esp_vfs_fat_sdmmc_unmount(); +#endif if (ret == ESP_ERR_INVALID_STATE) { ESP_LOGE(TAG, "File system not mounted"); diff --git a/components/esp_peripherals/lib/sdcard/sdcard.h b/components/esp_peripherals/lib/sdcard/sdcard.h index 42bdc98a0..527df1344 100644 --- a/components/esp_peripherals/lib/sdcard/sdcard.h +++ b/components/esp_peripherals/lib/sdcard/sdcard.h @@ -60,11 +60,13 @@ esp_err_t sdcard_mount(const char* base_path, periph_sdcard_mode_t mode); /** * @brief Unmount FAT filesystem and release resources acquired using esp_vfs_fat_sdmmc_mount * + * @param base_path path where partition is mounted (e.g. "/sdcard") + * * @return * - ESP_OK on success * - ESP_ERR_INVALID_STATE if sd_card_mount hasn't been called */ -esp_err_t sdcard_unmount(void); +esp_err_t sdcard_unmount(const char *base_path); /** * @brief remove the sdcard device GPIO interruption in Audio board diff --git a/components/esp_peripherals/periph_sdcard.c b/components/esp_peripherals/periph_sdcard.c index c5471b4d5..ff05ed7fc 100644 --- a/components/esp_peripherals/periph_sdcard.c +++ b/components/esp_peripherals/periph_sdcard.c @@ -106,7 +106,7 @@ static esp_err_t _sdcard_destroy(esp_periph_handle_t self) esp_err_t ret = ESP_OK; periph_sdcard_t *sdcard = esp_periph_get_data(self); if (sdcard->is_mounted) { - ret |= sdcard_unmount(); + ret |= sdcard_unmount(sdcard->root); sdcard->is_mounted = false; } ret |= sdcard_destroy(); @@ -145,7 +145,7 @@ esp_err_t periph_sdcard_unmount(esp_periph_handle_t periph) { VALIDATE_SDCARD(periph, ESP_FAIL); periph_sdcard_t *sdcard = esp_periph_get_data(periph); - int ret = sdcard_unmount(); + int ret = sdcard_unmount(sdcard->root); if (ret == ESP_OK) { ESP_LOGD(TAG, "UnMount SDCARD success"); sdcard->is_mounted = false;