|
发表于 2018-1-10 13:48:18
|
显示全部楼层
你好,看SD卡的f_read,f_write等都是启动DMA并等待结束后再继续操作,那比如SD卡拷贝数据期间(for循环)怎么响应串口数据?
/* Copy source to destination */
for (;;)
{
fr = f_read(&SDFile, buffer, sizeof buffer, &br); /* Read a chunk of source file */
if (fr || br == 0) break; /* error or eof */
fr = f_write(&USBHFile, buffer, br, &bw); /* Write it to the destination file */
if (fr || bw < br) break; /* error or disk full */
_pRunStrt->SDCard.UseFrameNum++;
}
-------------------
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-Bit aligned address
adjust the address and the D-Cache size to clean accordingly.
*/
alignedAddr = (uint32_t)buff & ~3;
SCB_CleanDCache_by_Addr((uint32_t*)alignedAddr, count*BLOCKSIZE + ((uint32_t)buff - alignedAddr));
#endif
if(BSP_SD_WriteBlocks_DMA((uint32_t*)buff,
(uint32_t) (sector),
count) == MSD_OK)
{
/* Wait that the 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_SD_GetCardState() == SD_TRANSFER_OK)
{
res = RES_OK;
break;
}
}
}
}
return res;
}
|
|