From edaa4bd56d684bb7b8de15be6e0d895902c4a810 Mon Sep 17 00:00:00 2001 From: Junior Martinez Date: Mon, 24 Jan 2022 15:04:07 -0500 Subject: [PATCH] Rework efr32 build script, add some info for SED build in the examples readme & restyle --- examples/lighting-app/efr32/BUILD.gn | 2 +- examples/lighting-app/efr32/README.md | 21 +- .../efr32/include/FreeRTOSConfig.h | 3 +- examples/lock-app/efr32/BUILD.gn | 2 +- examples/lock-app/efr32/README.md | 31 ++- .../lock-app/efr32/include/FreeRTOSConfig.h | 3 +- examples/platform/efr32/uart.cpp | 15 ++ examples/window-app/efr32/BUILD.gn | 2 +- examples/window-app/efr32/README.md | 21 +- .../window-app/efr32/include/FreeRTOSConfig.h | 3 +- scripts/examples/gn_efr32_example.sh | 198 +++++++++++------- src/messaging/ExchangeContext.cpp | 22 +- third_party/efr32_sdk/efr32_sdk.gni | 9 +- third_party/zap/repo | 2 +- 14 files changed, 235 insertions(+), 99 deletions(-) diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index f3b4bf14f642b7..664e57c4387e5c 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -47,7 +47,7 @@ declare_args() { # Enable Sleepy end device sleepy_device = false - + # Wifi related stuff - they are overriden by gn -args="use_wf200=true" use_wf200 = false use_rs911x = false diff --git a/examples/lighting-app/efr32/README.md b/examples/lighting-app/efr32/README.md index 391a5f39976ef1..ca56caa5aae9fc 100644 --- a/examples/lighting-app/efr32/README.md +++ b/examples/lighting-app/efr32/README.md @@ -85,7 +85,7 @@ Silicon Labs platform. $ cd ~/connectedhomeip $ rm -rf ./out/ -OR use GN/Ninja directly + OR use GN/Ninja directly $ cd ~/connectedhomeip/examples/lighting-app/efr32 $ git submodule update --init @@ -99,7 +99,19 @@ OR use GN/Ninja directly $ cd ~/connectedhomeip/examples/lighting-app/efr32 $ rm -rf out/ -* Build the example with pigweed RCP use GN/Ninja Directly +* Build the example as Sleepy End Device (SED) + + $ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32/ ./out/lighting-app_SED BRD4161A --sed + + or use gn as previously mentioned but adding the following arguments: + + $ gn gen out/debug '--args=efr32_board="BRD4161A" sleepy_device=true chip_openthread_ftd=false' + +* Build the example with pigweed RCP + + $ ./scripts/examples/gn_efr32_example.sh examples/lighting-app/efr32/ out/lighting_app_rpc BRD4161A 'import("//with_pw_rpc.gni")' + + or use GN/Ninja Directly $ cd ~/connectedhomeip/examples/lighting-app/efr32 $ git submodule update --init @@ -110,6 +122,11 @@ OR use GN/Ninja directly [Running Pigweed RPC console](#running-pigweed-rpc-console) +For more build options, help is provided when running the build script without +arguments + + ./scripts/examples/gn_efr32_example.sh + ## Flashing the Application diff --git a/examples/lighting-app/efr32/include/FreeRTOSConfig.h b/examples/lighting-app/efr32/include/FreeRTOSConfig.h index dc4cb5385fcbe5..f8d2c6a1500057 100644 --- a/examples/lighting-app/efr32/include/FreeRTOSConfig.h +++ b/examples/lighting-app/efr32/include/FreeRTOSConfig.h @@ -127,13 +127,12 @@ extern "C" { * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ - /* Energy saving modes. */ #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) #define configUSE_TICKLESS_IDLE 1 #else #define configUSE_TICKLESS_IDLE 0 -#endif //SL_CATALOG_POWER_MANAGER_PRESENT +#endif // SL_CATALOG_POWER_MANAGER_PRESENT #define configTICK_RATE_HZ (1000) /* Definition used by Keil to replace default system clock source. */ diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index 4056216e804f11..faed6b8cc3225a 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -43,7 +43,7 @@ declare_args() { # Monitor & log memory usage at runtime. enable_heap_monitoring = false - + # Enable Sleepy end device sleepy_device = false diff --git a/examples/lock-app/efr32/README.md b/examples/lock-app/efr32/README.md index 6c3fa798d6154a..c6914bbb4ee407 100644 --- a/examples/lock-app/efr32/README.md +++ b/examples/lock-app/efr32/README.md @@ -84,7 +84,7 @@ Silicon Labs platform. $ cd ~/connectedhomeip $ rm -rf ./out/ -OR use GN/Ninja directly + OR use GN/Ninja directly $ cd ~/connectedhomeip/examples/lock-app/efr32 $ git submodule update --init @@ -98,6 +98,35 @@ OR use GN/Ninja directly $ cd ~/connectedhomeip/examples/lock-app/efr32 $ rm -rf out/ + +* Build the example as Sleepy End Device (SED) + + $ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32/ ./out/lighting-app_SED BRD4161A --sed + + or use gn as previously mentioned but adding the following arguments: + + $ gn gen out/debug '--args=efr32_board="BRD4161A" sleepy_device=true chip_openthread_ftd=false' + +* Build the example with pigweed RCP + + $ ./scripts/examples/gn_efr32_example.sh examples/lock-app/efr32/ out/lock_app_rpc BRD4161A 'import("//with_pw_rpc.gni")' + + or use GN/Ninja Directly + + $ cd ~/connectedhomeip/examples/lock-app/efr32 + $ git submodule update --init + $ source third_party/connectedhomeip/scripts/activate.sh + $ export EFR32_BOARD=BRD4161A + $ gn gen out/debug --args='import("//with_pw_rpc.gni")' + $ ninja -C out/debug + + [Running Pigweed RPC console](#running-pigweed-rpc-console) + +For more build options, help is provided when running the build script without +arguments + + ./scripts/examples/gn_efr32_example.sh + ## Flashing the Application diff --git a/examples/lock-app/efr32/include/FreeRTOSConfig.h b/examples/lock-app/efr32/include/FreeRTOSConfig.h index cd89cfe3802846..af0b8ace973680 100644 --- a/examples/lock-app/efr32/include/FreeRTOSConfig.h +++ b/examples/lock-app/efr32/include/FreeRTOSConfig.h @@ -127,13 +127,12 @@ extern "C" { * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ - /* Energy saving modes. */ #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) #define configUSE_TICKLESS_IDLE 1 #else #define configUSE_TICKLESS_IDLE 0 -#endif //SL_CATALOG_POWER_MANAGER_PRESENT +#endif // SL_CATALOG_POWER_MANAGER_PRESENT #define configTICK_RATE_HZ (1000) /* Definition used by Keil to replace default system clock source. */ diff --git a/examples/platform/efr32/uart.cpp b/examples/platform/efr32/uart.cpp index 8d384a9ac657b4..dd370c60475daa 100644 --- a/examples/platform/efr32/uart.cpp +++ b/examples/platform/efr32/uart.cpp @@ -32,6 +32,10 @@ extern "C" { #include #include +#if defined(SL_CATALOG_POWER_MANAGER_PRESENT) +#include "sl_power_manager.h" +#endif + #if !defined(MIN) #define MIN(A, B) ((A) < (B) ? (A) : (B)) #endif @@ -245,13 +249,24 @@ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength) return UART_CONSOLE_ERR; } +#if defined(SL_CATALOG_POWER_MANAGER_PRESENT) + sl_power_manager_add_em_requirement(SL_POWER_MANAGER_EM1); +#endif + // Use of ForceTransmit here. Transmit with DMA was causing errors with PW_RPC // TODO Use DMA and find/fix what causes the issue with PW if (UARTDRV_ForceTransmit(sl_uartdrv_usart_vcom_handle, (uint8_t *) Buf, BufLength) == ECODE_EMDRV_UARTDRV_OK) { +#if defined(SL_CATALOG_POWER_MANAGER_PRESENT) + sl_power_manager_remove_em_requirement(SL_POWER_MANAGER_EM1); +#endif return BufLength; } +#if defined(SL_CATALOG_POWER_MANAGER_PRESENT) + sl_power_manager_remove_em_requirement(SL_POWER_MANAGER_EM1); +#endif + return UART_CONSOLE_ERR; } diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index 2bbfd2ac19c21f..135d14f1bc462c 100644 --- a/examples/window-app/efr32/BUILD.gn +++ b/examples/window-app/efr32/BUILD.gn @@ -40,7 +40,7 @@ declare_args() { # Enable Sleepy end device sleepy_device = false - + # Wifi related stuff - they are overriden by gn -args="use_wf200=true" use_wf200 = false use_rs911x = false diff --git a/examples/window-app/efr32/README.md b/examples/window-app/efr32/README.md index 79ad30072ff490..17e1c7799afa55 100644 --- a/examples/window-app/efr32/README.md +++ b/examples/window-app/efr32/README.md @@ -89,7 +89,7 @@ Silicon Labs platform. $ cd ~/connectedhomeip $ rm -rf ./out/ -OR use GN/Ninja directly + OR use GN/Ninja directly $ cd ~/connectedhomeip/examples/window-app/efr32 $ git submodule update --init @@ -103,7 +103,19 @@ OR use GN/Ninja directly $ cd ~/connectedhomeip/examples/window-app/efr32 $ rm -rf out/ -* Build the example with pigweed RCP use GN/Ninja Directly +* Build the example as Sleepy End Device (SED) + + $ ./scripts/examples/gn_efr32_example.sh ./examples/window-app/efr32/ ./out/window-app_SED BRD4161A --sed + + or use gn as previously mentioned but adding the following arguments: + + $ gn gen out/debug '--args=efr32_board="BRD4161A" sleepy_device=true chip_openthread_ftd=false' + +* Build the example with pigweed RCP + + $ ./scripts/examples/gn_efr32_example.sh examples/window-app/efr32/ out/window_app_rpc BRD4161A 'import("//with_pw_rpc.gni")' + + or use GN/Ninja Directly $ cd ~/connectedhomeip/examples/window-app/efr32 $ git submodule update --init @@ -114,6 +126,11 @@ OR use GN/Ninja directly [Running Pigweed RPC console](#running-pigweed-rpc-console) +For more build options, help is provided when running the build script without +arguments + + ./scripts/examples/gn_efr32_example.sh + ## Flashing the Application diff --git a/examples/window-app/efr32/include/FreeRTOSConfig.h b/examples/window-app/efr32/include/FreeRTOSConfig.h index cd89cfe3802846..af0b8ace973680 100644 --- a/examples/window-app/efr32/include/FreeRTOSConfig.h +++ b/examples/window-app/efr32/include/FreeRTOSConfig.h @@ -127,13 +127,12 @@ extern "C" { * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ - /* Energy saving modes. */ #if defined(SL_CATALOG_POWER_MANAGER_PRESENT) #define configUSE_TICKLESS_IDLE 1 #else #define configUSE_TICKLESS_IDLE 0 -#endif //SL_CATALOG_POWER_MANAGER_PRESENT +#endif // SL_CATALOG_POWER_MANAGER_PRESENT #define configTICK_RATE_HZ (1000) /* Definition used by Keil to replace default system clock source. */ diff --git a/scripts/examples/gn_efr32_example.sh b/scripts/examples/gn_efr32_example.sh index ed0cc22502bfff..9bc42a1f8e4e9f 100755 --- a/scripts/examples/gn_efr32_example.sh +++ b/scripts/examples/gn_efr32_example.sh @@ -23,79 +23,133 @@ source "$(dirname "$0")/../../scripts/activate.sh" set -x env -USE_WF200=0 -USE_RS911X=0 -USE_WIFI=0 - -ROOT=$1 -arg2=$2 -shift -shift -while [ $# -gt 0 ]; do - case $1 in - --wifi) - if [ -z "$2" ]; then - echo "--efr requires BRDxxxx" - exit 1 - fi - if [ X"$2" = "Xrs911x" ]; then - WIFI_ARGS="use_rs911x=true" - elif [ "$2" = wf200 ]; then - WIFI_ARGS="use_wf200=true" - else - echo "Wifi usage: --wifi rs911x|wf200" - exit 1 - fi - shift - shift - - ;; - --efr) - if [ -z "$2" ]; then - echo "--efr requires BRDxxxx" - exit 1 - fi - EFR32_BOARD=$2 - shift - shift - ;; - - --gnargs) - echo "-gnargs - Not yet implemented" - exit 1 - GNARGS=$2 - shift - shift - ;; - - *) - EFR32_BOARD=$1 - shift - if [ X"$1" != "X" ]; then - GNARGS=$1 - shift - fi - ;; - esac -done - -if [ X"$EFR32_BOARD" = "X" ]; then - echo "EFR32_BOARD not defined" - exit 1 -fi -BUILD_DIR=$arg2/$EFR32_BOARD -echo BUILD_DIR="$BUILD_DIR" -if [ "X$WIFI_ARGS" != "X" ]; then - gn gen --check --fail-on-unused-args --root="$ROOT" --dotfile="$ROOT"/build_for_wifi_gnfile.gn --args="efr32_board=\"$EFR32_BOARD\" $WIFI_ARGS" "$BUILD_DIR" +USE_WIFI=false + +USAGE="./scripts/examples/gn_efr32_example.sh []" + +if [ "$#" == "0" ]; then + echo "Build script for EFR32 Matter apps + Format: + $USAGE + + + Root Location of the app e.g: examples/lighting-app/efr32/ + + + Desired location for the output files + + + Identifier of the board for which this app is built + Currently Supported : + BRD4161A + BRD4163A + BRD4164A + BRD4166A + BRD4170A + BRD4186A + BRD4187A + BRD4304A + + - optional noteworthy build options for EFR32 + chip_build_libshell + Enable libshell support. (Default false) + chip_logging + Current value (Default true) + chip_openthread_ftd + Use openthread Full Thread Device, else, use Minimal Thread Device. (Default true) + efr32_sdk_root + Location for an alternate or modified efr32 SDK + enable_heap_monitoring + Monitor & log memory usage at runtime. (Default false) + setupDiscriminator + Discriminatoor value used for BLE connexion. (Default 3840) + setupPinCode + PIN code for PASE session establishment. (Default 73141520) + sleepy_device + Enable Sleepy end device. (Default false) + Must also set chip_openthread_ftd=false + use_rs911x + Build wifi example with extension board rs911x. (Default false) + use_wf200 + Build wifi example with extension board wf200. (Default false) + 'import("//with_pw_rpc.gni")' + Use to build the example with pigweed RPC + + Presets + --sed + enable sleepy end device and set thread mtd + --wifi + build wifi example variant for given exansion board + " +elif [ "$#" -lt "2" ]; then + echo "Invalid number of arguments + Format: + $USAGE" else - # thread build - # - if [ -z "$GNARGS" ]; then - gn gen --check --fail-on-unused-args --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\"" "$BUILD_DIR" + ROOT=$1 + OUTDIR=$2 + + if [ "$#" -gt "2" ]; then + EFR32_BOARD=$3 + shift + fi + + shift + shift + while [ $# -gt 0 ]; do + case $1 in + --wifi) + if [ -z "$2" ]; then + echo "--wifi requires rs911x or wf200" + exit 1 + fi + if [ "$2" = "rs911x" ]; then + optArgs+="use_rs911x=true" + elif [ "$2" = "wf200" ]; then + optArgs+="use_wf200=true" + else + echo "Wifi usage: --wifi rs911x|wf200" + exit 1 + fi + USE_WIFI=true + shift + shift + ;; + --sed) + optArgs+="sleepy_device=true chip_openthread_ftd=false " + shift + ;; + *) + if [ "$1" =~ *"use_rs911x=true"* ] || [ "$1" =~ *"use_wf200=true"* ]; then + USE_WIFI=true + fi + + optArgs+=$1" " + shift + ;; + esac + done + + if [ -z "$EFR32_BOARD" ]; then + echo "EFR32_BOARD not defined" + exit 1 + fi + + BUILD_DIR=$OUTDIR/$EFR32_BOARD + echo BUILD_DIR="$BUILD_DIR" + if [ "$USE_WIFI" == true ]; then + gn gen --check --fail-on-unused-args --root="$ROOT" --dotfile="$ROOT"/build_for_wifi_gnfile.gn --args="efr32_board=\"$EFR32_BOARD\" $optArgs" "$BUILD_DIR" else - gn gen --check --fail-on-unused-args --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\" $GNARGS" "$BUILD_DIR" + # thread build + # + if [ -z "$optArgs" ]; then + gn gen --check --fail-on-unused-args --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\"" "$BUILD_DIR" + else + gn gen --check --fail-on-unused-args --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\" $optArgs" "$BUILD_DIR" + fi fi + ninja -v -C "$BUILD_DIR"/ + #print stats + arm-none-eabi-size -A "$BUILD_DIR"/*.out + fi -ninja -v -C "$BUILD_DIR"/ -#print stats -arm-none-eabi-size -A "$BUILD_DIR"/*.out diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index 8ec3b67989aff8..64c99bd7a76427 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -87,15 +87,23 @@ void ExchangeContext::SetResponseTimeout(Timeout timeout) #if CONFIG_DEVICE_LAYER && CHIP_DEVICE_CONFIG_ENABLE_SED void ExchangeContext::UpdateSEDPollingMode() { - if (GetSessionHandle()->AsSecureSession()->GetPeerAddress().GetTransportType() != Transport::Type::kBle) + SessionHandle sessionHandle = GetSessionHandle(); + Transport::Session::SessionType sessType = sessionHandle->GetSessionType(); + + // During PASE session, which happen on BLE, the session is kUnauthenticated + // So AsSecureSession() ends up faulting the sytem + if (sessType != Transport::Session::SessionType::kUnauthenticated) { - if (!IsResponseExpected() && !IsSendExpected() && (mExchangeMgr->GetNumActiveExchanges() == 1)) - { - chip::DeviceLayer::ConnectivityMgr().RequestSEDFastPollingMode(false); - } - else + if (sessionHandle->AsSecureSession()->GetPeerAddress().GetTransportType() != Transport::Type::kBle) { - chip::DeviceLayer::ConnectivityMgr().RequestSEDFastPollingMode(true); + if (!IsResponseExpected() && !IsSendExpected() && (mExchangeMgr->GetNumActiveExchanges() == 1)) + { + chip::DeviceLayer::ConnectivityMgr().RequestSEDFastPollingMode(false); + } + else + { + chip::DeviceLayer::ConnectivityMgr().RequestSEDFastPollingMode(true); + } } } } diff --git a/third_party/efr32_sdk/efr32_sdk.gni b/third_party/efr32_sdk/efr32_sdk.gni index b1ca399851c0b8..660b3668e14be5 100644 --- a/third_party/efr32_sdk/efr32_sdk.gni +++ b/third_party/efr32_sdk/efr32_sdk.gni @@ -152,17 +152,15 @@ template("efr32_sdk") { defines += board_defines - if (defined(invoker.sleepy_device)) - { + if (defined(invoker.sleepy_device)) { if (invoker.sleepy_device) { - print("INVOKER SLEEPY") defines += [ "CHIP_DEVICE_CONFIG_ENABLE_SED=1", "SL_CATALOG_POWER_MANAGER_PRESENT", "SL_CATALOG_SLEEPTIMER_PRESENT", - ] + ] } - } + } if (chip_build_libshell) { defines += [ @@ -438,6 +436,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/util/third_party/freertos/kernel/croutine.c", "${efr32_sdk_root}/util/third_party/freertos/kernel/event_groups.c", "${efr32_sdk_root}/util/third_party/freertos/kernel/list.c", + "${efr32_sdk_root}/util/third_party/freertos/kernel/portable/SiliconLabs/tick_power_manager.c", "${efr32_sdk_root}/util/third_party/freertos/kernel/queue.c", "${efr32_sdk_root}/util/third_party/freertos/kernel/stream_buffer.c", "${efr32_sdk_root}/util/third_party/freertos/kernel/tasks.c", diff --git a/third_party/zap/repo b/third_party/zap/repo index d57a2656ed73c1..85a7080f6d1c17 160000 --- a/third_party/zap/repo +++ b/third_party/zap/repo @@ -1 +1 @@ -Subproject commit d57a2656ed73c12a72e393ab65cb0a729b9593a9 +Subproject commit 85a7080f6d1c17ec0bc4a6698a3dfd1f6bff7ce7