Fix LittleFS formatting freeze bug #98
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.