Skip to content

Commit 3b7627e

Browse files
committed
esp_peripherals: fix warnings with IDF >= 5.1
Fix the following warnings when building with ESP-IDF >= 5.1. Building C object esp-idf/esp_peripherals/CMakeFiles/__idf_esp_peripherals.dir/lib/sdcard/sdcard.c.obj/willow/deps/esp-adf/components/esp_peripherals/lib/sdcard/sdcard.c: In function 'sdcard_unmount': /willow/deps/esp-adf/components/esp_peripherals/lib/sdcard/sdcard.c:168:5: warning: 'esp_vfs_fat_sdmmc_unmount' is deprecated: Please use esp_vfs_fat_sdcard_unmount instead [-Wdeprecated-declarations] 168 | esp_err_t ret = esp_vfs_fat_sdmmc_unmount(); | ^~~~~~~~~ In file included from /willow/deps/esp-adf/components/esp_peripherals/lib/sdcard/sdcard.c:32: /opt/esp/idf/components/fatfs/vfs/esp_vfs_fat.h:197:11: note: declared here 197 | esp_err_t esp_vfs_fat_sdmmc_unmount(void) __attribute__((deprecated("Please use esp_vfs_fat_sdcard_unmount instead"))); | ^~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Stijn Tintel <[email protected]>
1 parent 31d37d0 commit 3b7627e

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

components/esp_peripherals/lib/sdcard/sdcard.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444

4545
static const char *TAG = "SDCARD";
4646
static int g_gpio = -1;
47+
static sdmmc_card_t *card = NULL;
4748

48-
static void sdmmc_card_print_info(const sdmmc_card_t *card)
49+
static void sdmmc_card_print_info(void)
4950
{
5051
ESP_LOGD(TAG, "Name: %s\n", card->cid.name);
5152
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)
6465
return ESP_FAIL;
6566
}
6667

67-
sdmmc_card_t *card = NULL;
6868
esp_err_t ret = ESP_FAIL;
6969

7070
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)
142142
switch (ret) {
143143
case ESP_OK:
144144
// Card has been initialized, print its properties
145-
sdmmc_card_print_info(card);
145+
sdmmc_card_print_info();
146146
ESP_LOGI(TAG, "CID name %s!\n", card->cid.name);
147147
break;
148148

@@ -163,9 +163,13 @@ esp_err_t sdcard_mount(const char *base_path, periph_sdcard_mode_t mode)
163163

164164
}
165165

166-
esp_err_t sdcard_unmount(void)
166+
esp_err_t sdcard_unmount(const char *base_path)
167167
{
168+
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0))
169+
esp_err_t ret = esp_vfs_fat_sdcard_unmount(base_path, card);
170+
#else
168171
esp_err_t ret = esp_vfs_fat_sdmmc_unmount();
172+
#endif
169173

170174
if (ret == ESP_ERR_INVALID_STATE) {
171175
ESP_LOGE(TAG, "File system not mounted");

components/esp_peripherals/lib/sdcard/sdcard.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ esp_err_t sdcard_mount(const char* base_path, periph_sdcard_mode_t mode);
6060
/**
6161
* @brief Unmount FAT filesystem and release resources acquired using esp_vfs_fat_sdmmc_mount
6262
*
63+
* @param base_path path where partition is mounted (e.g. "/sdcard")
64+
*
6365
* @return
6466
* - ESP_OK on success
6567
* - ESP_ERR_INVALID_STATE if sd_card_mount hasn't been called
6668
*/
67-
esp_err_t sdcard_unmount(void);
69+
esp_err_t sdcard_unmount(const char *base_path);
6870

6971
/**
7072
* @brief remove the sdcard device GPIO interruption in Audio board

components/esp_peripherals/periph_sdcard.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static esp_err_t _sdcard_destroy(esp_periph_handle_t self)
106106
esp_err_t ret = ESP_OK;
107107
periph_sdcard_t *sdcard = esp_periph_get_data(self);
108108
if (sdcard->is_mounted) {
109-
ret |= sdcard_unmount();
109+
ret |= sdcard_unmount(sdcard->root);
110110
sdcard->is_mounted = false;
111111
}
112112
ret |= sdcard_destroy();
@@ -145,7 +145,7 @@ esp_err_t periph_sdcard_unmount(esp_periph_handle_t periph)
145145
{
146146
VALIDATE_SDCARD(periph, ESP_FAIL);
147147
periph_sdcard_t *sdcard = esp_periph_get_data(periph);
148-
int ret = sdcard_unmount();
148+
int ret = sdcard_unmount(sdcard->root);
149149
if (ret == ESP_OK) {
150150
ESP_LOGD(TAG, "UnMount SDCARD success");
151151
sdcard->is_mounted = false;

0 commit comments

Comments
 (0)