-
Notifications
You must be signed in to change notification settings - Fork 804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussion: littlefs on SPI NAND #11
Comments
Forgot to ask my question... will LittleFS work with such a memory? |
Hi @hchaudhary1, at the moment you may run into problems. LittleFS has only been used on NOR flash, eMMC, SD cards; devices with <4KB erase units, so I'm not sure how it will perform on NAND flash. Concerns:
At the moment, I think LittleFS might need a flash translation layer (FTL) to be efficient. An FTL would provide a smaller erase unit and prevent all of the issues, though you may still want to use LittleFS for power resilience. At the very least, LittleFS is probably better than putting FAT directly on top of raw NAND. If you do try to put LittleFS on a NAND chip, let me know how it goes! I'd be interested to know what sort of problems you run into. |
geky, thanks for elaborating on this My hope is to avoid using a fully featured FTL layer such as dhara (https://github.com/dlbeer/dhara), since fail-safety, wear-leveling, and bad-block-management are already built into littlefs...
I guess my main concern is what will happen to stale data that over several years develops more than 8-bits of errors. I supposed only static wear leveling can reduce this issue... Thanks. I will provide some feedback |
Ah interesting, that is a nice side effect of static wear leveling. Though I've heard that errors from stale data are less concerning on SLC NAND parts. Looking at the MT29F's datasheet, it only mentions concerns about write errors:
The same datasheet also lists a data retention of 10 years. I suspect that is in the case when the chip has no power, and may be the same for stale data. If you need longer data retention, you could probably increase the size of the ECC, though that may require software ECC. Although it may be a good idea to ask someone who's a better expert on NAND memory. |
implementation was a success! |
Ah! That is exciting! Thanks for the update. |
Hi, just to understand, does littleFS support NAND flash without any change? regards |
Yes, it supports NAND without modifications. EDIT: |
is there any example,how to use littlefs on spi nand? |
What is the status of LittleFS with NAND flash support? Any improvement? |
there isn't anyhting special about nand and lfs, same as NOR pretty much. blocks are larger, but that's it. |
NAND working well |
I have connected the littlefs to NAND flash too. 1gb SPI nand W25N01. It works too. FTL didn't connect yet, maybe I will connect it later. |
Hi, its good to see @hchaudhary1, @timandr made it work with NAND , i am also trying to add lfs to NAND based flash (winbond w25n01gv) with nrf52 but it gives mount error. lfs error:495: Corrupted dir pair at 0 1 i have added it without making any changes to the lfs, i have tested the read/write/erase functions and all are working fine. this is how my implementation looks like, const struct lfs_config cfg = {
}; these wrapper functions will call the spi based flash drivers. void init_littlefs(){
} I have also read somewhere that the SPI operations needs to be synchronous/blocking in order for lfs to work. as i have looked at the code lfc.c,
the read for srtuct test is all 0xff i can see only one write operation before it fails, which i have tried to read back and it gives some data (1,0,0,0,20,0,0,0). |
Post your read/write/erase/sync functions... also you lfs_config struct settings... |
flash details, page size 2048 minimum write = 1 byte |
i can't give my code, since it is closed source. Write in a test pattern (at a random offeset) with a large size, and read it back. Do this at multiple random starting blocks. once you can make that portion work, then everything should fall in place |
@hchaudhary1 thanks for the update, there was an issue with my spi driver while reading big blocks of code(limited dma size). now its working like a charm :) |
Thanks for all your information sharing, plan to test this myself next week. |
Thank you for the great work!!! It works for Windbond W25M02GWZEIT (SLC Nand SPI Flash, 2 Gbit) |
Hi hcChaudary/Joice,
Regards, |
@joicetm . Hi I am working on the same Winbond flash. Could you have some time to talk |
Hi visakh, 1, Not sure, the minimum value should be the chip block size 1024*64 FYI, LFS still have some performance issues on NAND flash as the number of files increases. |
@joicetm Hi Thanks Joice, Yes. I have given the actual block size (128 KiB - 2048*64). I have created a separate post where I have added my code for test. Can you please check over there. This I have pasted here as well, can you please review it. I have ported littlefs to my application and written wrapper functions for it to attach to the config structure (lfs_config). This wrapper function is tested individually by writing a test application that writes a 100byte buffer to all the 1024 blocks (each block 128 KB) start addresses(first column) and read back and compared. All is Success. But when I started to test with the example like in the littlefs readme.md mount error and format error has returned and finally hangs at fileopen(the next instruction). I can paste the test code here and config here, if someone have a clue please respond..... I expects a solution from @geky @geky // block device configuration ------------------------------Test code ------------------------- uint32_t FlashTest(void) { uint32_t err = lfs_mount(&lfs, &cfg); // reformat if we can't mount the filesystem // update boot count err= lfs_file_write(&lfs, &file, &boot_count, sizeof(boot_count)); if(err) // remember the storage is not updated until the file is closed successfully if(err) // release any resources we were using // print the boot count |
@joicetm . Hi @joicetm . lfs_trace:3603: lfs_mount(0x2001b484, 0x8022470 {.context=0, .read=0x8003d65, .p rog=0x8003d91, .erase=0x8003dbd, .sync=0x8003de3, .read_size=16, .prog_size=16, .block_size=131072, .block_count=1024, .block_cycles=500, .cache_size=16, .looka head_size=2048, .read_buffer=0, .prog_buffer=0, .lookahead_buffer=0, .name_max=0 , .file_max=0, .attr_max=0}) |
Make sure that your read/write/erase functions are working fine. |
@hchaudhary1 @geky Use below config is OK? .read_size = 2048, |
I believe LittleFS already has bad block management |
yes, the idea is that failing writes will be reallocated to a different block |
@hchaudhary1 @rojer Run code : Err info: |
I tested without bad blocks and it works fine |
i debug in lfs_format ,when call lfs_dir_compact, lfs_bd_erase(block 0) return LFS_ERR_CORRUPT,goto relocate run here return LFS_ERR_NOSPC; |
@geky @hchaudhary1 @rojer |
yeah, i guess when block 0 or 1, the superblocks, go bad, it's game over. fortunately, they don't get changed much, normally. |
Can you share the MT29F wrapper ? |
@zbqxyz and @hchaudhary1 Which nand (mt29f2g01abagdwb), it has 128 bytes per page. So I don't see and understand why you didn't include it in littlefs configuration. Without that it will calculate wrong physical block ? |
Hello, I am using LittleFs on a spi nand flash Micron, MT29F and it works very well. But now, I would like to improve write speed, if possible. I understand (tell me if I am wrong), that after every write, there is a read spi transfert, and a compare to check. Pleased find enclosed a timing:
But MT29F nand flash provide an 'uncorrected ECC error code' when it cannot correct read page. So I think that we just have to test the flag, no need to do a spi read transfert to check write. So we could avoid many read spi transferts. What do you think about this ? Thank you, best regards |
Hello,
Here was my config:
// minimum read and prog size operation
// if use ecc, only 4 'partial page programming' are allowed
// so size must be > PAGE_DATA_SIZE/4
// if not, ecc error bit remains high ...
#define LFS_SIZE_READ_PROG 1024
#define NUM_PAGE_BLOCK 64 /* Number of pages for block*/
const struct lfs_config cfg =
{
// block device operations
.read = read_littlefs_wrapper, .prog = write_littlefs_wrapper, .erase
=
erase_littlefs_wrapper, .sync = sync_littlefs_wrapper,
// block device configuration
.read_size = LFS_SIZE_READ_PROG,
.prog_size = LFS_SIZE_READ_PROG,
.block_size = PAGE_DATA_SIZE * NUM_PAGE_BLOCK,
.block_count = NUM_BLOCKS,
.lookahead_size = LFS_SIZE_READ_PROG,
// cache_size must be multiple of read_size
.cache_size = LFS_SIZE_READ_PROG,
// Set to -1 to disable block-level wear-leveling.
.block_cycles = -1
};
Is that what you expected ?
Le sam. 15 oct. 2022 à 05:28, Matt Mercaldo ***@***.***> a
écrit :
… Hello Jac666,
What was your config for the MT29F NAND chip?
Thanks!
—
Reply to this email directly, view it on GitHub
<#11 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI6ZODFOFCQUXCIGL5TYC5LWDIQHBANCNFSM4EMT3LFQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Perfect! Thanks so much! |
@joicetm I am wondering what SPI driver you are using? I am using the same Winbond NAND memory and can't find the driver that provides the functions your wrapper uses. Any help would be appreciated. Or if there are other drivers that would do the job that would be much appreciated. |
Update, if you contact Winbond they can provide you with an example driver that works on STM32 MCUs. |
Hello .I am using LittleFs on a spi nand flash in esp32s3. |
Hi, However, everything works perfectly when I utilize the LittleFS interfaces to access the NAND flash. [Partition configuration] [Application] static struct fs_mount_t lfs_mnt = { [Error messages] __device_dts_ord_98 corresponds to my spi flash driver I constructed my SPI NAND flash driver as an out-of-tree driver, considering that it might be the cause of the problem. |
wonderful discussion... |
Hi, I am also working on porting littlefs driver, on top of MT29. I am able to port the fs. Although while life testing, I am getting -84 error (i.e. LFS_ERR_CORRUPT) after I write around 210 files of 3K, and after that complete file system gets corrupted. So can anyone help me to understand the cause of error. My config struct is as follows: const struct lfs_config cfg = {
#ifdef LFS_THREADSAFE
}; |
I'll let the others speak up to correct me if i am wrong..
It looks like your configuration is not correct.
Read size is pretty high - you may want to think about tuning it to something smaller.
My running config is
read size - 16
prog size - 1024
cache size - 1024
lookahead - 16
block count - 2048
you have to be careful because the sizes are not bytes all the time.
Remember, the chip can only do 4 write operations before it needs to get refreshed to all FF as per the documentation on the chip.
There are some good notes in this blog overall about these value and what they should be.
You will also want to deep dive the amazing documentation created for littlefs.
… On 07/13/2023 7:18 AM EDT ParthJaiswal17 ***@***.***> wrote:
Hi,
I am also working on porting littlefs driver, on top of MT29. I am able to port the fs.
Although while life testing, I am getting -84 error (i.e. LFS_ERR_CORRUPT) after I write around 210 files of 3K, and after that complete file system gets corrupted.
So can anyone help me to understand the cause of error.
My config struct is as follows:
const struct lfs_config cfg = {
.context = NULL,
.read = lfsread,
.prog = lfsprog,
.erase = lfserase,
.sync = lfssync,
#ifdef LFS_THREADSAFE
.lock = sh_lfslock,
.unlock = sh_lfsunlock,
#endif
.read_size = 4096,
.prog_size = 4096,
.block_size = 4096,
.block_count = 262144,
.block_cycles = 512,
.cache_size = 4096,
.lookahead_size = 4096,
};
—
Reply to this email directly, view it on GitHub #11 (comment), or unsubscribe https://github.com/notifications/unsubscribe-auth/AQAXUR2QSIS3HN6Q5TRYFA3XP7KQTANCNFSM4EMT3LFQ.
You are receiving this because you commented.Message ID: ***@***.***>
|
Hi mattmercaldo, Thank you for the advice, although if decrease the prog size to 1024, I get ecc error during read, also if reduce read size I am getting error while reading file number 32, must be metadeta issue. Although the update is I have resolved the Issue by Increasing the block size to actual block size of MT29 flash which is 256KB and now it is working well, but with the cost of low speed. Thank you. |
Hello @hchaudhary1 |
Trying to get littleFS running on w25m02gw SPI NAND, So far it seem to be working okay, with ability to write multiple file, read back and confirm data..etc. .read_size/.prog_size is 2048 bytes(page size), and .erase_size is 64 x page size(128KB) @hchaudhary1 Any guess Why I am seeing frequent block erases.. on every 4K write? It appears like its starting on a new block on every write. More details here - #905 |
Hi all, |
I am also working on the MT29F (2Gb version). How did you handle the max 4 partial page writes? Did lfs handle this or did you keep track of and manage this yourself? |
Hi I would like to use LittleFS directly on a NAND chip, such as Micron MT29F.
The minimum erasable unit on the MT29F is 128KiB
The smallest writable unit is 2KiB (random write)
The smallest writable unit is 1 byte (sequential write)
Thanks
The text was updated successfully, but these errors were encountered: