From ab73b4f395d875eb2b7288a7141c316ac2c38ad1 Mon Sep 17 00:00:00 2001 From: Ricardo Casallas <77841255+rcasallas-silabs@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:42:27 -0400 Subject: [PATCH] Silabs: RTT I/O stream support added. (#29452) --- examples/platform/silabs/FreeRTOSConfig.h | 22 +++++---- examples/platform/silabs/args.gni | 3 ++ examples/platform/silabs/matter-platform.slcp | 1 + src/platform/silabs/Logging.cpp | 4 -- src/platform/silabs/SilabsConfig.cpp | 49 ++++++++++++++++--- src/platform/silabs/SilabsConfig.h | 3 ++ .../efr32/include/FreeRTOSConfig.h | 11 ++++- third_party/silabs/efr32_sdk.gni | 5 ++ third_party/silabs/matter_support | 2 +- third_party/silabs/silabs_board.gni | 3 ++ 10 files changed, 81 insertions(+), 22 deletions(-) diff --git a/examples/platform/silabs/FreeRTOSConfig.h b/examples/platform/silabs/FreeRTOSConfig.h index 520c84a2d73b81..869093051edb85 100644 --- a/examples/platform/silabs/FreeRTOSConfig.h +++ b/examples/platform/silabs/FreeRTOSConfig.h @@ -291,25 +291,29 @@ standard names. */ #define SysTick_Handler xPortSysTickHandler /* Thread local storage pointers used by the SDK */ -#ifdef PERFORMANCE_TEST_ENABLED -// ot_debug_channel component uses thread-local storage -#define configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS 2 + #ifndef configNUM_USER_THREAD_LOCAL_STORAGE_POINTERS -#define configNUM_USER_THREAD_LOCAL_STORAGE_POINTERS 0 -#define configNUM_THREAD_LOCAL_STORAGE_POINTERS \ - (configNUM_USER_THREAD_LOCAL_STORAGE_POINTERS + configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS) +#define configNUM_USER_THREAD_LOCAL_STORAGE_POINTERS 2 #endif -#else /* PERFORMANCE_TEST_ENABLED */ + #ifndef configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS -#define configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS 0 +#define configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS 2 +#endif + +#ifndef configNUM_THREAD_LOCAL_STORAGE_POINTERS +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS \ + (configNUM_USER_THREAD_LOCAL_STORAGE_POINTERS + configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS + 1) #endif -#endif /* PERFORMANCE_TEST_ENABLED */ #if defined(__GNUC__) /* For the linker. */ #define fabs __builtin_fabs #endif +#ifndef configNUM_USER_THREAD_LOCAL_STORAGE_POINTERS +#error RC-FRTOS +#endif + #ifdef __cplusplus } #endif diff --git a/examples/platform/silabs/args.gni b/examples/platform/silabs/args.gni index ff5317006bd805..41ad41f51c05e9 100644 --- a/examples/platform/silabs/args.gni +++ b/examples/platform/silabs/args.gni @@ -20,6 +20,9 @@ chip_project_config_include = "" chip_inet_project_config_include = "" chip_system_project_config_include = "" +segger_rtt_buffer_size_up = 1024 +segger_rtt_buffer_size_down = 1024 + declare_args() { app_data_model = "" } diff --git a/examples/platform/silabs/matter-platform.slcp b/examples/platform/silabs/matter-platform.slcp index 33ed32c11d909f..3616d074a6df88 100644 --- a/examples/platform/silabs/matter-platform.slcp +++ b/examples/platform/silabs/matter-platform.slcp @@ -63,6 +63,7 @@ component: - {id: mbedtls_base64} - {id: ot_psa_crypto} - {id: bluetooth_crypto} +- {id: iostream_rtt} # Necessary componenets for ot coap cert lib # - {id: mbedtls_dtls} # Requried by COAP lib # - {id: mbedtls_tls_server} # Requried by COAP lib diff --git a/src/platform/silabs/Logging.cpp b/src/platform/silabs/Logging.cpp index d517f20e7120be..ec0b00fe7fa942 100644 --- a/src/platform/silabs/Logging.cpp +++ b/src/platform/silabs/Logging.cpp @@ -13,14 +13,10 @@ #endif #include "AppConfig.h" -#include -#include #include #include -#include #ifndef BRD4325A -#include "rail_types.h" #ifdef RAIL_ASSERT_DEBUG_STRING #include "rail_assert_error_codes.h" diff --git a/src/platform/silabs/SilabsConfig.cpp b/src/platform/silabs/SilabsConfig.cpp index 950b6040490c0a..4c9093e09d97f8 100644 --- a/src/platform/silabs/SilabsConfig.cpp +++ b/src/platform/silabs/SilabsConfig.cpp @@ -21,21 +21,21 @@ * Utilities for accessing persisted device configuration on * platforms based on the Silicon Labs SDK. */ -/* this file behaves like a config.h, comes first */ -#include - #include #include +#include #include +#include -#include "FreeRTOS.h" -#include "nvm3.h" -#include "nvm3_default.h" -#include "nvm3_hal_flash.h" +#include +#include +#include #include #ifndef BRD4325A // TODO: fix semaphore usage in nvm3_lock for siwx917. use weak implementation for that board instead +#include +#include // Substitute the GSDK weak nvm3_lockBegin and nvm3_lockEnd // for an application controlled re-entrance protection static SemaphoreHandle_t nvm3_Sem; @@ -106,6 +106,28 @@ CHIP_ERROR SilabsConfig::ReadConfigValue(Key key, bool & val) return err; } +CHIP_ERROR SilabsConfig::ReadConfigValue(Key key, uint16_t & val) +{ + CHIP_ERROR err; + uint32_t objectType; + size_t dataLen; + uint16_t tmpVal = 0; + + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + // Get nvm3 object info. + err = MapNvm3Error(nvm3_getObjectInfo(nvm3_defaultHandle, key, &objectType, &dataLen)); + SuccessOrExit(err); + + // Read nvm3 bytes into tmp. + err = MapNvm3Error(nvm3_readData(nvm3_defaultHandle, key, &tmpVal, dataLen)); + SuccessOrExit(err); + val = tmpVal; + +exit: + return err; +} + CHIP_ERROR SilabsConfig::ReadConfigValue(Key key, uint32_t & val) { CHIP_ERROR err; @@ -296,6 +318,19 @@ CHIP_ERROR SilabsConfig::WriteConfigValue(Key key, bool val) return err; } +CHIP_ERROR SilabsConfig::WriteConfigValue(Key key, uint16_t val) +{ + CHIP_ERROR err; + + VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. + + err = MapNvm3Error(nvm3_writeData(nvm3_defaultHandle, key, &val, sizeof(val))); + SuccessOrExit(err); + +exit: + return err; +} + CHIP_ERROR SilabsConfig::WriteConfigValue(Key key, uint32_t val) { CHIP_ERROR err; diff --git a/src/platform/silabs/SilabsConfig.h b/src/platform/silabs/SilabsConfig.h index d5742c7c077d9d..0f820f6fb8268e 100644 --- a/src/platform/silabs/SilabsConfig.h +++ b/src/platform/silabs/SilabsConfig.h @@ -25,6 +25,7 @@ #pragma once #include +#include #include "nvm3.h" #include "nvm3_hal_flash.h" @@ -176,6 +177,7 @@ class SilabsConfig // Configuration methods used by the GenericConfigurationManagerImpl<> template. static CHIP_ERROR ReadConfigValue(Key key, bool & val); + static CHIP_ERROR ReadConfigValue(Key key, uint16_t & val); static CHIP_ERROR ReadConfigValue(Key key, uint32_t & val); static CHIP_ERROR ReadConfigValue(Key key, uint64_t & val); static CHIP_ERROR ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen); @@ -183,6 +185,7 @@ class SilabsConfig static CHIP_ERROR ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen, size_t offset); static CHIP_ERROR ReadConfigValueCounter(uint8_t counterIdx, uint32_t & val); static CHIP_ERROR WriteConfigValue(Key key, bool val); + static CHIP_ERROR WriteConfigValue(Key key, uint16_t val); static CHIP_ERROR WriteConfigValue(Key key, uint32_t val); static CHIP_ERROR WriteConfigValue(Key key, uint64_t val); static CHIP_ERROR WriteConfigValueStr(Key key, const char * str); diff --git a/src/test_driver/efr32/include/FreeRTOSConfig.h b/src/test_driver/efr32/include/FreeRTOSConfig.h index bb486f66231af6..c74684789ac1bd 100644 --- a/src/test_driver/efr32/include/FreeRTOSConfig.h +++ b/src/test_driver/efr32/include/FreeRTOSConfig.h @@ -285,8 +285,17 @@ standard names. */ #define SysTick_Handler xPortSysTickHandler /* Thread local storage pointers used by the SDK */ +#ifndef configNUM_USER_THREAD_LOCAL_STORAGE_POINTERS +#define configNUM_USER_THREAD_LOCAL_STORAGE_POINTERS 2 +#endif + #ifndef configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS -#define configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS 0 +#define configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS 2 +#endif + +#ifndef configNUM_THREAD_LOCAL_STORAGE_POINTERS +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS \ + (configNUM_USER_THREAD_LOCAL_STORAGE_POINTERS + configNUM_SDK_THREAD_LOCAL_STORAGE_POINTERS + 1) #endif #if defined(__GNUC__) diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 0c743ddcd83b39..e04aa9d7070e75 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -157,6 +157,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/platform/service/device_init/inc", "${efr32_sdk_root}/platform/service/hfxo_manager/inc", "${efr32_sdk_root}/platform/service/hfxo_manager/src", + "${efr32_sdk_root}/platform/service/iostream/inc", "${efr32_sdk_root}/platform/service/mpu/inc", "${efr32_sdk_root}/platform/service/power_manager/inc/", "${efr32_sdk_root}/platform/service/power_manager/src/", @@ -584,6 +585,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/platform/bootloader/api/btl_interface_storage.c", "${efr32_sdk_root}/platform/bootloader/security/sha/crypto_sha.c", "${efr32_sdk_root}/platform/common/src/sl_slist.c", + "${efr32_sdk_root}/platform/common/src/sli_cmsis_os2_ext_task_register.c", "${efr32_sdk_root}/platform/emdrv/dmadrv/src/dmadrv.c", "${efr32_sdk_root}/platform/emdrv/gpiointerrupt/src/gpiointerrupt.c", "${efr32_sdk_root}/platform/emdrv/nvm3/src/nvm3_default.c", @@ -626,6 +628,8 @@ template("efr32_sdk") { "${efr32_sdk_root}/platform/service/device_init/src/sl_device_init_lfrco.c", "${efr32_sdk_root}/platform/service/device_init/src/sl_device_init_nvic.c", "${efr32_sdk_root}/platform/service/hfxo_manager/src/sl_hfxo_manager.c", + "${efr32_sdk_root}/platform/service/iostream/src/sl_iostream.c", + "${efr32_sdk_root}/platform/service/iostream/src/sl_iostream_rtt.c", "${efr32_sdk_root}/platform/service/mpu/src/sl_mpu.c", "${efr32_sdk_root}/platform/service/power_manager/src/sl_power_manager.c", "${efr32_sdk_root}/platform/service/power_manager/src/sl_power_manager_debug.c", @@ -711,6 +715,7 @@ template("efr32_sdk") { "${silabs_gen_folder}/autogen/sl_board_default_init.c", "${silabs_gen_folder}/autogen/sl_device_init_clocks.c", "${silabs_gen_folder}/autogen/sl_event_handler.c", + "${silabs_gen_folder}/autogen/sl_iostream_handles.c", ] if (enable_dic) { sources += [ diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index d336c71c24b154..220e87668200a1 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit d336c71c24b1541c9099a258216dfd4585ace9fe +Subproject commit 220e87668200a1ac3c4bc3604a9408c2b12d440e diff --git a/third_party/silabs/silabs_board.gni b/third_party/silabs/silabs_board.gni index c69a09820d9c7f..6910e410a4e2f0 100644 --- a/third_party/silabs/silabs_board.gni +++ b/third_party/silabs/silabs_board.gni @@ -48,6 +48,9 @@ declare_args() { # Disable UART log forwarding by default sl_uart_log_output = false + + # Self-provision enabled + use_provision_channel = false } declare_args() {