2024-11-06 11:05 PM - edited 2024-11-07 05:29 PM
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
Solved! Go to Solution.
2024-11-15 05:30 AM - edited 2024-11-15 05:31 AM
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.
2024-11-07 09:41 AM
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.
2024-11-07 06:00 PM
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.
2024-11-07 08:47 PM - edited 2024-11-07 08:49 PM
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
2024-11-08 12:26 AM - edited 2024-11-08 02:07 AM
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.
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
2024-11-15 05:30 AM - edited 2024-11-15 05:31 AM
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.
2024-11-18 07:27 PM - edited 2024-11-20 10:41 PM
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