Skip to content

Commit

Permalink
AP_Logger: nuance minspace for W25NXX and W25QXX
Browse files Browse the repository at this point in the history
  • Loading branch information
andyp1per committed Dec 13, 2024
1 parent 31f101a commit 613bdca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
8 changes: 6 additions & 2 deletions libraries/AP_Logger/AP_Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ extern const AP_HAL::HAL& hal;

#ifndef HAL_LOGGER_MIN_MB_FREE
#if AP_FILESYSTEM_LITTLEFS_ENABLED
#define HAL_LOGGER_MIN_MB_FREE 1
#if AP_FILESYSTEM_LITTLEFS_FLASH_TYPE == AP_FILESYSTEM_FLASH_W25NXX
#define HAL_LOGGER_MIN_MB_FREE 10
#else
#define HAL_LOGGER_MIN_MB_FREE 2
#endif
#else
#define HAL_LOGGER_MIN_MB_FREE 500
#endif
Expand Down Expand Up @@ -143,7 +147,7 @@ const AP_Param::GroupInfo AP_Logger::var_info[] = {
// @DisplayName: Old logs on the SD card will be deleted to maintain this amount of free space
// @Description: Set this such that the free space is larger than your largest typical flight log
// @Units: MB
// @Range: 10 1000
// @Range: 2 1000
// @User: Standard
AP_GROUPINFO("_FILE_MB_FREE", 7, AP_Logger, _params.min_MB_free, HAL_LOGGER_MIN_MB_FREE),

Expand Down
12 changes: 10 additions & 2 deletions libraries/AP_Logger/AP_Logger_File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,14 +1011,22 @@ void AP_Logger_File::io_timer(void)
_writebuf.advance(nwritten);

/*
fsync on littlefs is extremely expensive (20% CPU on an H7) and not
required since the whole point of the filesystem is to avoid corruption
fsync on littlefs is extremely expensive (20% CPU on an H7) particularly because the
COW architecture can mean you end up copying a load of blocks. instead try and only sync
at the end of a block to avoid copying and minimise CPU. fsync is needed for the file
metadata (including size) to be updated
*/
#if CONFIG_HAL_BOARD != HAL_BOARD_SITL && CONFIG_HAL_BOARD_SUBTYPE != HAL_BOARD_SUBTYPE_LINUX_NONE
#if AP_FILESYSTEM_LITTLEFS_ENABLED
if (sync_block)
#endif // AP_FILESYSTEM_LITTLEFS_ENABLED
{
/*
the best strategy for minimizing corruption on microSD cards
seems to be to write in 4k chunks and fsync the file on each
chunk, ensuring the directory entry is updated after each
write.
*/
last_io_operation = "fsync";
AP::FS().fsync(_write_fd);
last_io_operation = "";
Expand Down
6 changes: 5 additions & 1 deletion libraries/AP_Logger/AP_Logger_File.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ class AP_Logger_File : public AP_Logger_Backend
uint32_t _free_space_last_check_time; // milliseconds
const uint32_t _free_space_check_interval = 1000UL; // milliseconds
#if AP_FILESYSTEM_LITTLEFS_ENABLED
const uint32_t _free_space_min_avail = 4096; // bytes
#if AP_FILESYSTEM_LITTLEFS_FLASH_TYPE == AP_FILESYSTEM_FLASH_W25NXX
const uint32_t _free_space_min_avail = 1024 * 1024; // bytes
#else
const uint32_t _free_space_min_avail = 1024 * 256; // bytes
#endif
#else
const uint32_t _free_space_min_avail = 8388608; // bytes
#endif
Expand Down

0 comments on commit 613bdca

Please sign in to comment.