初级会员
- 积分
- 71
- 金钱
- 71
- 注册时间
- 2024-6-20
- 在线时间
- 25 小时
|
30金钱
STM32F407 挂载了TF卡,开了 fatfs 也连接成为了usb massive storage设备
底层读写都能正常更新剩余容量
但是usb删加文件后 剩余容量不更新
获取容量用的是f_getfree
然后usb这边代码如下
int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
int8_t ret = USBD_FAIL;
if( HAL_SD_ReadBlocks_DMA(&hsd, buf, blk_addr, blk_len) == HAL_OK ) { ret = USBD_OK; }
if( USBD_OK == ret )
{
while(HAL_SD_GetState(&hsd) == HAL_SD_STATE_BUSY){};
while( HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER ){};
}
return ret;
}
int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
int8_t ret = USBD_FAIL;
if( HAL_SD_WriteBlocks_DMA(&hsd, buf, blk_addr, blk_len) == HAL_OK )
{ ret = USBD_OK;}
if( USBD_OK == ret )
{
while(HAL_SD_GetState(&hsd) == HAL_SD_STATE_BUSY){};
while( HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER ){};
}
return ret;
}
|
|