From 8e43afef3b033d7493f9b42dc4075735546402bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20M=C3=BAdry?= Date: Wed, 10 Apr 2024 16:51:31 +0200 Subject: [PATCH] fix(nvs): Fix possible collision with app trace sysview defines Global.h defines U8, I8, U16, etc. symbols, which are also used in NVS as a part of custom enum class and this can cause a compilation error during macro expansion, when sysview is enabled and FreeRTOS.h is included in NVS --- .../host_test/nvs_host_test/main/test_nvs.cpp | 16 ++++++++++++++ .../nvs_page_test/main/nvs_page_test.cpp | 18 ++++++++++++++- components/nvs_flash/include/nvs.h | 22 ++++++++++++++++++- components/nvs_flash/include/nvs_handle.hpp | 15 +++++++++++++ components/nvs_flash/src/nvs_storage.cpp | 16 ++++++++++++++ 5 files changed, 85 insertions(+), 2 deletions(-) diff --git a/components/nvs_flash/host_test/nvs_host_test/main/test_nvs.cpp b/components/nvs_flash/host_test/nvs_host_test/main/test_nvs.cpp index 82973c0416..23741b90fa 100644 --- a/components/nvs_flash/host_test/nvs_host_test/main/test_nvs.cpp +++ b/components/nvs_flash/host_test/nvs_host_test/main/test_nvs.cpp @@ -26,6 +26,18 @@ #define WD_PREFIX "./components/nvs_flash/host_test/nvs_host_test/" // path from ci cwd to the location of host test +#if defined(SEGGER_H) && defined(GLOBAL_H) +NVS_GUARD_SYSVIEW_MACRO_EXPANSION_PUSH(); +#undef U8 +#undef I8 +#undef U16 +#undef I16 +#undef U32 +#undef I32 +#undef U64 +#undef I64 +#endif + stringstream s_perf; TEST_CASE("crc32 behaves as expected", "[nvs]") @@ -3405,3 +3417,7 @@ TEST_CASE("dump all performance data", "[nvs]") std::cout << s_perf.str() << std::endl; std::cout << "====================" << std::endl; } + +#if defined(SEGGER_H) && defined(GLOBAL_H) +NVS_GUARD_SYSVIEW_MACRO_EXPANSION_POP(); +#endif diff --git a/components/nvs_flash/host_test/nvs_page_test/main/nvs_page_test.cpp b/components/nvs_flash/host_test/nvs_page_test/main/nvs_page_test.cpp index 96050448a7..f3bfcf70fc 100644 --- a/components/nvs_flash/host_test/nvs_page_test/main/nvs_page_test.cpp +++ b/components/nvs_flash/host_test/nvs_page_test/main/nvs_page_test.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,6 +10,18 @@ static const char* TAG = "nvs_page_host_test"; #include "test_fixtures.hpp" #include "esp_log.h" +#if defined(SEGGER_H) && defined(GLOBAL_H) +NVS_GUARD_SYSVIEW_MACRO_EXPANSION_PUSH(); +#undef U8 +#undef I8 +#undef U16 +#undef I16 +#undef U32 +#undef I32 +#undef U64 +#undef I64 +#endif + using namespace std; using namespace nvs; @@ -968,3 +980,7 @@ int main(int argc, char **argv) int failures = UNITY_END(); return failures; } + +#if defined(SEGGER_H) && defined(GLOBAL_H) +NVS_GUARD_SYSVIEW_MACRO_EXPANSION_POP(); +#endif diff --git a/components/nvs_flash/include/nvs.h b/components/nvs_flash/include/nvs.h index 0378457fb3..1f4715d64b 100644 --- a/components/nvs_flash/include/nvs.h +++ b/components/nvs_flash/include/nvs.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -61,6 +61,26 @@ typedef nvs_handle_t nvs_handle IDF_DEPRECATED("Replace with nvs_handle_t"); #define NVS_KEY_NAME_MAX_SIZE 16 /*!< Maximum length of NVS key name (including null terminator) */ #define NVS_NS_NAME_MAX_SIZE NVS_KEY_NAME_MAX_SIZE /*!< Maximum length of NVS namespace name (including null terminator) */ +#define NVS_GUARD_SYSVIEW_MACRO_EXPANSION_PUSH() \ +_Pragma("push_macro(\"U8\")") \ +_Pragma("push_macro(\"I8\")") \ +_Pragma("push_macro(\"U16\")") \ +_Pragma("push_macro(\"I16\")") \ +_Pragma("push_macro(\"U32\")") \ +_Pragma("push_macro(\"I32\")") \ +_Pragma("push_macro(\"U64\")") \ +_Pragma("push_macro(\"I64\")") + +#define NVS_GUARD_SYSVIEW_MACRO_EXPANSION_POP() \ +_Pragma("pop_macro(\"U8\")") \ +_Pragma("pop_macro(\"I8\")") \ +_Pragma("pop_macro(\"U16\")") \ +_Pragma("pop_macro(\"I16\")") \ +_Pragma("pop_macro(\"U32\")") \ +_Pragma("pop_macro(\"I32\")") \ +_Pragma("pop_macro(\"U64\")") \ +_Pragma("pop_macro(\"I64\")") + /** * @brief Mode of opening the non-volatile storage */ diff --git a/components/nvs_flash/include/nvs_handle.hpp b/components/nvs_flash/include/nvs_handle.hpp index 43bca298a5..32f49ab759 100644 --- a/components/nvs_flash/include/nvs_handle.hpp +++ b/components/nvs_flash/include/nvs_handle.hpp @@ -9,6 +9,18 @@ namespace nvs { +#if defined(SEGGER_H) && defined(GLOBAL_H) +NVS_GUARD_SYSVIEW_MACRO_EXPANSION_PUSH(); +#undef U8 +#undef I8 +#undef U16 +#undef I16 +#undef U32 +#undef I32 +#undef U64 +#undef I64 +#endif + /** * The possible blob types. This is a helper definition for template functions. */ @@ -28,6 +40,9 @@ enum class ItemType : uint8_t { ANY = NVS_TYPE_ANY }; +#if defined(SEGGER_H) && defined(GLOBAL_H) +NVS_GUARD_SYSVIEW_MACRO_EXPANSION_POP(); +#endif /** * @brief A handle allowing nvs-entry related operations on the NVS. diff --git a/components/nvs_flash/src/nvs_storage.cpp b/components/nvs_flash/src/nvs_storage.cpp index c1fcc3c9c4..0cf28149ab 100644 --- a/components/nvs_flash/src/nvs_storage.cpp +++ b/components/nvs_flash/src/nvs_storage.cpp @@ -23,6 +23,18 @@ #include "esp_log.h" #define TAG "nvs_storage" +#if defined(SEGGER_H) && defined(GLOBAL_H) +NVS_GUARD_SYSVIEW_MACRO_EXPANSION_PUSH(); +#undef U8 +#undef I8 +#undef U16 +#undef I16 +#undef U32 +#undef I32 +#undef U64 +#undef I64 +#endif + namespace nvs { @@ -983,3 +995,7 @@ bool Storage::nextEntry(nvs_opaque_iterator_t* it) } + +#if defined(SEGGER_H) && defined(GLOBAL_H) +NVS_GUARD_SYSVIEW_MACRO_EXPANSION_POP(); +#endif