cancel
Showing results for 
Search instead for 
Did you mean: 

How to sync usb device MSC with host

Jason927
Associate III

I'm already achieved a USBX-MSC class, and also a FileX in MCU local.

I know that using two file systems at the same time is not recommended, but still have some questions.

 

1. I implement the ux_deveice_msc.c as followed. Use PC-Windows to create a file such as my_test.txt to U-DISK, successfully and the local FileX will see the new file immediately.

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;
}

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;
}

UINT USBD_STORAGE_Flush(VOID *storage_instance, ULONG lun, ULONG number_blocks,
                        ULONG lba, ULONG *media_status)
{
  UINT status = UX_SUCCESS;

  /* USER CODE BEGIN USBD_STORAGE_Flush */
    if (fx_media_cache_invalidate(sdioDisk) != FX_SUCCESS || fx_media_flush(sdioDisk) != FX_SUCCESS) {
        status = UX_ERROR;
    }
  /* USER CODE END USBD_STORAGE_Flush */

  return status;
}

 

2. When I use local FileX to create a new file, and call function fx_media_flush, the Host PC-Windows can't see th new file until the usb reconnect. Seem windows explorer cache not fresh.

3. Based on point 2, I want to implement function USBD_STORAGE_Status, when some changes happend in local, return a UX_ERROR and media_status with Sense Key = UNIT ATTENTION (0x06), ASC/ASCQ = NOT READY TO READY CHANGE, MEDIA MAY HAVE CHANGED (0x28, 0x00). The purpose is let host reread the U-DISK's FAT32 table.

 

UINT USBD_STORAGE_Status(VOID *storage_instance, ULONG lun, ULONG media_id,
                         ULONG *media_status)
{
  UINT status = UX_SUCCESS;

  /* USER CODE BEGIN USBD_STORAGE_Status */
  UX_PARAMETER_NOT_USED(storage_instance);
  UX_PARAMETER_NOT_USED(lun);
  UX_PARAMETER_NOT_USED(media_id);
  UX_PARAMETER_NOT_USED(media_status);
  /* USER CODE END USBD_STORAGE_Status */

  return status;
}



I want to know if this method is feasible? THANK YOU!

 

0 REPLIES 0