USB MSC how to read file from sketch after host write? #245
Unanswered
DisasterAreaDesigns
asked this question in
Q&A
Replies: 1 comment 2 replies
-
it could be the cache issue, both device and host cache the data. One cache assume that other does not change and can cause mis-interpreter of the data. PC Host <-> cache <-> USB <-> SDfat Cache <-> Sketch. You can clear cache on SDfat if lba of written blocks matches the caching of SdFat. However, the other way around is not easy, there is no easy way to force PC Host to clear its cache. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, all. I'm having some issues with an application based on the TinyUSB msc_external_flash and SPIFlash/SdFat_print_file examples. Hardware is a Raspberry Pi Pico, running the standard Arduino Pico core. I'm using the latest versions of all the libraries that are used (TinyUSB, SDFat, SPIFlash.) Note: I also posted this on the Adafruit forums so far without reply. If I can figure this out I'll post answers in both places to help others in future.
I can write files to the flash from host over USB, and I can read them back to the host. The files are identical on read and write, so that suggests to me that the TinyUSB part of the code is working correctly.
But if I try to read the contents of the file from inside the sketch, I'm having some issues. If I put the file on the flash and then reboot the Pi Pico, the file contents read correctly 100% of the time. If I write the file to the flash while the program is running, the file read fails after 512 or 1024 bytes.
If I write the file first and then read (correct and expected result)
If I write the file while the program is running (unexpected and incorrect result)
The program can see the file size correctly in both cases, but reading out the file results in invalid results if the file is read after write without restarting the program. I'm okay with restarting the application, or whatever is necessary, as long as it doesn't eject the volume from the host OS. How does CircuitPython handle this? It seems to restart cleanly after a file is saved on the disk and it always reads correctly.
Frustratingly, sometimes this all actually works, and I get all 1488 bytes read. Sometimes I only get 512 bytes read. But the file always copies correctly, if I read it back it's identical to the source. And if I restart the Pico with the file already in flash, the results are correct. Both good and bad results are showing me 1488 bytes in the file, but the bad reads only get part of the result before it chokes and gives me an error.
What am I doing wrong here? The file is copying correctly, all the MSC stuff seems to be working fine. I think the issue might be with the SDFatLib, but this is my first time using it and so I'm not sure where to start looking to debug this.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions