76 lines
2.7 KiB
C
76 lines
2.7 KiB
C
/**
|
|
* Copyright (2017) Baidu Inc. All rights reserved.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
/**
|
|
* File: duerapp_sdcard_config.c
|
|
* Auth: Su Hao(suhao@baidu.com)
|
|
* Desc: Duer Application sdcard configuration.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include "esp_err.h"
|
|
#include "esp_log.h"
|
|
#include "esp_vfs_fat.h"
|
|
#include "driver/sdmmc_host.h"
|
|
#include "driver/sdmmc_defs.h"
|
|
#include "sdmmc_cmd.h"
|
|
#include "duerapp_config.h"
|
|
|
|
void initialize_sdcard(void)
|
|
{
|
|
DUER_LOGI("Initializing SD card");
|
|
|
|
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
|
|
|
// To use 1-line SD mode, uncomment the following line:
|
|
host.flags = SDMMC_HOST_FLAG_1BIT;
|
|
|
|
// 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.
|
|
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
|
|
|
// Options for mounting the filesystem.
|
|
// If format_if_mount_failed is set to true, SD card will be partitioned and formatted
|
|
// in case when mounting fails.
|
|
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
|
.format_if_mount_failed = true,
|
|
.max_files = 5
|
|
};
|
|
|
|
// Use settings defined above to initialize SD card and mount FAT filesystem.
|
|
// Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
|
|
// Please check its source code and implement error recovery when developing
|
|
// production applications.
|
|
sdmmc_card_t *card;
|
|
esp_err_t ret = esp_vfs_fat_sdmmc_mount(SDCARD_PATH, &host, &slot_config, &mount_config, &card);
|
|
if (ret != ESP_OK) {
|
|
if (ret == ESP_FAIL) {
|
|
DUER_LOGE("Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true.");
|
|
} else {
|
|
DUER_LOGE("Failed to initialize the card (%d). Make sure SD card lines have pull-up resistors in place.", ret);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Card has been initialized, print its properties
|
|
sdmmc_card_print_info(stdout, card);
|
|
}
|
|
|
|
void finalize_sdcard(void)
|
|
{
|
|
// All done, unmount partition and disable SDMMC host peripheral
|
|
esp_vfs_fat_sdmmc_unmount();
|
|
DUER_LOGI("Card unmounted");
|
|
} |