AnsweredAssumed Answered

MQX 4.2.0.2 with MFS and USBv2 data not flushing on fclose

Question asked by Thomas Wong on Oct 4, 2016
Latest reply on Oct 14, 2016 by Johannes Schock

Hello,

 

Has anybody else had problems where the data does not flush to the USB stick on fclose?

 

I am having problems where the data I am writing to the USB stick is not persistent even after I do fflush and fclose on the file unless I close the filesystem (usb_filesystem_uninstall).

 

It's similar to this FFS fsclose required?  except with USB and now on MQX 4.2. I have tried this with SD card and the SD card data has been persistent.

 

My development environment consists of IAR with a Vybrid VF65GS10 based system with MQX 4.2.0.2 mfs (not mfsv1) usbv2(not usb).

 

For example, what I have seen is that:

1) fopen, fwrite("abc"), fclose

2) "abc" will be on the file in the USB stick

3) fopen, fwrite("def"), fclose

4) only "abc" will be on the file in the USB stick

5) fopen, fwrite("ghi"), fclose

6) only "abcdef" will be on the file in the USB stick

...

 

So, other than the first fwrite, the last fwrite to the USB stick will not be flushed into the USB stick until I close the filesystem.

 

I have tried doing the following and the data is not persistent after fclose:

1) fflush file

fopen, fwrite, fflush, fclose

 

2) fflush device before fclose

fopen

fwrite

_io_get_fs_by_name(...); //get filesystem_pointer

fflush(filesystem_pointer) //MFS_Flush_Device function tries to flush the whole device

fclose

 

3) fflush device after fclose

fopen

fwrite

fclose

_io_get_fs_by_name(...); //get filesystem_pointer

fflush(filesystem_pointer) //MFS_Flush_Device function tries to flush the whole device

 

4) set mfs to MFS_WRITE_THROUGH_CACHE

usb_filesystem_install(...);

_io_get_fs_by_name(...); //get filesystem_pointer

ioctl(filesystem_pointer, IO_IOCTL_WRITE_CACHE_OFF, NULL);

 

 

As well, I ran the msd_fatfs example in the usbv2 directory (\Freescale\Freescale_MQX_4_2\usb_v2\example\host\msd\msd_fatfs) with the same results using the following steps:

 

1) Change #define  HIGH_SPEED (1) to get it working for Vybrid.

2) Change USBCFG_HOST_BUFF_PROPERTY_CACHEABLE in usb_host_config.h to 1 when running from ddr or to 0 when running from sram

3a) Debug example

3b) Insert USB stick

3c) In shell, write tmp 5

3d) In shell, write tmp 5 end 0

3e) Remove USB stick

4) Can only see 01234, Expect to see 0123401234

 

Is there something I can look at doing so the data will be persistent after an fclose to a USB file without having to close and reopen the filesystem each time?

Outcomes