This commit is contained in:
Thomas Peterson 2026-01-22 22:37:41 +01:00
parent 582149309b
commit 3440e1af58

View File

@ -4,7 +4,7 @@
#include "sdmmc_cmd.h" #include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h" #include "driver/sdmmc_host.h"
#include "sd_pwr_ctrl_by_on_chip_ldo.h" #include "sd_pwr_ctrl_by_on_chip_ldo.h"
#include "tinyusb.h" #include "tinyusb_default_config.h"
#include "tinyusb_msc.h" #include "tinyusb_msc.h"
#include <sys/stat.h> #include <sys/stat.h>
@ -66,11 +66,9 @@ bool SdCard::init() {
slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP; slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
// Mount FAT filesystem // Mount FAT filesystem
esp_vfs_fat_sdmmc_mount_config_t mount_config = { esp_vfs_fat_sdmmc_mount_config_t mount_config = VFS_FAT_MOUNT_DEFAULT_CONFIG();
.format_if_mount_failed = false, mount_config.max_files = 5;
.max_files = 5, mount_config.allocation_unit_size = 16 * 1024;
.allocation_unit_size = 16 * 1024
};
ESP_LOGI(TAG, "Mounting SD card..."); ESP_LOGI(TAG, "Mounting SD card...");
ret = esp_vfs_fat_sdmmc_mount(MOUNT_POINT, &host, &slot_config, &mount_config, &s_card); ret = esp_vfs_fat_sdmmc_mount(MOUNT_POINT, &host, &slot_config, &mount_config, &s_card);
@ -139,10 +137,8 @@ bool SdCard::enableUsbMsc() {
// Initialize TinyUSB // Initialize TinyUSB
ESP_LOGI(TAG, "Initializing TinyUSB..."); ESP_LOGI(TAG, "Initializing TinyUSB...");
const tinyusb_config_t cfg = { const tinyusb_config_t cfg = TINYUSB_DEFAULT_CONFIG();
.external_phy = false, esp_err_t ret = tinyusb_driver_install(&cfg);
};
esp_err_t ret = tinyusb_driver_install(&tusb_cfg);
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to install TinyUSB driver: %s", esp_err_to_name(ret)); ESP_LOGE(TAG, "Failed to install TinyUSB driver: %s", esp_err_to_name(ret));
return false; return false;
@ -150,20 +146,24 @@ bool SdCard::enableUsbMsc() {
// Initialize MSC storage with SD card // Initialize MSC storage with SD card
ESP_LOGI(TAG, "Initializing USB MSC with SD card..."); ESP_LOGI(TAG, "Initializing USB MSC with SD card...");
const tinyusb_msc_sdmmc_config_t msc_cfg = { tinyusb_msc_storage_config_t storage_cfg = {};
.card = s_card, storage_cfg.medium.card = s_card;
}; storage_cfg.mount_point = TINYUSB_MSC_STORAGE_MOUNT_USB;
storage_cfg.fat_fs.base_path = nullptr;
storage_cfg.fat_fs.config = VFS_FAT_MOUNT_DEFAULT_CONFIG();
storage_cfg.fat_fs.config.max_files = 5;
storage_cfg.fat_fs.config.allocation_unit_size = 16 * 1024;
storage_cfg.fat_fs.do_not_format = true;
storage_cfg.fat_fs.format_flags = 0;
ret = tinyusb_msc_storage_init_sdmmc(&msc_cfg); tinyusb_msc_storage_handle_t storage_hdl = nullptr;
ret = tinyusb_msc_new_storage_sdmmc(&storage_cfg, &storage_hdl);
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize MSC storage: %s", esp_err_to_name(ret)); ESP_LOGE(TAG, "Failed to initialize MSC storage: %s", esp_err_to_name(ret));
return false; return false;
} }
if (storage_hdl == nullptr) {
// Mount MSC storage ESP_LOGE(TAG, "MSC storage handle not initialized");
ret = tinyusb_msc_storage_mount(MOUNT_POINT);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount MSC storage: %s", esp_err_to_name(ret));
return false; return false;
} }