目前使用的存储介质是SD卡,进行fx_media_format格式化之后,可以被PC正常识别,写入读取都是正常的。
但是存在本地和PC端不同步的问题,比如在本地创建或写入文件,创建或写入后立即调用了fx_media_flush,本地已经生效,PC端也不会立即刷新出文件,需要重新枚举才能正常显示。
同样通过PC端写入文件,需要重新fx_media_open本地才能看到PC端上次写入的文件。
造成这样的现象,貌似是两边在维护不同的FAT表。请问有什么好的解决方法吗?
下面是我的格式化代码,以及MSC相关操作代码。
[C] 纯文本查看 复制代码 HAL_SD_CardInfoTypeDef cardInfo;
HAL_SD_GetCardInfo(&hsd1, &cardInfo);
fxStatus = fx_media_format(&sdioDisk, //Disk Handle
fx_stm32_sd_driver, //Disk Driver
(VOID *)FX_NULL, //Unused
(UCHAR *)fxSDMediaMemory, //Disk Buffer
sizeof(fxSDMediaMemory), //Disk Buffer Size
FX_SD_VOLUME_NAME, //Volume Name
1, //Num of FATs
32, //Directory Entries
0, //Hidden Sectors
((cardInfo.BlockNbr * cardInfo.BlockSize) / FX_STM32_SD_DEFAULT_SECTOR_SIZE),//Total Sectors
FX_STM32_SD_DEFAULT_SECTOR_SIZE,//Bytes per Sector
128, //Sectors per Cluster
1, //Heads
1); //Sectors per Track
[C] 纯文本查看 复制代码 /**
* @brief USBD_STORAGE_Read
* This function is invoked to read from media.
* @param storage_instance : Pointer to the storage class instance.
* @param lun: Logical unit number is the command is directed to.
* @param data_pointer: Address of the buffer to be used for reading or writing.
* @param number_blocks: number of sectors to read/write.
* @param lba: Logical block address is the sector address to read.
* @param media_status: should be filled out exactly like the media status
* callback return value.
* @retval status
*/
UINT USBD_STORAGE_Read(VOID *storage_instance, ULONG lun, UCHAR *data_pointer,
ULONG number_blocks, ULONG lba, ULONG *media_status)
{
UINT status = UX_SUCCESS;
/* USER CODE BEGIN USBD_STORAGE_Read */
UINT fxStatus = FX_SUCCESS;
while (number_blocks--) {
fxStatus = fx_media_read(sdioDisk, lba, data_pointer);
if (fxStatus != FX_SUCCESS) {
status = UX_ERROR;
break;
}
data_pointer += sdioDisk->fx_media_bytes_per_sector;
lba++;
}
/* USER CODE END USBD_STORAGE_Read */
return status;
}
/**
* @brief USBD_STORAGE_Write
* This function is invoked to write in media.
* @param storage_instance : Pointer to the storage class instance.
* @param lun: Logical unit number is the command is directed to.
* @param data_pointer: Address of the buffer to be used for reading or writing.
* @param number_blocks: number of sectors to read/write.
* @param lba: Logical block address is the sector address to read.
* @param media_status: should be filled out exactly like the media status
* callback return value.
* @retval status
*/
UINT USBD_STORAGE_Write(VOID *storage_instance, ULONG lun, UCHAR *data_pointer,
ULONG number_blocks, ULONG lba, ULONG *media_status)
{
UINT status = UX_SUCCESS;
/* USER CODE BEGIN USBD_STORAGE_Write */
UINT fxStatus = FX_SUCCESS;
while (number_blocks--) {
fxStatus = fx_media_write(sdioDisk, lba, data_pointer);
if (fxStatus != FX_SUCCESS && lba != 0) {
status = UX_ERROR;
break;
}
data_pointer += sdioDisk->fx_media_bytes_per_sector;
lba++;
}
/* USER CODE END USBD_STORAGE_Write */
return status;
}
|