From 075446318df651216be42966e721c30d822b48e2 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 17 Jan 2017 00:42:55 +0800 Subject: [PATCH 1/2] spi_flash: define spi_flash_guard_{start,stop} with IRAM_ATTR These functions are marked as inline and are called from functions which are in IRAM. In release (-Os) builds, the compiler may decide not to inline these functions. Placing these functions into IRAM explicitly works around this. --- components/spi_flash/flash_ops.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/spi_flash/flash_ops.c b/components/spi_flash/flash_ops.c index fffe487bd1..a74558a96f 100644 --- a/components/spi_flash/flash_ops.c +++ b/components/spi_flash/flash_ops.c @@ -103,16 +103,18 @@ SpiFlashOpResult IRAM_ATTR spi_flash_unlock() return SPI_FLASH_RESULT_OK; } -static inline void spi_flash_guard_start() +static inline void IRAM_ATTR spi_flash_guard_start() { - if (s_flash_guard_ops) + if (s_flash_guard_ops) { s_flash_guard_ops->start(); + } } -static inline void spi_flash_guard_end() +static inline void IRAM_ATTR spi_flash_guard_end() { - if (s_flash_guard_ops) + if (s_flash_guard_ops) { s_flash_guard_ops->end(); + } } esp_err_t IRAM_ATTR spi_flash_erase_sector(size_t sec) From c47cc6348947cfd1aa6a8aa87e0764c1f07630c6 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 17 Jan 2017 00:49:38 +0800 Subject: [PATCH 2/2] newlib: change definition of assert for release builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One common pattern of using assert function looks as follows: int ret = do_foo(); assert(ret == 0); // which reads as: “do_foo should never fail here, by design” The problem with such code is that if ‘assert’ is removed by the preprocessor in release build, variable ret is no longer used, and the compiler issues a warning about this. Changing assert definition in the way done here make the variable used, from language syntax perspective. Semantically, the variable is still unused at run time (as sizeof can be evaluated at compile time), so the compiler can optimize things away if possible. --- components/newlib/include/assert.h | 2 +- components/nvs_flash/src/nvs_pagemanager.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/newlib/include/assert.h b/components/newlib/include/assert.h index 91bb040cab..df46c030b2 100644 --- a/components/newlib/include/assert.h +++ b/components/newlib/include/assert.h @@ -11,7 +11,7 @@ extern "C" { #undef assert #ifdef NDEBUG /* required by ANSI standard */ -# define assert(__e) ((void)0) +# define assert(__e) ((void) sizeof(__e)) #else # define assert(__e) ((__e) ? (void)0 : __assert_func (__FILE__, __LINE__, \ __ASSERT_FUNC, #__e)) diff --git a/components/nvs_flash/src/nvs_pagemanager.cpp b/components/nvs_flash/src/nvs_pagemanager.cpp index f4d02a7d40..768b30667a 100644 --- a/components/nvs_flash/src/nvs_pagemanager.cpp +++ b/components/nvs_flash/src/nvs_pagemanager.cpp @@ -163,8 +163,10 @@ esp_err_t PageManager::requestNewPage() return err; } +#ifndef NDEBUG assert(usedEntries == newPage->getUsedEntryCount()); - +#endif + mPageList.erase(maxErasedItemsPageIt); mFreePageList.push_back(erasedPage);