cancel
Showing results for 
Search instead for 
Did you mean: 

"Please insert a disk into USB Drive" USBX MSC+FILEX+LVLX+THREADX

Silexman
Associate III

I am working on a project to connect QSPI flash memory to a PC as a USB mass storage device (MSC) using USBX, FILEX, LVLX, and THREADX on an STM32. This setup should allow the QSPI flash to appear as a drive in Windows.

Previously, I successfully implemented a similar project using the MCU's internal RAM as the storage medium. However, after switching to QSPI flash, I encounter the error message: 'Please insert a disk into USB Drive' when connecting the device to a PC.

To debug this issue, I tested the QSPI flash read/write functionality using FILEX + LVLX + THREADX without USBX, and it worked perfectly. This suggests the problem lies in the integration with USB MSC.

I am including my code for review. Could anyone help identify any potential errors or missing steps in my implementation? Additionally, are there specific areas I should focus on to resolve this issue? Thank you.

EDIT :

lastlba ux_device_msc.c

1 ACCEPTED SOLUTION

Accepted Solutions
Haithem Rahmani
ST Employee

Hi @Silexman 

when working with USBX Device MSC class what ever the storage media is (uSD, NOR Flash) you should not use the FileX API because the logic of the filesystem is managed by the Host, the PC for example.

so you'll need to access the NOR Flash via LEVELX API.it will manage the wearleveling and the mapping between logic sectors for the Host request and the respective physical block.

 

regards

Haithem.

View solution in original post

6 REPLIES 6
FBL
ST Employee

Hi @Silexman 

AFAIK, no direct example, you can start with the example using LevelX FileX. Then, customize usbx_device_mass_storage  example using FileX After that you can simply use the example of MSC device. So, you can properly connect external flash memory to a PC as a USB mass storage device.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!

Halo, @FBL . Thank you for the response.

I followed your instructions. First, I created a project using LevelX and FileX as in the example you mentioned, formatting the nor flash to 512 bytes per sector. Then, I integrated it with USBX MSC, as per your suggestion. However, when the flash was formatted to 512 bytes per sector, a hard fault occurred upon connecting the USB to a PC. After reformatting to 2048 bytes per sector, the hard fault was resolved, but I now encounter a 'Please insert a disk into USB Drive' notification.

Screenshot 2024-11-08 085908.png

 

If the SCSI Inquiry or Sense Codes indicate the media not being present.

Or it's not formatted properly. For a File System to work your block read/write methods need to WORK, and flawlessly return the data patterns written previously. Otherwise all bets are off..

I seriously double 512 to 2048 bytes sectors will work without a lot of effort.

The QSPI NOR Flash likely needs a 4K sector as this is the minimum erase block/page size, and the only things that's reasonably easy to manage.

 

With FATFS we'd use f_mkfs() to preformat new QSPI instances before FIRST USE

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Halo @Tesla DeLorean , thank you for the reply

I tried read/write operations again using FileX+LevelX+ThreadX as in this example project, formatting the media to 4096 bytes per sector, and the read results matched what was written earlier. I also checked the media using fx_media_check, and the result showed no errors on the media.

Screenshot 2024-11-08 151224.png

Additionally, I changed the media format to 4096 bytes per sector in the USB MSC project. I also checked the media through Disk Management in Windows with the following results. Still not working so far

Screenshot 2024-11-08 151027.png

 

 

Haithem Rahmani
ST Employee

Hi @Silexman 

when working with USBX Device MSC class what ever the storage media is (uSD, NOR Flash) you should not use the FileX API because the logic of the filesystem is managed by the Host, the PC for example.

so you'll need to access the NOR Flash via LEVELX API.it will manage the wearleveling and the mapping between logic sectors for the Host request and the respective physical block.

 

regards

Haithem.

Halo @Haithem Rahmani Thank you for the replay.

After I accessed it using LevelX, the USB MSC feature didn’t work initially. However, after formatting it using the formatting tool in Windows, the USB MSC started working, and I could read and write files. The problem is, whenever I unplug the USB—whether the device is powered or not—the files I saved become corrupted. What steps should I take to identify and resolve this issue?

edit : after I changed the sectore size to 512 bytes, the issue is gone