Skip to content

Commit c0761da

Browse files
authored
Fix LittleFS formatting freeze bug
LittleFileSystem::reformat() on the SD Card block device internally runs LittleFileSystem::format() and then LittleFileSystem::mount() in a sequence. After LittleFileSystem::format()'s main job is performed using the LittleFS file system driver one level below it, it runs deinit() on the block device. That leads, after a series of calls, to a call to the Renesas FSP function R_SDHI_Close(), which sets the initialized field of the ctrl structure to false. LittleFileSystem::mount() runs next, and begins by running init() on the block device, but because it's still in a state where card_inserted and initialized are true, full initialization doesn't occur - only parts of it. This leaves the initialized field of the ctrl structure being false, which leads to the FSP-internal function r_sdhi_common_error_check() returning an error when it's called by the FSP function R_SDHI_Read() from SDCardBlockDevice::read(), which is, in turn, called from LittleFileSystem::mount(). This is caught by the LittleFS file system driver function lfs_bd_read() at the layer directly over the SDCardBlockDevice::read() function, which, in turn, sends the board into an infinite loop and the format freezes.
1 parent 1c9b086 commit c0761da

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

libraries/BlockDevices/SDCardBlockDevice.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ int SDCardBlockDevice::close() {
346346
fsp_err_t rv = FSP_ERR_INVALID_ADDRESS;
347347
rv = R_SDHI_Close (&ctrl);
348348
opened = false;
349+
card_inserted = false;
350+
initialized = false;
349351
return (int)rv;
350352
}
351353

0 commit comments

Comments
 (0)