|

楼主 |
发表于 2019-11-13 08:20:03
|
显示全部楼层
感谢 Eric 大的回覆
diskio.c 驱动指的是这个部分吗? 仅撷取一小部分您的demo
- /*
- * when using cachable memory region, it may be needed to maintain the cache
- * validity. Enable the define below to activate a cache maintenance at each
- * read and write operation.
- * Notice: This is applicable only for cortex M7 based platform.
- */
- #define ENABLE_SD_DMA_CACHE_MAINTENANCE 1
- /* Private variables ---------------------------------------------------------*/
- /* Disk status */
- static volatile DSTATUS Stat = STA_NOINIT;
- static volatile UINT WriteStatus = 0, ReadStatus = 0;
- /* Private function prototypes -----------------------------------------------*/
- static DSTATUS SD_CheckStatus(BYTE lun);
- DSTATUS SD_initialize (BYTE);
- DSTATUS SD_status (BYTE);
- DRESULT SD_read (BYTE, BYTE*, DWORD, UINT);
- #if _USE_WRITE == 1
- DRESULT SD_write (BYTE, const BYTE*, DWORD, UINT);
- #endif /* _USE_WRITE == 1 */
- #if _USE_IOCTL == 1
- DRESULT SD_ioctl (BYTE, BYTE, void*);
- #endif /* _USE_IOCTL == 1 */
- const Diskio_drvTypeDef SD_Driver =
- {
- SD_initialize,
- SD_status,
- SD_read,
- #if _USE_WRITE == 1
- SD_write,
- #endif /* _USE_WRITE == 1 */
- #if _USE_IOCTL == 1
- SD_ioctl,
- #endif /* _USE_IOCTL == 1 */
- };
- /* Private functions ---------------------------------------------------------*/
- static DSTATUS SD_CheckStatus(BYTE lun)
- {
- Stat = STA_NOINIT;
- if(BSP_MMC_GetCardState() == MMC_TRANSFER_OK)
- {
- Stat &= ~STA_NOINIT;
- }
- return Stat;
- }
复制代码
---------------------------------------------------------------------------------------------------------
另外我在侦错时,会在下面这个部分的HAL_GetTick返回ERROR,再麻烦您,谢谢!
---------------------------------------------------------------------------------------------------------
- #if _USE_WRITE == 1
- DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
- {
- DRESULT res = RES_ERROR;
- WriteStatus = 0;
- uint32_t timeout;
- #if (ENABLE_SD_DMA_CACHE_MAINTENANCE == 1)
- uint32_t alignedAddr;
- /*
- the SCB_CleanDCache_by_Addr() requires a 32-Byte aligned address
- adjust the address and the D-Cache size to clean accordingly.
- */
- alignedAddr = (uint32_t)buff & ~0x1F;
- SCB_CleanDCache_by_Addr((uint32_t*)alignedAddr, count*BLOCKSIZE + ((uint32_t)buff - alignedAddr));
- #endif
- if(BSP_MMC_WriteBlocks_DMA((uint32_t*)buff,
- (uint32_t)(sector),
- count) == MMC_OK)
- {
- /* Wait that writing process is completed or a timeout occurs */
- timeout = HAL_GetTick();
- while((WriteStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT))
- {
- }
- /* incase of a timeout return error */
- if (WriteStatus == 0)
- {
- res = RES_ERROR;
- }
- else
- {
- WriteStatus = 0;
- timeout = HAL_GetTick();
- while((HAL_GetTick() - timeout) < SD_TIMEOUT)
- {
- if (BSP_MMC_GetCardState() == MMC_TRANSFER_OK)
- {
- res = RES_OK;
- break;
- }
- }
- }
- }
- return res;
- }
复制代码 |
|