2021-01-20 10:34 AM
I'm using a Nucleo F746ZG
The SPI is setup in RX only slave mode and uses DMA Double buffer mode. The data rate changes, but at max I should be writing right at 126 kBytes per second to the drive.
I'm using fatfs and USB driver with the cubemxide source code and slight modifications
2021-01-20 11:23 AM
You are logging to a USB MSC device, right?
2021-01-20 12:02 PM
Correct, the USB is acting as a mass storage host.
2021-01-20 03:56 PM
There is no guaranteed timing in any FLASH device with controller, such as USB "stick" or SD card (or SSD for that matter). They can do whatever they like and whenever they like. From time to time they may need to erase a block and that takes time.
JW
2021-01-20 10:32 PM
The problem writing to a flash based storage device is the non-deterministic latency built into the firmware of the storage device flash controller. At unpredictable intervals the internal flash drive must perform garbage collection, erasing deleted blocks to recover them for future use. Erasing flash blocks is very slow compared to a sector write.
To overcome this you need a separate task to manage data writes, with a data queue sufficient to buffer writes for however long the worst case latency is on the storage device (perhaps for several seconds). Your data collection task runs at a higher priority to ensure you don't drop data while an erase is in progress.
Jack Peacock