28 #if defined(SDMMC_DATATIMEOUT)
29 #define SD_TIMEOUT SDMMC_DATATIMEOUT
30 #elif defined(SD_DATATIMEOUT)
31 #define SD_TIMEOUT SD_DATATIMEOUT
33 #define SD_TIMEOUT 30 * 1000
36 #define SD_DEFAULT_BLOCK_SIZE 512
56 #if !defined(DISABLE_SD_INIT)
58 if (BSP_SD_Init() == MSD_OK) {
59 stat = SD_CheckStatus(lun);
63 Stat = SD_CheckStatus(lun);
73 DSTATUS
disk_status(BYTE lun)
override {
return SD_CheckStatus(lun); }
83 DRESULT
disk_read(BYTE lun, BYTE *buff, DWORD sector, UINT count) {
85 DRESULT res = RES_ERROR;
87 if (BSP_SD_ReadBlocks((uint32_t *)buff, (uint32_t)(sector), count,
88 SD_TIMEOUT) == MSD_OK) {
90 while (BSP_SD_GetCardState() != MSD_OK) {
107 DRESULT
disk_write(BYTE lun,
const BYTE *buff, DWORD sector, UINT count) {
109 DRESULT res = RES_ERROR;
111 if (BSP_SD_WriteBlocks((uint32_t *)buff, (uint32_t)(sector), count,
112 SD_TIMEOUT) == MSD_OK) {
114 while (BSP_SD_GetCardState() != MSD_OK) {
133 DRESULT res = RES_ERROR;
134 BSP_SD_CardInfo CardInfo;
136 if (stat & STA_NOINIT)
return RES_NOTRDY;
145 case GET_SECTOR_COUNT:
146 BSP_SD_GetCardInfo(&CardInfo);
147 *(DWORD *)buff = CardInfo.LogBlockNbr;
152 case GET_SECTOR_SIZE:
153 BSP_SD_GetCardInfo(&CardInfo);
154 *(WORD *)buff = CardInfo.LogBlockSize;
160 BSP_SD_GetCardInfo(&CardInfo);
161 *(DWORD *)buff = CardInfo.LogBlockSize / SD_DEFAULT_BLOCK_SIZE;
175 volatile DSTATUS stat = STA_NOINIT;
177 DSTATUS SD_CheckStatus(BYTE lun) {
181 if (BSP_SD_GetCardState() == MSD_OK) {
Empty IO implementation that we can use to test the compilation.
Definition: BaseIO.h:10
Depending on the usecase, the SD card initialization could be done at the application level,...
Definition: SDSTM32DiskIO.h:47
DRESULT disk_ioctl(BYTE lun, ioctl_cmd_t cmd, void *buff)
I/O control operation.
Definition: SDSTM32DiskIO.h:131
DRESULT disk_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
Reads Sector(s)
Definition: SDSTM32DiskIO.h:83
DSTATUS disk_initialize(BYTE lun) override
Initializes a Drive.
Definition: SDSTM32DiskIO.h:54
DRESULT disk_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
Writes Sector(s)
Definition: SDSTM32DiskIO.h:107
DSTATUS disk_status(BYTE lun) override
Gets Disk Status.
Definition: SDSTM32DiskIO.h:73