-
Notifications
You must be signed in to change notification settings - Fork 802
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
lfs_cache_prog: assert(pcache->block == 0xffffffff) #12
Comments
To add more information, I observe that every time I see this assert, just before it was in "fill with 0" behavior in lfs_file_write |
Hi @guillaumerems, That assert means that littlefs tried to reuse a program cache that wasn't written out yet. It is most likely a bug in littlefs. What file operations led to this failure? You mentioned "fill with zeros", are you referring to this line? Did you seek past the end of the file to fill it with zeros? Some other info that would help: What is your block device's geometry? (read size, program size, erase size) and compiler+arch? Thanks for reporting |
Exactly it is this line, I added a log when fill with zero happen and when it happens, I have the assert right after. My configuration is the following:
The processor is a Cortex-M4 (STM32L4), the Flash is a NOR Flash (512Mbits) |
A few other questions:
There were two fixes that went in recently related to seek (aea3d3d) and non-powers-of-2 block counts (425aa3c). So it may be worth trying to update to the current master. |
No seek, no truncate I will continue the test to see when a fill to zero can happen because it does not happen all the time |
What flags do you pass to The fill to zero should only happen when you seek past the end of a file and write data. So something must be going wrong inside littlefs. You're not calling littlefs from multiple threads are you? (or from interrupts) Another possibility is that the ctz/popc intrinsics aren't being emitted correctly by the compiler, though I would be surprised on gcc, since I've been using gcc for a while without issues. You could try replacing the intrinsics in static inline uint32_t lfs_ctz(uint32_t a) {
uint32_t r = 32;
a &= -a;
if (a) r -= 1;
if (a & 0x0000ffff) r -= 16;
if (a & 0x00ff00ff) r -= 8;
if (a & 0x0f0f0f0f) r -= 4;
if (a & 0x33333333) r -= 2;
if (a & 0x55555555) r -= 1;
return r;
}
static inline uint32_t lfs_npw2(uint32_t a) {
uint32_t r = 0;
uint32_t s;
s = (a > 0xffff) << 4; a >>= s; r |= s;
s = (a > 0xff ) << 3; a >>= s; r |= s;
s = (a > 0xf ) << 2; a >>= s; r |= s;
s = (a > 0x3 ) << 1; a >>= s; r |= s;
return r | (a >> 1);
}
static inline uint32_t lfs_popc(uint32_t a) {
a = a - ((a >> 1) & 0x55555555);
a = (a & 0x33333333) + ((a >> 2) & 0x33333333);
return (((a + (a >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24;
} |
I open the file in a+ for append. I am under preemptive FreeRTOS so yes the functions could be called from several thread, but I have a littlefs_hal on top of it with a mutex implementation to prevent several thread calling the function I will try the function lfs_ctz / lfs_npw2 / lfs_popc |
Hi @guillaumerems, do you know if this could have been fixed by #12? I haven't been able to put together a reproducible case for this yet, so sorry I don't have more info here. |
Hi,
I see sometimes this ASSERT, is there a way to recover when it happens and understand when this could happen ?
Thanks
The text was updated successfully, but these errors were encountered: