From ec90ceb3d8b910b67cb632d1867af5c7500c8b05 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 15 Oct 2019 16:39:36 +0700 Subject: [PATCH] clean up flash --- .../InternalFileSytem/src/InternalFileSystem.cpp | 4 ++-- .../InternalFileSytem/src/flash/flash_cache.c | 2 +- .../InternalFileSytem/src/flash/flash_nrf5x.c | 16 +++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libraries/InternalFileSytem/src/InternalFileSystem.cpp b/libraries/InternalFileSytem/src/InternalFileSystem.cpp index 9b35802f..81ad95b9 100644 --- a/libraries/InternalFileSytem/src/InternalFileSystem.cpp +++ b/libraries/InternalFileSytem/src/InternalFileSystem.cpp @@ -48,7 +48,7 @@ static int _internal_flash_read (const struct lfs_config *c, lfs_block_t block, (void) c; uint32_t addr = lba2addr(block) + off; - flash_nrf5x_read(buffer, addr, size); + VERIFY( flash_nrf5x_read(buffer, addr, size) > 0, -1); return 0; } @@ -61,7 +61,7 @@ static int _internal_flash_prog (const struct lfs_config *c, lfs_block_t block, (void) c; uint32_t addr = lba2addr(block) + off; - flash_nrf5x_write(addr, buffer, size); + VERIFY( flash_nrf5x_write(addr, buffer, size), -1) return 0; } diff --git a/libraries/InternalFileSytem/src/flash/flash_cache.c b/libraries/InternalFileSytem/src/flash/flash_cache.c index 0636feb9..400533fc 100644 --- a/libraries/InternalFileSytem/src/flash/flash_cache.c +++ b/libraries/InternalFileSytem/src/flash/flash_cache.c @@ -83,7 +83,7 @@ void flash_cache_flush (flash_cache_t* fc) // skip erase & program if verify() exists, and memory matches if ( !(fc->verify && fc->verify(fc->cache_addr, fc->cache_buf, FLASH_CACHE_SIZE)) ) { - // indicator + // indicator TODO allow to disable flash indicator ledOn(LED_BUILTIN); fc->erase(fc->cache_addr); diff --git a/libraries/InternalFileSytem/src/flash/flash_nrf5x.c b/libraries/InternalFileSytem/src/flash/flash_nrf5x.c index c489e85f..f9fac1fd 100644 --- a/libraries/InternalFileSytem/src/flash/flash_nrf5x.c +++ b/libraries/InternalFileSytem/src/flash/flash_nrf5x.c @@ -59,13 +59,15 @@ static bool fal_verify (uint32_t addr, void const * buf, uint32_t len); static uint8_t _cache_buffer[FLASH_CACHE_SIZE] __attribute__((aligned(4))); -static flash_cache_t _cache = { - .erase = fal_erase, - .program = fal_program, - .read = fal_read, - .verify = fal_verify, +static flash_cache_t _cache = +{ + .erase = fal_erase, + .program = fal_program, + .read = fal_read, + .verify = fal_verify, + .cache_addr = FLASH_CACHE_INVALID_ADDR, - .cache_buf = _cache_buffer + .cache_buf = _cache_buffer }; //--------------------------------------------------------------------+ @@ -100,7 +102,7 @@ bool flash_nrf5x_erase(uint32_t addr) //--------------------------------------------------------------------+ // HAL for caching //--------------------------------------------------------------------+ -bool fal_erase (uint32_t addr) +static bool fal_erase (uint32_t addr) { // Init semaphore for first call if ( _sem == NULL )