Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_esp_vfs_fat_sdmmc_unmount_warning' into 'mas…
Browse files Browse the repository at this point in the history
…ter'

esp_peripherals: fix warnings 'esp_vfs_fat_sdmmc_unmount' is deprecated

See merge request adf/esp-adf-internal!1294
  • Loading branch information
jason-mao committed Apr 8, 2024
2 parents d01f540 + b39e7db commit 6f969f5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 6 additions & 3 deletions components/esp_peripherals/lib/sdcard/sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

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)
{
Expand All @@ -64,9 +65,7 @@ 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 = {
.format_if_mount_failed = false,
.max_files = get_sdcard_open_file_num_max(),
Expand Down Expand Up @@ -164,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");
Expand Down
4 changes: 3 additions & 1 deletion components/esp_peripherals/lib/sdcard/sdcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions components/esp_peripherals/periph_sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6f969f5

Please sign in to comment.