Hello,
I am working on an application that requires saving a large amount of data onto a NOR flash. We have a custom board using an NRF52840 and a Winbond 2G-Bit NOR flash.
I am trying to mount a file system to the NOR to be able to save files to it, and then switch to a USB mass storage mode for offloading. These issues pertain to both modes of operation. While LittleFS would be preferred, I have only been able to get FAT working with some significant problems. After long periods of data collection, the filesystem corrupts and I seem to lose all data on the file system. I suspect this could potentially be due to 24-bit addressing on the NOR. To utilize 2Gigabits of NOR, 32 bit addressing would be required, but enabling address-size-32 in the boards .dts prevents the file system from mounting. Specifically I run into the following error code:
00> [00:00:00.004,150] <inf> flashdisk: Initialize device NAND 00> [00:00:00.004,150] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 2147483648 ... 00> [00:00:01.114,501] <inf> StorageLib: Area 0 at 0x0 on w25q02jv@0 for 2147483648 bytes 00> [00:00:01.114,501] <inf> StorageLib: Setup Flash completed successfully 00> [00:00:01.114,562] <inf> flashdisk: Initialize device NAND 00> [00:00:01.114,593] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 2147483648 00> [00:00:02.192,596] <inf> flashdisk: Initialize device NAND 00> [00:00:02.192,626] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 2147483648 00> [00:00:03.408,508] <inf> flashdisk: Initialize device NAND 00> [00:00:03.408,538] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 2147483648 00> [00:00:04.485,931] <err> fs: fs mount error (-19) 00> [00:00:04.485,961] <err> StorageLib: Failed to mount filesystem 00> [00:00:04.485,961] <err> StorageLib: Could not setup disk, -19
Removing address-size-32 does allow the system to mount and "work" for a limited period:
00> [00:00:00.004,150] <inf> flashdisk: Initialize device NAND 00> [00:00:00.004,150] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 2147483648 ... 00> [00:00:01.137,786] <inf> StorageLib: Area 0 at 0x0 on w25q02jv@0 for 2147483648 bytes 00> [00:00:01.137,786] <inf> StorageLib: Setup Flash completed successfully 00> [00:00:01.137,847] <inf> flashdisk: Initialize device NAND 00> [00:00:01.137,878] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 2147483648 00> [00:00:02.215,911] <inf> flashdisk: Initialize device NAND 00> [00:00:02.215,942] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 2147483648 00> [00:00:03.652,221] <inf> flashdisk: Initialize device NAND 00> [00:00:03.652,252] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 2147483648 00> [00:00:04.730,895] <inf> StorageLib: File System Mounted 00> [00:00:04.781,005] <inf> StorageLib: Mount /NAND:: 0 00> [00:00:04.831,146] <inf> StorageLib: /NAND:: bsize = 512 ; frsize = 32768 ; blocks = 65527 ; bfree = 65526 00> [00:00:04.831,207] <inf> StorageLib: /NAND: opendir: 0 00> [00:00:04.831,420] <inf> StorageLib: End of files
This is the overlay I am trying to use:
&qspi { status = "okay"; pinctrl-0 = <&qspi_default>; pinctrl-1 = <&qspi_sleep>; pinctrl-names = "default", "sleep"; w25q02jv: w25q02jv@0 { compatible = "nordic,qspi-nor"; reg = <0>; writeoc = "pp4o"; readoc = "read4io"; sck-frequency = <16000000>; jedec-id = [ef 70 22]; size-in-bytes = <2147483648>; has-dpd; t-enter-dpd = <20000>; t-exit-dpd = <20000>; quad-enable-requirements = "S2B1v1"; //address-size-32; }; }; &w25q02jv { partitions { compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; storage_partition: partition@0 { label = "storage"; reg = <0x00000000 0x80000000>; }; }; }; / { msc_disk0 { compatible = "zephyr,flash-disk"; partition = <&storage_partition>; disk-name = "NAND"; cache-size = <4096>; }; };
Weirdly, I don't believe the Quad enable requirement to be setup correctly. The flash I am using has a unique system for enabling quad mode. I don't believe the qspi-nor driver includes the necessary operation to enable quad mode on this nor. I chose "S2B1v1" through trial and error.
Attempting to use Little FS I run into similar mounting issues. Specifically I run into a "Little FS Corrupted dir pair at {0x1, 0x0}" error regardless of the address size setting. This error happens every time.
00> [00:00:00.063,110] <inf> littlefs: LittleFS version 2.5, disk version 2.0 00> [00:00:00.557,556] <inf> littlefs: FS at w25q02jv@0:0x0 is 524288 0x1000-byte blocks with 512 cycle 00> [00:00:00.557,586] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32 00> [00:00:00.558,013] <err> littlefs: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1234: Corrupted dir pair at {0x0, 0x1} 00> [00:00:00.558,013] <wrn> littlefs: can't mount (LFS -84); formatting 00> [00:00:00.761,596] <inf> littlefs: /lfs mounted 00> [00:00:00.811,676] <inf> StorageLib: Mount /lfs: 0 00> [00:00:00.812,164] <inf> StorageLib: /lfs: bsize = 16 ; frsize = 4096 ; blocks = 524288 ; bfree = 524286 00> [00:00:00.812,713] <inf> StorageLib: /lfs opendir: 0 00> 00> [00:00:00.813,171] <inf> StorageLib: End of files 00> 00> [00:00:00.813,201] <inf> StorageLib: The device is put in USB mass storage mode.
I understand this is a lot of weirdness without much direct code, so here are some specific questions:
- If I wanted to utilize the full 2gigabit size of the NOR, I would need to use a FAT32 fs and 32 bit addressing, right? Is there any issue with this combination?
- Is my setup for QSPI in the DTS correct for the nor I am using? Is there away to send specific commands to the NOR using the qspi-nor driver if the quad operation setting that my drive requires is not
Thank you for any help.
The datasheet for the flash can be found here: - Relevant info on page 12
https://www.mouser.com/datasheet/2/949/W25Q02JV_DTR_RevB_04192021-2329042.pdf
For main.c and library code I am pulling form the Mass storage example and LittleFS example. Running those directly gives the same error code.