Are you writing the FLASH device within the ISR? I went around this a while ago and posted loads here
e.g.
https://www.eevblog.com/forum/microcontrollers/cleanest-way-to-block-usb-interrupts/The simplest way to implement FatFS / USB MSC is to do the whole FLASH write inside the ISR so that ISR may hold up lower priority stuff for the write time which might be say 15ms! But apparently (see the various threads of mine) this is what SD cards do and it is the max compatibility mode.
The "proper solution" is to write a "driver" for the FLASH (or equiv) so that the USB MSC ISR is short, but this is really hard unless you have tons of RAM for caching writes, or you return a Busy state to the Host so it keeps retrying (which is poorly documented and often doesn't work).
are you using FatFS at the same time as the host is connected via USB? If so, then this is not something that would ever work.
Why not?
The USB MSC stuff is done in the USB ISR. The Host (Windows usually) just sees a block device, 512 byte blocks (best done with a FLASH which actually has 512 byte blocks, obviously, but you can do blocking/deblocking as in hard disks) and knows nothing about the embedded code.
The internal filesystem access is done with FatFS which provides the embedded code with a file-based "view" of the block device. Usually FAT12 unless you have 8MB or more, IIRC, and then FAT16.
There will always be things to watch if both internal code and USB MSC are active concurrently, but there are ways to handle that. These are notes from my project manual:
====
The 2MB FAT filesystem is accessible to both a user application program running in the XXX and via USB as a removable mass storage media visible to the USB Host (Windows etc).
Read speed varies from 300kbytes/sec to 2Mbytes/sec, depending on various factors. Write speed is around 30kbytes/sec - the FLASH programming speed.
File System LimitationsThe 4MB FLASH device has an endurance of 100k writes, on a per-byte basis. The FAT directory area is written on every file write and this thus gets the most wear. Care must therefore be exercised when writing code which does file write operations. There is no limit on reading operations since no "last-accessed" timestamp gets written - FAT12/FAT16 file systems have only the "last-modified" timestamp.
Only "8.3" filenames (names in the format xxxxxxxx.xxx) are supported e.g.
filename.txt
file1.txt
f.a
but not filename2.txt3 because >8 or >3 in the filename and the extension, respectively, are not allowed. Wiki article:
https://en.wikipedia.org/wiki/8.3_filenameHowever, nothing stops a USB Host (e.g. Windows) creating whatever filenames and directory structures it is able to according to its own operating system limitations. Within the FAT12 drive it can create more or less anything. If the Host creates a non-8.3 filename, it will be visible to user code under its 8.3 alternate filename which the Host must create, by convention.
All files accessible to user code must be in the root of the drive. Subdirectories (folders) are not supported. If a USB Host creates a subdirectory, this will not be accessible to user code although its name will be visible to the get_file_list() and get_file_properties() functions.
Host Operating System Caching issuesIt is important to realise that the USB Host sees the 2MB of FLASH as no more than a number of 512 byte sectors representing a FAT12 removable storage device, which it owns entirely. It can perform whatever operations it wants to in there, without regard to whether the XXX internal software understands it. The XXX system software is viewing this 2MB FLASH block from the other side and uses the FatFS embedded filesystem module
http://elm-chan.org/fsw/ff/00index_e.htmlto interpret the data as a FAT12 filesystem.
Looking at this in the opposite direction (XXX to USB Host), files created or modified by the XXX do not immediately become visible to the USB Host. This is due to Host operating system architecture; for example Windows assumes nobody else is changing the data on a removable drive, and almost never checks for changes. It checks if it detects that the media has been removed or mounted. See file_usb_eject() and file_usb_insert() functions on how to make XXX file changes visible to the USB Host.
Files created or modified by the USB Host should become visible to XXX code immediately, assuming the data is actually written and the directory updated. This does not always happen because the OS may not flush the data to the USB drive. This was particularly true for older versions of Windows (before winXP).
Filenames are not case-sensitive. All filenames created by user applications are converted to uppercase.
The FLASH device used for the filesystem implements a per-sector pre-read on writes and performs the write only if the data is different. This increases the write speed by around 50x if the data has not changed. It can sometimes appear confusing in that a file writes extremely fast; this is because is has not been changed, or only a few bytes were changed! This is sometimes visible with XXX firmware updates.
====
My FatFS build was for 8.33 only, no LFN, and there were complicated reasons for that related to RTOS usage. Frankly no embedded code needs LFN anyway
There are ways to do a concurrent access filesystem but not with a removable USB device profile. You need to implement an ethernet storage device, IIRC, like a Synology network drive.