FR_NO_FILESYSTEM Error on USB Host MSD with FatFs

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

FR_NO_FILESYSTEM Error on USB Host MSD with FatFs

2,869 Views
Vagni
Contributor IV

On my custom board based on K66F180 cpu I have to handle both SD cards through the SPI interface and a memory stick on USB Host.

I am developing my application with KDS 3.0.0 and KSDK 1.3.0 + PEx. My application is based on MQX RTOS Standard and I created my project following the tutorial How To: Create an MQX RTOS for KSDK project with Processor Expert in Kinetis Design Studio IDE .How To: Create an MQX RTOS for KSDK project with Processor Expert in Kinetis Design Studio IDE

 

Following the tutorial FRDM K64F Data Logger using FatFs with KSDK 1.2.0 | Centaurian  and the host_msd_fatfs_mqx_twrk65f180m demo project provided with KSDK 1.3.0, I chose FatFs file system for both the mass storage devices.

 

I imported FatFs source files in my project and now I can properly read/write files on SD cards.

 

In my project I loaded the fsl_usb_framework PE component and configured it in Host mode to generate the driver information table for USB_CLASS_MASS_STORAGE with USB_SUBCLASS_MASS_UFI and USB_SUBCLASS_MASS_SCSI sub-classes and USB_PROTOCOL_MASS_BULK protocol. I use the same usb_host_mass_device_event() MSD event call-back function and my USB task has the same architecture of APP_Task() function in the demo.

On a USB_DEVICE_INTERFACE_OPENED mass device state event I call f_mount() to mount the FatFs file system on the attached USB memory stick.

 

But FatFs mounting always fails on USB, I always get the FR_NO_FILESYSTEM error.

 

Debugging my code I verified all the calls to msd_disk_initialize(), msd_disk_ioctl() and msd_disk_read() functions return with no errors (USB_OK).

Also, the USB code should work, because upon disk initialization the Vendor Information, Product Identification and Product Revision Level strings are properly received from the attached USB memory stick.

But no data are received when f_mount() tries to read the first disk sector to check if a valid FAT is present: the received buffer remains with all its byte at 0x00 and the check for a 0xAA55 valid boot record signature at offset 510 always fails.

And I get the same issue even if I change the USB memory stick (formatted as FAT or FAT32).

 

I verified both the usbhdltask and the KHCI Task are running, but I am not able to debug inside the USB code to see what happens.

And I confirm: I can read/write files on SD cards in the same time with the same FatFs file system

 

I am attaching my PE project, the FatFs config file, the msd_diskio.c source file and my USB task source file.

Is there anyone who can help me on that issue?

 

Thanks.

Original Attachment has been moved to: USB_Host_MSD.zip

Labels (1)
6 Replies

1,696 Views
thiagow
Contributor III

I solved a similar problem.

I changed the 

#define _WORD_ACCESS 1

To

#define _WORD_ACCESS 0

On ffconf.h

My platform is Coldfire.

0 Kudos

1,696 Views
isaacavila
NXP Employee
NXP Employee

Hello Alessandro,

I think you should analyze USB frames by using an USB sniffer, if you do not have one, you could migrate your code to TWR-K65F180M with minimum settings (only adding USB and SD components) and this way I can analyze your project.

I hope this can help

Best Regards,

Isaac

0 Kudos

1,696 Views
Vagni
Contributor IV

Hello Isaac,

In the meantime I solved my issue. I changed the SCSI command object initialization in the msd_disk_initialize() function of the msd_diskio.c source file in the following way:

//g_pCmd.LUN = pdrv;

g_pCmd.LUN = 0;

The g_pCmd structure is used in all the USB transactions. Having also a SD card disk was the cause of my issue ( I have more than one physical drive). The host_msd_fatfs_mqx_twrk65f180m demo project provided with KSDK 1.3.0 works, I think because it assumes to have only one physical disk.

Maybe, some actions I don't know are required before the USB MSD disk initialization to know how many logical units are defined on the mass storage device and to pass the correct logical unit index to the msd_disk_initialize() function.

How to properly handle the LUN g_pCmd structure member? Is LUN related to disk partitions?

Best Regards,

Alessandro

1,696 Views
isaacavila
NXP Employee
NXP Employee

Hello Alessandro,

About your questions:

Is LUN related to disk partitions?

It is not related with disk partitions. If the LUN is 2, the device will have two mediums, it seems there are two devices. Host can operate one with LUN = 0 and operates another with LUN = 1.

How to properly handle the LUN g_pCmd strcuture member?

Current structure in example (twrk65f180m_host_msd_fatfs_mqx example) does not allow to use another LUN value rather than 0. However, if you would like to use LUN 1 for USB disk, you will need to apply next patch. (Please, notice that some devices do not support LUN = 1, that is why it was set to 0).

Attached patch (msd_fat_demo.c) illustrates all changes requiered in this example in order to use LUN value different to 0 (in example, LUN value is set to 1 as USB definition).

Remember to change USB value (in diskio.h) as follow:

/* Definitions of physical drive number for each media */

#define USB                                             1

#define SD                                              0

I hope this can help you to understand all places where LUN value is used.

Best Regards,

Isaac

----------------------------------------------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------------------------------------------

0 Kudos

1,696 Views
Vagni
Contributor IV

Sorry Isaac,

I don't know how to apply the msd_fat_demo.patch file to the msd_fat_demo.c file ...

Should I have installed and lunch some patch tool in my KDS and/or KSDK folders?

Best Regards,

Alessandro

0 Kudos

1,696 Views
antonioconcio
NXP Employee
NXP Employee

Ciao Alessandro,

As you are using KDS IDE that is Eclipse based, here below the steps to apply patches to code:

  1. Menu Window > Open Perspective > Team Synchronizing
  2. Open the patch file, select all text and copy it to clipboard (Ctrl+ C)
  3. Menu > Project > Apply Patch... (or simply Ctrl + V)
  4. Select clipboard and click next (not needed if you used the Ctrl + V way), select the file you want to patch (msd_fat_demo.c into sources folder), click next and then finish.

Let us know if that fixed the issue,

Antonio