USB Host with MFS problems

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB Host with MFS problems

1,314 Views
adyr
Contributor V

I am using MQX version 4.1 and a modified sample web-hvac project with the IAR workbench 7.1. I am running the project on the TWR-K60F120M and the TWR-SER boards.
I have only been using this system for a few weeks and it is my first time with MQX and USB stacks, etc.


The sample functions are all working fine but I have added a shell command to do a file read speed test. This simply records the time to read the contents of a file from a mounted device into a memory buffer in a loop.

E.g.

uint32_t bufSize = 10 * 512;
buffer = (char*)_mem_alloc_system_zero( bufSize );
if (NULL == buffer)
{
  printf( "Failed to allocate read buffer" );
  fclose( fd );
  return_code = SHELL_EXIT_ERROR;
}

printf( "Reading from %s:\n", argv[ 1 ] );
_time_get_elapsed( &startTime );
while ((count = read( fd, buffer, bufSize )) > 0)
{
  bytes += count;
}
_time_get_elapsed( &endTime );
int32_t err = ferror( fd );
fclose( fd );
_time_diff( &startTime, &endTime, &diffTime );
if (err != FS_EOF)
{
  printf( "\nRead Error Code %i\n", err );
}
float time1 = (float)((diffTime.SECONDS * 1000) + diffTime.MILLISECONDS);
float kbytes_sec = (float)bytes / time1;

printf( "\nRead %i bytes in %i.%i S - %.3f KB/S\n", bytes, diffTime.SECONDS, diffTime.MILLISECONDS, kbytes_sec );
_mem_free( buffer );

Files on an SD card are working fine at around 3.5MB/s but I am having problems with files on a USB stick. If I connect the stick directly to the TWR-SER USB port I can read a 97660 bytes file with no problems but a 1234920448

bytes file fails. If I connect the stick via a hub then even the smaller file sometimes fails.
The failure modes are below:


1. When connect directly. Stops reading part way through the file (read function returns 0 bytes read). No other errors but ferror returns 0. Once the error occurs all further speed tests return 0 bytes immediately but I can still

perform the dir function correctly. Unplugging and plugging the stick back in resolves the problem until a new speed test fails.


2. When connected via a hub. The detach event occurs which tries to close the file system but that fails as a file is still open. After that a reboot is required as unplugging and plugging in the stick fails to mount the file

system that was not closed properly. The MQX plugin, Check for Errors command, shows an Error Code: Invalid Pointer (0x0001), State Active.

I have used the IAR - MQX plugin to check the stacks and the highest usage is only 56 %.


My questions are:

1. Has anyone got any ideas why the read is failing or where to start looking?

2. Can anyone suggest why it is less reliable through the hub and where to start looking for what is going wrong?

3. Any recommendations on a way to close the file system on the unexpected detach event so that the system can recover when the attach event occurs? I have found that ignoring the "if ( !drive_ptr->MFS_FILE_PTR )" in MFS_Uninstall

to force the destroy does at least remove the requirement to reboot the board but the automatic attach that follows the unexpected detach shows "NOT A DOS DISK! You must format to continue.". Unplugging and plugging back in

resolves that.

Unfortunately I don't have a USB analyser and I can't make any sense of the Jet-Trace trace buffer so I'm hoping there is someone that might have already solved a similar problem or some experts on the USB stack that might be able to give me some suggestions.

Best regards,
Adrian.

Labels (2)
Tags (3)
0 Kudos
6 Replies

614 Views
CarlosCasillas
NXP Employee
NXP Employee

Hi Adrian,

Have you verify if the mentioned errors also happen on the mfs_usb demo without adding the printf functions? The mentioned demo is located at the following path:

C:\Freescale\Freescale_MQX_4_1\mfs\examples\mfs_usb\build\iar\mfs_usb_twrk60f120m


Hope this will be useful for you
Best regards!
/Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

614 Views
adyr
Contributor V

I have now tried to copy a large file from one USB flash drive to another using both the mfs_usb_twrk60f120m and my application and both fail in the same way as my speed test. Worse still is that all my Flash drives fail doing this, even the ones that seemed to work in my speed test.

I have also tried to copy from the USB flash drive to the SD card using my application and get exactly the same problems as my speed test with and without the hub.

Has anyone else had problems copying large files over a MQX USB MSD host?

Thanks,

Adrian.

0 Kudos

614 Views
ARQuattr
Contributor IV

Hi Adrian, I've been having issues reading files from a USB drive with MQX, MFS, and USB Host.  I've had similar problems in both MQX 3.6 and 4.0.  My primary application for this is reading large audio files from the drive while streaming to a CODEC for real-time playback, so I need a high read rate.  I was wondering if you are still having these issues or if you found some solution?

0 Kudos

614 Views
adyr
Contributor V

Hi Angelo,

I never solved that problem then and got side tracked on another project. In that time Freescale launched the KSDK, which I am now using (1.3) with the latest MQX (5.0.512), and that does seem better so far but I haven't tried to replicate the same tests as before. I have tried a quick test to copy a ~10MB file to another folder on the same thumb drive and it did work and took about 45 seconds. Maybe I should also say that I am running the latest KSDK, etc. on our own hardware and not a tower board like the previous test but I don't know if that is relevant.

I can also confirm that the shell dir function with long filenames works much faster than before.

Best regards,

Adrian.

0 Kudos

614 Views
adyr
Contributor V

I have now added a similar speed test to my bootloader code. I think this is based on the sample code from the USB_Stack_v4.1.1 download but I got inspiration from so many sources that I have lost track. This works on all my USB flash drives, except it is slow (~53 KB/s using a 30720 bytes buffer).

I'm not sure if that points to it being an MQX problem as the drives work in bare metal but not MQX?

The mfs_usb_... sample gave me the solution to the open file problem when dismounting the USB drive so I have now ported that over to my application. Now instead of returning if there is a MFS_SHARING_VIOLATION it waits in a loop for the other tasks to close the files. So thank you for pointing me to that sample Carlos.

Adrian.

0 Kudos

614 Views
adyr
Contributor V

Hi Carlos,

Thank you for the suggestion.

I have now tried that and I get the same problems. I'm not sure what you meant by "without adding the printf functions" though. The only printf's I have added are before the test starts and after it has finished so do you think they may be a problem or am I not reading your suggestion correctly?

One thing I am not sure about, I have added "#include <sh_prv.h> and the path to the source folder in the project pre-processor to get my function to compile. Basically my speed test function is a modified copy of the MQX Shell read function and it must be using non-standard shell features. Rather than fixing the non-standard usage I added the include.

I have also found that the problem seems to be dependent on the USB flash drive type as well. Initially I was using a Corsair Voyager 3.0 revision 1.00 (as reported by the application) which fails. I then tried 2 Kingston DataTraveler 2.0 revision PMAP several times and they work fine (at 227 KB/s). I also tried 2 Generic Flash Disk revision 1.68 and they worked (at 124 KB/s). Next I tried a Kingston DT HyperX 3.0 revision PMAP and that fails. I'm using the same file on all the drives to make sure it is not content dependent.

Also, when a drive is removed with a file open, in this case due to the error, the device is un-mounted but the file system is left hanging so it can't be remounted when the drive is connected again. This means the board has to be reset. Any ideas how to force the file system to close when the detach event occurs?

Adrian.

0 Kudos