5#include "esp_vfs_fat.h"
8#include "sd_pwr_ctrl_by_on_chip_ldo.h"
11#include "tinyusb_msc.h"
14#include "bsp/esp32_p4_nano.h"
16static const char *FNAME =
"kest_sd.c";
20#define MAX_PARALLEL_FILES 12
26sdmmc_host_t
host = SDMMC_HOST_DEFAULT();
30 .format_if_mount_failed =
false,
32 .allocation_unit_size = 16 * 1024
35static sdmmc_card_t card_obj;
36sdmmc_card_t *
card = &card_obj;
47 .user_flags.auto_mount_off = 1,
51 .mount_point = TINYUSB_MSC_STORAGE_MOUNT_APP,
65 sd_pwr_ctrl_ldo_config_t ldo_config = {
68 sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL;
70 ret = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle);
74 kest_printf(
"Failed to create a new on-chip LDO power control driver");
77 host.pwr_ctrl_handle = pwr_ctrl_handle;
79 sd_pwr_ctrl_set_io_voltage(pwr_ctrl_handle, 3300);
89 slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
99 ret = sdmmc_host_init();
102 kest_printf(
"Failed to initialise SDMMC host: %s\n", esp_err_to_name(ret));
107 if (ret != ESP_OK)
if (ret != ESP_OK)
109 kest_printf(
"Failed to initialise SDMMC host slot: %s\n", esp_err_to_name(ret));
114 if (ret != ESP_OK)
if (ret != ESP_OK)
116 kest_printf(
"Failed to initialise SDMMC card: %s\n", esp_err_to_name(ret));
120 ret = tinyusb_driver_install(&
tusb_cfg);
123 sdmmc_card_print_info(stdout,
card);
128 kest_printf(
"Failed to installed tinyusb driver: %s\n", esp_err_to_name(ret));
136 kest_printf(
"Failed to installed tinyusb MSC driver: %s\n", esp_err_to_name(ret));
144 kest_printf(
"Failed to create tinyusb MSC SDMMC storage decide: %s\n", esp_err_to_name(ret));
164 xSemaphoreTake(
sd_mutex, portMAX_DELAY);
166 esp_err_t ret = tinyusb_msc_set_storage_mount_point(
storage_handle, TINYUSB_MSC_STORAGE_MOUNT_USB);
170 kest_printf(
"Failed to set SD storage point to USB\n");
181 esp_err_t ret = tinyusb_msc_set_storage_mount_point(
storage_handle, TINYUSB_MSC_STORAGE_MOUNT_APP);
185 kest_printf(
"Failed to uninstall tinyusb driver: %s\n", esp_err_to_name(ret));
203 tinyusb_msc_mount_point_t mp;
#define ERR_SD_MOUNT_FAIL
void kest_printf(const char *fmt,...)
sdmmc_slot_config_t slot_config
const int mount_point_strlen
tinyusb_msc_storage_handle_t storage_handle
esp_vfs_fat_sdmmc_mount_config_t mount_config
tinyusb_msc_storage_config_t storage_cfg
tinyusb_msc_driver_config_t msc_drv_cfg
tinyusb_config_t tusb_cfg
SemaphoreHandle_t sd_mutex