From b1604e8459eeb17a8424dd44efeb86e69e60c55a Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Thu, 2 Jan 2025 19:04:58 +0000 Subject: [PATCH] AT32F435 SD card support (#14018) Support either USE_FLASH or USE_SDCARD on AT32F435 --- .../middlewares/usbd_class/msc/msc_bot_scsi.c | 3 ++ src/platform/AT32/mk/AT32F4.mk | 3 +- src/platform/AT32/usb_msc_at32f43x.c | 35 ++++++++++++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/main/AT32F43x/middlewares/usbd_class/msc/msc_bot_scsi.c b/lib/main/AT32F43x/middlewares/usbd_class/msc/msc_bot_scsi.c index 8e8e740ff..3b79860b3 100644 --- a/lib/main/AT32F43x/middlewares/usbd_class/msc/msc_bot_scsi.c +++ b/lib/main/AT32F43x/middlewares/usbd_class/msc/msc_bot_scsi.c @@ -23,6 +23,7 @@ */ #include "msc_bot_scsi.h" #include "msc_diskio.h" +#include "usbd_msc_mem.h" /** @addtogroup AT32F435_437_middlewares_usbd_class * @{ @@ -112,6 +113,8 @@ void bot_scsi_init(void *udev) pmsc->csw_struct.dCSWSignature = 0; pmsc->csw_struct.dCSWTag = CSW_BCSWSTATUS_PASS; + USBD_STORAGE_fops->Init(0); + usbd_flush_tx_fifo(pudev, USBD_MSC_BULK_IN_EPT&0x7F); /* set out endpoint to receive status */ diff --git a/src/platform/AT32/mk/AT32F4.mk b/src/platform/AT32/mk/AT32F4.mk index 66c04b4af..610bb463b 100644 --- a/src/platform/AT32/mk/AT32F4.mk +++ b/src/platform/AT32/mk/AT32F4.mk @@ -124,7 +124,8 @@ MCU_COMMON_SRC = \ msc/usbd_storage.c \ msc/usbd_storage_emfat.c \ msc/emfat.c \ - msc/emfat_file.c + msc/emfat_file.c \ + msc/usbd_storage_sd_spi.c SPEED_OPTIMISED_SRC += \ common/stm32/system.c diff --git a/src/platform/AT32/usb_msc_at32f43x.c b/src/platform/AT32/usb_msc_at32f43x.c index 6a06dd8c1..42e7ec32e 100644 --- a/src/platform/AT32/usb_msc_at32f43x.c +++ b/src/platform/AT32/usb_msc_at32f43x.c @@ -179,6 +179,35 @@ uint8_t mscStart(void) IOInit(IOGetByTag(IO_TAG(PA11)), OWNER_USB, 0); IOInit(IOGetByTag(IO_TAG(PA12)), OWNER_USB, 0); + switch (blackboxConfig()->device) { +#ifdef USE_SDCARD + case BLACKBOX_DEVICE_SDCARD: + switch (sdcardConfig()->mode) { +#ifdef USE_SDCARD_SDIO + case SDCARD_MODE_SDIO: + USBD_STORAGE_fops = &USBD_MSC_MICRO_SDIO_fops; + break; +#endif +#ifdef USE_SDCARD_SPI + case SDCARD_MODE_SPI: + USBD_STORAGE_fops = &USBD_MSC_MICRO_SD_SPI_fops; + break; +#endif + default: + return 1; + } + break; +#endif + +#ifdef USE_FLASHFS + case BLACKBOX_DEVICE_FLASH: + USBD_STORAGE_fops = &USBD_MSC_EMFAT_fops; + break; +#endif + default: + return 1; + } + msc_usb_gpio_config(); crm_periph_clock_enable(OTG_CLOCK, TRUE); msc_usb_clock48m_select(USB_CLK_HEXT); @@ -199,7 +228,7 @@ uint8_t mscStart(void) int8_t msc_disk_capacity(uint8_t lun, uint32_t *block_num, uint32_t *block_size) { - return USBD_MSC_EMFAT_fops.GetCapacity(lun, block_num, block_size); + return USBD_STORAGE_fops->GetCapacity(lun, block_num, block_size); } int8_t msc_disk_read( @@ -208,7 +237,7 @@ int8_t msc_disk_read( uint8_t *buf, // Pointer to the buffer to save data uint16_t blk_len) // number of blocks to be read { - return USBD_MSC_EMFAT_fops.Read(lun, buf, blk_addr, blk_len); + return USBD_STORAGE_fops->Read(lun, buf, blk_addr, blk_len); } int8_t msc_disk_write(uint8_t lun, @@ -228,7 +257,7 @@ uint8_t *get_inquiry(uint8_t lun) { UNUSED(lun); - return (uint8_t *)USBD_MSC_EMFAT_fops.pInquiry; + return (uint8_t *)USBD_STORAGE_fops->pInquiry; } uint8_t msc_get_readonly(uint8_t lun) -- 2.11.4.GIT