adafruit / Adafruit_SPIFlash

Arduino library for external (Q)SPI flash device
MIT License
162 stars 86 forks source link

Release 3.0.0 examples fail on Metro M4 Express, but 2.0.2 examples work just fine #14

Closed microscope closed 5 years ago

microscope commented 5 years ago

As posted on https://forums.adafruit.com/viewtopic.php?f=63&t=154063:

With the latest version 3.0.0 of the Adafruit_SPIFlash library, I am having trouble getting the QSPI flash to work with Arduino on both my Metro M0 Express and Metro M4 Express boards:

It does not seem to be a hardware issue: I can restore the QSPI flash as CIRCUITPY drive for use with CircuitPython by double-clicking the reset button to enter the UF2 boot loader and dragging the appropriate file (today adafruit-circuitpython-metro_m4_express-en_US-4.0.2.uf) onto the METROBOOT drive.

Libraries are up-to-date:

After some further digging ....

With version 2.0.2 from https://github.com/adafruit/Adafruit_SP ... /tag/2.0.2, all the important examples work with my Metro M4 Express board: fatfs_circuitpython, fatfs_datalogging, fatfs_format, fatfs_full_usage, fatfs_print_file, flash_erase, and flash_erase_express. (SPI_Flash_Manipulator fails looking for an SD card, which I don't have; I didn't try circuitpython_backupFiles).

Since 2.0.2 is deprecated, I'd rather get 3.0.0 to work (or help with getting it to work), but I am not sure where to start.

Thanks,

microscope

ladyada commented 5 years ago

yeah we did a bunch of refactoring (for good reason and also its way better now) but we are still fixing up stuff. @hathach please take a look :)

hathach commented 5 years ago

Just tested with Metro M0 and M4, it still works here. @microscope can you download the current master of https://github.com/adafruit/SdFat as zip and replace your local library. If the sketches still fails, try to enable SdFat DEBUG_MODE here to 1 and post your serial output here. https://github.com/adafruit/SdFat/blob/master/src/FatLib/FatVolume.h#L38

microscope commented 5 years ago

@hathach - In short, no joy.

So I am stumped.

hathach commented 5 years ago

@microscope thank you for your detail information, I am able to reproduce the issue after running the flash_erase_express example which erase the whole chip. Troubleshooting it now.

UPDATE: look like SdFat's wipe only erase existing system, and doesn't create a new one filesystem if not existed.

ChristieLeeEMT commented 5 years ago

yeah we did a bunch of refactoring (for good reason and also its way better now) but we are still fixing up stuff. @hathach please take a look :)

So, is this why I'm getting the below errors? Suddenly my Hallowing isn't running the full test code at all. I tried to run the SDFat sketches that @microscope did, and they all failed with the same error.

Arduino: 1.8.9 (Windows 10), Board: "Adafruit Hallowing M0, Arduino, Off"

In file included from C:\Users\Lisa\Documents\Hocus Pocus\Software\hallowing_full_test\full_test\full_test.ino:16:0:

C:\Users\Lisa\Documents\Arduino\libraries\Adafruit_SPIFlash\src/Adafruit_SPIFlash.h:39:4: error: #error ENABLE_EXTENDED_TRANSFER_CLASS must be set to 1 in SdFat SdFatConfig.h

error ENABLE_EXTENDED_TRANSFER_CLASS must be set to 1 in SdFat SdFatConfig.h

^

C:\Users\Lisa\Documents\Arduino\libraries\Adafruit_SPIFlash\src/Adafruit_SPIFlash.h:43:4: error: #error FAT12_SUPPORT must be set to 1 in SdFat SdFatConfig.h

error FAT12_SUPPORT must be set to 1 in SdFat SdFatConfig.h

^

exit status 1 Error compiling for board Adafruit Hallowing M0.

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

microscope commented 5 years ago

@ChristieLeeEMT: The errors you describe are a different issue (failure to compile) and easy to fix - as the messages say, you need to edit two lines (change 0 to 1) in the SdFatConfig.h file of the SDFat library installed on your system. I also got these errors early on when I used the SdFat library from its original creator (https://github.com/greiman/SdFat). But the Adafruit fork of the SdFat library (https://github.com/adafruit/SdFat) has these changes already incorporated.

Making these changes or using the Adafruit fork of the SdFat library allowed me to successfully compile the examples from the SPIFlash 3.0.0/1 library. But the examples still failed to run, as describe above.

S2Doc commented 5 years ago

Same problem and same results as @microscope using an M4 Feather Express. Of the example code: Compiles and appears to work: flash_erase

Compiles but give errors (as reported by @microscope above): flash_manipulator SDFat_full_usage SDFat_ReadWrite SDFat_datalogging SDFat_print_file

ChristieLeeEMT commented 5 years ago

@microscope I'll have to try the Adafruit version. BUT, when I got the board 2 weeks ago, I didn't include any sdfat libraries, and the full test compiled and ran. The only thing I had a problem with was sound. I got a mini speaker (cuz I was told I needed one for sound), and when I tried it again, the compiler was asking for sdfat.

ChristieLeeEMT commented 5 years ago

@microscope I tried the Adafruit SDFat, and NG. I no longer have SDFat errors, but now it didn't recognize any of the calls to SPIFlash. Backing up to Adafruit SPIFlash v2.0.2 (even without SDFat), it's working again. TY for the help.

hathach commented 5 years ago

@microscope It should be fixed by PR #15 . It is kind of complicated and take more time than expected to troubleshoot. Short story: SdFat is not fully support FAT12. Its library only provide an formatter example for FAT16/FAT32 but FAT12. I have to use the good old f_mkfs() from Elm Chan's fatfs for SdFat_format example.

To make thing worst, SdFat insist number of FAT table must be 2, while by default f_mkfs() only create 1 FAT https://github.com/greiman/SdFat/blob/master/src/FatLib/FatVolume.cpp#L490

Anyway, please try to run SdFat_format example in the PR, once it is probably formatted, it should work well as before. When you could verify it works. We can merge and release it :)

hathach commented 5 years ago

Note: This issue only occurs if you erased the flash contents with flash_erase/flash_erase_express and haven't formatted it with appropriate disk management like windows/linux via USB MSC external flash example sketch.

Since Circuitpython also format using f_mkfs() with 1 FAT table, it also didn't help with SdFat insisting with 2 FAT

microscope commented 5 years ago

@hathach: It all works now!

Thank you so much for fixing this!

hathach commented 5 years ago

For my edification: You talk about "appropriate disk management like windows/linux via USB MSC external flash example sketch." Is this another, non-Arduino-based tool that could be used instead of the now fixed SdFat_format example to format the QSPI flash? Where do I find that?

this sketch example will expose qspi flash as USB Mass Storage, you could then format it with windows/Linux by right click on the disk

hathach commented 5 years ago

UPDATE: we have changed the SdFat code to support bot 1 and 2 FAT tables. Once both of these PR is merged and release, things will work in harmony ( with circuitpython ) and existing board without running through SdFat_format. Thank you very much you all for reporting this issue.

https://github.com/adafruit/SdFat/pull/3 https://github.com/adafruit/Adafruit_SPIFlash/pull/16

microscope commented 5 years ago

@hathach @ladyada : Glad to be able to contribute a tiny bit. I greatly value Adafruit's tutorials and libraries--that's why I have been a customer for more than a decade. Cheers!