请问谁有合泰的32位的芯片使用USB读取SPI FLASH模拟成U盘在电脑端读取和写入文件吗?我现在按照例程中读写SD的方案写了一个读写flash的,但是只能在电脑端读文件,不能写入文件。现在是USB读写flash的函数,其中读函数是一次两个字节,所以读取长度需要少一半,即右移了一位
u32 FLASHDISK_Write(u32 uId, u8 *pBuffer, u32 uBlockAddress, u32 uLength)
{
u32 i;
u32 uResult = TRUE;
if (uId == FLASHDISK0_ID)
{
uResult = TRUE;
if (gDiskWriteStatus == FLASHDISK_IDLE)
{
gDiskWriteStatus = FLASHDISK_WRITE;
guWriteBufferOffset = 0;
}
for (i = 0; i < uLength; i++)
{
guWriteBuffer[guWriteBufferOffset + i] = *(pBuffer + i);
}
guWriteBufferOffset += uLength;
if (guWriteBufferOffset == FLASHDISK0_BlockSize)
{
gDiskWriteStatus = FLASHDISK_IDLE;
uBlockAddress = uBlockAddress<<12;
SPI_FLASH_SectorErase(uBlockAddress);
FATFS_SPI_FLASH_BufferWrite((u8 *)guWriteBuffer,uBlockAddress,FLASHDISK0_BlockSize);
}
}
else
{
uResult = FALSE;
}
return uResult;
}
u32 FLASHDISK_Read(u32 uId, u8 **pBuffer, u32 uBlockAddress, u32 uLength)
{
u32 uResult = TRUE;
if (uId == FLASHDISK0_ID)
{
if ((uBlockAddress / CACHE_CNT != uCachePage / CACHE_CNT) && (uCachePage != uBlockAddress))
{
/* Calculate the cache start address which shall be aligned with the cache size. */
uCachePage = (uBlockAddress / CACHE_CNT) * CACHE_CNT;
QSPI_FLASH_BufferQuadReadByDMA((u16*)guReadBuffer, uCachePage, (FLASHISK_READ_BUFFER)>>1);
}
if ((uCurrentBlock != uBlockAddress) || ((guReadBufferOffset % FLASHDISK0_BlockSize) == 0))
{
uCurrentBlock = uBlockAddress;
guReadBufferOffset = (uBlockAddress - uCachePage) * FLASHDISK0_BlockSize;
}
*pBuffer = &(guReadBuffer[guReadBufferOffset]);
guReadBufferOffset += BOT_MAX_PACKET_SIZE;
}
else
{
uResult = FALSE;
}
return uResult;
}
|