MSC Support for STM32 + SDIO boards -> SKR 2 (#22354)

This commit is contained in:
Victor Oliveira 2021-07-14 02:34:18 -03:00 committed by Scott Lahteine
parent 8cf15e8546
commit 8334e92b6f
6 changed files with 276 additions and 281 deletions

View File

@ -28,36 +28,6 @@
#include <stdint.h>
#include <stdbool.h>
#if NONE(STM32F103xE, STM32F103xG, STM32F4xx, STM32F7xx)
#error "ERROR - Only STM32F103xE, STM32F103xG, STM32F4xx or STM32F7xx CPUs supported"
#endif
#if HAS_SD_HOST_DRIVE
// use USB drivers
extern "C" {
int8_t SD_MSC_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
int8_t SD_MSC_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
extern SD_HandleTypeDef hsd;
}
bool SDIO_Init() {
return hsd.State == HAL_SD_STATE_READY; // return pass/fail status
}
bool SDIO_ReadBlock(uint32_t block, uint8_t *src) {
int8_t status = SD_MSC_Read(0, (uint8_t*)src, block, 1); // read one 512 byte block
return (bool) status;
}
bool SDIO_WriteBlock(uint32_t block, const uint8_t *src) {
int8_t status = SD_MSC_Write(0, (uint8_t*)src, block, 1); // write one 512 byte block
return (bool) status;
}
#else // !USBD_USE_CDC_COMPOSITE
// use local drivers
#if defined(STM32F103xE) || defined(STM32F103xG)
#include <stm32f1xx_hal_rcc_ex.h>
@ -73,7 +43,7 @@
#include <stm32f7xx_hal_gpio.h>
#include <stm32f7xx_hal_sd.h>
#else
#error "ERROR - Only STM32F103xE, STM32F103xG, STM32F4xx or STM32F7xx CPUs supported"
#error "SDIO only supported with STM32F103xE, STM32F103xG, STM32F4xx, or STM32F7xx."
#endif
// Fixed
@ -330,6 +300,14 @@
return false;
}
bool SDIO_IsReady() {
return hsd.State == HAL_SD_STATE_READY;
}
uint32_t SDIO_GetCardSize() {
return (uint32_t)(hsd.SdCard.BlockNbr) * (hsd.SdCard.BlockSize);
}
#if defined(STM32F1xx)
#define DMA_IRQ_HANDLER DMA2_Channel4_5_IRQHandler
#elif defined(STM32F4xx)
@ -341,6 +319,5 @@
extern "C" void SDIO_IRQHandler(void) { HAL_SD_IRQHandler(&hsd); }
extern "C" void DMA_IRQ_HANDLER(void) { HAL_DMA_IRQHandler(&hdma_sdio); }
#endif // !USBD_USE_CDC_COMPOSITE
#endif // SDIO_SUPPORT
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC && !MAPLE_STM32F1

View File

@ -19,10 +19,10 @@
#if HAS_SD_HOST_DRIVE
#include "../shared/Marduino.h"
#include "msc_sd.h"
#include "usbd_core.h"
#include "../shared/Marduino.h"
#include "../../sd/cardreader.h"
#include <USB.h>

View File

@ -184,6 +184,10 @@ bool SDIO_WriteBlock(uint32_t blockAddress, const uint8_t *data) {
inline uint32_t SDIO_GetCardState() { return SDIO_CmdSendStatus(SdCard.RelCardAdd << 16U) ? (SDIO_GetResponse(SDIO_RESP1) >> 9U) & 0x0FU : SDIO_CARD_ERROR; }
// No F1 board with SDIO + MSC using Maple, that I aware of...
bool SDIO_IsReady() { return true; }
uint32_t SDIO_GetCardSize() { return 0; }
// ------------------------
// SD Commands and Responses
// ------------------------

View File

@ -594,9 +594,9 @@
#elif MB(BTT_E3_RRF)
#include "stm32f4/pins_BTT_E3_RRF.h" // STM32F4 env:BIGTREE_E3_RRF
#elif MB(BTT_SKR_V2_0_REV_A)
#include "stm32f4/pins_BTT_SKR_V2_0_REV_A.h" // STM32F4 env:BIGTREE_SKR_2
#include "stm32f4/pins_BTT_SKR_V2_0_REV_A.h" // STM32F4 env:BIGTREE_SKR_2 env:BIGTREE_SKR_2_USB
#elif MB(BTT_SKR_V2_0_REV_B)
#include "stm32f4/pins_BTT_SKR_V2_0_REV_B.h" // STM32F4 env:BIGTREE_SKR_2
#include "stm32f4/pins_BTT_SKR_V2_0_REV_B.h" // STM32F4 env:BIGTREE_SKR_2 env:BIGTREE_SKR_2_USB
#elif MB(BTT_OCTOPUS_V1_0)
#include "stm32f4/pins_BTT_OCTOPUS_V1_0.h" // STM32F4 env:BIGTREE_OCTOPUS_V1 env:BIGTREE_OCTOPUS_V1_USB
#elif MB(BTT_OCTOPUS_V1_1)

View File

@ -29,6 +29,8 @@
bool SDIO_Init();
bool SDIO_ReadBlock(uint32_t block, uint8_t *dst);
bool SDIO_WriteBlock(uint32_t block, const uint8_t *src);
bool SDIO_IsReady();
uint32_t SDIO_GetCardSize();
class DiskIODriver_SDIO : public DiskIODriver {
public:
@ -36,20 +38,22 @@ class DiskIODriver_SDIO : public DiskIODriver {
bool readCSD(csd_t *csd) override { return false; }
bool readStart(const uint32_t block) override { return false; }
bool readData(uint8_t *dst) override { return false; }
bool readStop() override { return false; }
bool readStart(const uint32_t block) override { curBlock = block; return true; }
bool readData(uint8_t *dst) override { return readBlock(curBlock++, dst); }
bool readStop() override { curBlock = -1; return true; }
bool writeStart(const uint32_t block, const uint32_t) override { return false; }
bool writeData(const uint8_t *src) override { return false; }
bool writeStop() override { return false; }
bool writeStart(const uint32_t block, const uint32_t) override { curBlock = block; return true; }
bool writeData(const uint8_t *src) override { return writeBlock(curBlock++, src); }
bool writeStop() override { curBlock = -1; return true; }
bool readBlock(uint32_t block, uint8_t *dst) override { return SDIO_ReadBlock(block, dst); }
bool writeBlock(uint32_t block, const uint8_t *src) override { return SDIO_WriteBlock(block, src); }
uint32_t cardSize() override { return 0; }
uint32_t cardSize() override { return SDIO_GetCardSize(); }
bool isReady() override { return true; }
bool isReady() override { return SDIO_IsReady(); }
void idle() override {}
private:
uint32_t curBlock;
};

View File

@ -243,6 +243,16 @@ build_flags = ${stm_flash_drive.build_flags}
-DUSE_USBHOST_HS -DUSE_USB_HS_IN_FS -DUSBD_IRQ_PRIO=5 -DUSBD_IRQ_SUBPRIO=6
-DHSE_VALUE=8000000U -DHAL_SD_MODULE_ENABLED
#
# BigTreeTech SKR V2.0 (STM32F407VGT6 ARM Cortex-M4) with USB Media Share Support
#
[env:BIGTREE_SKR_2_USB]
platform = ${common_stm32.platform}
extends = env:BIGTREE_SKR_2
platform_packages = ${stm_flash_drive.platform_packages}
build_unflags = -DUSBD_USE_CDC
build_flags = ${env:BIGTREE_SKR_2.build_flags} -DUSBD_USE_CDC_MSC
#
# BigTreeTech Octopus V1.0/1.1 (STM32F446ZET6 ARM Cortex-M4)
#