Cannot f_mount() even though f_mkfs()
Closed this issue · 19 comments
Hello Mr. Andrew
Firstly, thank you very much for this source code which helps me a lot. In my case, I also use STM32 and Micron NAND flash, they work ok with I/O SPI interface between STM32 and NAND flash but when I cannot f_mount() even though I use f_mkfs() like your code. Can you help me with my situation and have you tried using f_write and f_read with this code? Thank you.
Lines 54 to 90 in 6a187bf
Hi, I am also encountered this same issue, may I know have you resolved this issue finally?
@TatChung68 apologies for not responding to this, I must have missed the email notification from GitHub. Yes, I was able to use f_write and f_read successfully to verify the contents of the file system.
@solosky An error code of 13 from fatfs indicates no file system is present (https://github.com/aloebs29/flash_management/blob/master/src/fatfs/ff.h#L290C2-L290C60). This is expected the first time you run the program, but after f_mkfs
is called (and your log shows that it succeeded), you should no longer see this error. This probably indicates that there is some issue in the lower level SPI NAND driver.
I would try commenting out the entire block that attempts to mount the filesystem in main.c
(https://github.com/aloebs29/flash_management/blob/master/src/main.c#L54-L89), and then test some of the low level flash operations (erase block, write page, read page, etc.) with the shell commands.
Hi @TatChung68, are you running Littlefs on NAND flash directly? does you use dhara FTL layer?
Anyway, I will continue address this issue and try to find what's going wrong.
The example provided by @aloebs29 should be straightforward. I am using MT29F2G01ABAFDWB which have 2G bits and extra plane selection should be sent to chip before program and read operation, but I have done the modification to adopt it.
The dhara layer did not report any error so I think the port should be fine without issue, but why the fatfs is not working is still need further invertigation.
Dear @solosky, LittleFS doesn't need Dhara or any ftl software layer, it's working well on nand/nor flash. So in my project, I'm using it.
Of course, we must set the plane bit to choose the plane (according to datasheet) before read/write. If you have tendency to use littlefs and face problem, you can can contact me via my email!!!
Hi @BadboyIntheLoop , I prefer to run fatfs on Nand flash, because we could use USB MSC device to connect PC managing file directly.
Other wearer leveling file system (e.g. littlefs, spiffs) cannot direct port to PC via USB MSC, instead, MTP protocol should be implemented for those filesystems if you would expect could manage files in PC. But the MTP protocol don't have a good opensource implementation yet.
Yes, FAT32 file can be read by PC. Keep trying more and more. I hope you can port successfully fatfs with dhara on this nand flash!!!
I will let you know if I have any progress on this.
Update:
with more log record, I find some thing intresting as bellow.
In mkfs call, I found the logic sector 63 data is written to nand page 800
disk wr: 63
nand: rd 799,1868,132
nand: rd 799,812,132
nand: wr 800,0,2048
but in mount call, the dhara mapping the sector 63 to nand page 870.
disk rd: 63
nand: rd 879,1868,132
nand: rd 879,812,132
nand: rd 870,0,2048
crc mismatch: sector=63, prev=23452, new=7504
f_mount failed, result: 13.
Appanrently, there should be a wrong mapping from logic sector to nand page.
I still dont know where did wrong.
Did you confirm the raw write/read/erase operations are working? I only provide a write operation that repeats a value across an entire page, but you could probably hack it to write a test pattern instead: https://github.com/aloebs29/flash_management/blob/master/src/modules/shell_cmd.c#L155
Hi @aloebs29, I think have done a simple test about the write/read/erase manually, but I will try to write more test case to check if the nand operation works correctly.
Dear @solosky,
I could confuse you but driver mr.aloebs29 write working well on littlefs!!! When I had been trying dhara, I also face the similar issue you posted above. After f_mkfs(), it writes lots of blocks in nand, f_write() and f_read() can run but these function don't working properly. I don't think that problem is in nand driver or porting layer between fatfs and nand; perhaps it lied on dhara layer. So, firstly, I think you should try turning off ecc on this nand flash and test nand driver properly, then continue test!
HI @BadboyIntheLoop, thank for your hit and I will try your suggestion later today.
Yeah, I am very familiar with Littlefs and I could port to Nand Flash if dhara goes to dead end.
But first of all, I would like to run Fatfs on nand because the USB MSC driver can work with FATTS seamless.
Even if the dhara layer works perfect, I would like try Fatfs on nor flash well!
Tested nand layer and dhara layer, seems all good, no progress today.
Anyway, I have push my code to https://github.com/solosky/flash_management for your reference.
I had a similar use case when I wrote this -- I needed a USB MSC interface to my device. I had adapted this code for a [previous] employer and didn't have any issues with it. Unfortunately I don't have the hardware anymore, otherwise it'd probably be useful for me to run the program with the extra logs you enabled so we could compare output.
Another thing that may be worth trying is erasing the entire flash (or trying with a new flash chip if you have multiple), as dhara may be resuming based on bad data that was written to the device during your initial testing.
Hi team, I have made FATFS working perfect via dhara over NAND flash!!
Quickly tested basic FATFS functions and it works well.
The problem is the copy implementation for NAND flash that has multiple planes (Like MT29F2G01ABAGDWB I am using)
If the src and dest are in same plane, the current implementation works fine, but it will faill if they are not in the same plane.
The solution is read out and write back, and it solves my problem.
Anyway, I commited my implmentation here and add lots of test command. (I think it only works for 2 plane NAND flash, but it could port to other NAND flash as well)
Good work -- glad to hear you got everything working