Skip to content

Commit

Permalink
[EFR32] Enable SED build option (#13886)
Browse files Browse the repository at this point in the history
* Add support for Sleepy End Device in EFR32 examples and add power manager to enable and handle  MCU sleep modes

* Rework efr32 build script, add some info for SED build in the examples readme  & restyle

* Restyled by prettier-markdown

* Fix non SED build, Correct typo

* Restyled by gn

* Add sed,SED and ftd to wordlist for spellcheck errors

* rename argument sleepy_device to enable_sleepy_device

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
jmartinez-silabs and restyled-commits authored Jan 25, 2022
1 parent e2fe13a commit c428576
Show file tree
Hide file tree
Showing 25 changed files with 285 additions and 230 deletions.
2 changes: 2 additions & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ FreeRTOSConfig
fsl
fstab
fsync
ftd
fullclean
gbl
gcloud
Expand Down Expand Up @@ -887,6 +888,7 @@ SDK's
SDKs
SDKTARGETSYSROOT
sdl
SED
SEGGER
semver
sendto
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ check_system_includes = true
default_args = {
target_cpu = "arm"
target_os = "freertos"

chip_openthread_ftd = true
import("//args.gni")
}
3 changes: 3 additions & 0 deletions examples/lighting-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ declare_args() {
# Monitor & log memory usage at runtime.
enable_heap_monitoring = false

# Enable Sleepy end device
enable_sleepy_device = false

# Wifi related stuff - they are overriden by gn -args="use_wf200=true"
use_wf200 = false
use_rs911x = false
Expand Down
21 changes: 19 additions & 2 deletions examples/lighting-app/efr32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" enable_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
Expand All @@ -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

<a name="flashing"></a>

## Flashing the Application
Expand Down
1 change: 0 additions & 1 deletion examples/lighting-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")
pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
chip_enable_openthread = true
chip_openthread_ftd = true
chip_system_config_use_open_thread_udp = true
48 changes: 2 additions & 46 deletions examples/lighting-app/efr32/include/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,14 @@ extern "C" {
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/

/* Set configCREATE_LOW_POWER_DEMO as follows:
*
* 0: Build the full test and demo application.
* 1: Build the simple blinky tickless low power demo, generating the tick
* interrupt from the RTCC. EM2 will be entered. The LXFO clock is used.
* See the comments at the top of main.c, main_full.c and main_low_power.c for
* more information.
*/

#define configCREATE_LOW_POWER_DEMO (0)

/* Some configuration is dependent on the demo being built. */
#if (configCREATE_LOW_POWER_DEMO == 0)

/* Tickless mode is not used. */

/* Some of the standard demo test tasks assume a tick rate of 1KHz, even
though that is faster than would normally be warranted by a real
application. */
#define configTICK_RATE_HZ (1000)

/* Energy saving modes. */
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#define configUSE_TICKLESS_IDLE 1
#else
#define configUSE_TICKLESS_IDLE 0
#endif
#endif // SL_CATALOG_POWER_MANAGER_PRESENT

#define configTICK_RATE_HZ (1000)
/* Definition used by Keil to replace default system clock source. */
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 1

Expand All @@ -164,30 +144,6 @@ application. */
#define configUSE_MALLOC_FAILED_HOOK (1)
#define configUSE_IDLE_HOOK (1)

#define configENERGY_MODE (sleepEM1)

#else

/* Tickless idle mode, generating RTOS tick interrupts from the RTC, fed
by the LXFO clock. */

/* The slow clock used to generate the tick interrupt in the low power demo
runs at 32768/8=4096Hz. Ensure the tick rate is a multiple of the clock. */
#define configTICK_RATE_HZ (128)

/* The low power demo uses the tickless idle feature. */
#define configUSE_TICKLESS_IDLE (1)
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION (1)

/* Hook function related definitions. */
#define configUSE_TICK_HOOK (0)
#define configCHECK_FOR_STACK_OVERFLOW (0)
#define configUSE_MALLOC_FAILED_HOOK (0)
#define configUSE_IDLE_HOOK (1)

#define configENERGY_MODE (sleepEM3)
#endif

/* Main functions*/
/* Run time stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS (0)
Expand Down
7 changes: 7 additions & 0 deletions examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ int main(void)
appError(ret);
}

#if CHIP_DEVICE_CONFIG_THREAD_FTD
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
#else // CHIP_DEVICE_CONFIG_THREAD_FTD
#if CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
#endif // CHIP_DEVICE_CONFIG_THREAD_FTD
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("ConnectivityMgr().SetThreadDeviceType() failed");
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/efr32/.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ check_system_includes = true
default_args = {
target_cpu = "arm"
target_os = "freertos"

chip_openthread_ftd = true
import("//args.gni")
}
3 changes: 3 additions & 0 deletions examples/lock-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ declare_args() {
# Monitor & log memory usage at runtime.
enable_heap_monitoring = false

# Enable Sleepy end device
enable_sleepy_device = false

# Wifi related stuff - they are overriden by gn -args="use_wf200=true"
use_wf200 = false
use_rs911x = false
Expand Down
30 changes: 29 additions & 1 deletion examples/lock-app/efr32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -98,6 +98,34 @@ 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" enable_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

<a name="flashing"></a>

## Flashing the Application
Expand Down
1 change: 0 additions & 1 deletion examples/lock-app/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ import("${chip_root}/src/platform/EFR32/args.gni")
efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain")

chip_enable_openthread = true
chip_openthread_ftd = true
pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
48 changes: 2 additions & 46 deletions examples/lock-app/efr32/include/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,14 @@ extern "C" {
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/

/* Set configCREATE_LOW_POWER_DEMO as follows:
*
* 0: Build the full test and demo application.
* 1: Build the simple blinky tickless low power demo, generating the tick
* interrupt from the RTCC. EM2 will be entered. The LXFO clock is used.
* See the comments at the top of main.c, main_full.c and main_low_power.c for
* more information.
*/

#define configCREATE_LOW_POWER_DEMO (0)

/* Some configuration is dependent on the demo being built. */
#if (configCREATE_LOW_POWER_DEMO == 0)

/* Tickless mode is not used. */

/* Some of the standard demo test tasks assume a tick rate of 1KHz, even
though that is faster than would normally be warranted by a real
application. */
#define configTICK_RATE_HZ (1000)

/* Energy saving modes. */
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
#define configUSE_TICKLESS_IDLE 1
#else
#define configUSE_TICKLESS_IDLE 0
#endif
#endif // SL_CATALOG_POWER_MANAGER_PRESENT

#define configTICK_RATE_HZ (1000)
/* Definition used by Keil to replace default system clock source. */
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 1

Expand All @@ -164,30 +144,6 @@ application. */
#define configUSE_MALLOC_FAILED_HOOK (1)
#define configUSE_IDLE_HOOK (1)

#define configENERGY_MODE (sleepEM1)

#else

/* Tickless idle mode, generating RTOS tick interrupts from the RTC, fed
by the LXFO clock. */

/* The slow clock used to generate the tick interrupt in the low power demo
runs at 32768/8=4096Hz. Ensure the tick rate is a multiple of the clock. */
#define configTICK_RATE_HZ (128)

/* The low power demo uses the tickless idle feature. */
#define configUSE_TICKLESS_IDLE (1)
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION (1)

/* Hook function related definitions. */
#define configUSE_TICK_HOOK (0)
#define configCHECK_FOR_STACK_OVERFLOW (0)
#define configUSE_MALLOC_FAILED_HOOK (0)
#define configUSE_IDLE_HOOK (1)

#define configENERGY_MODE (sleepEM3)
#endif

/* Main functions*/
/* Run time stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS (0)
Expand Down
7 changes: 7 additions & 0 deletions examples/lock-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ int main(void)
appError(ret);
}

#if CHIP_DEVICE_CONFIG_THREAD_FTD
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_Router);
#else // CHIP_DEVICE_CONFIG_THREAD_FTD
#if CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
#endif // CHIP_DEVICE_CONFIG_THREAD_FTD
if (ret != CHIP_NO_ERROR)
{
EFR32_LOG("ConnectivityMgr().SetThreadDeviceType() failed");
Expand Down
15 changes: 15 additions & 0 deletions examples/platform/efr32/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ extern "C" {
#include <stddef.h>
#include <string.h>

#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
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/window-app/efr32/.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ check_system_includes = true
default_args = {
target_cpu = "arm"
target_os = "freertos"

chip_openthread_ftd = true
import("//args.gni")
}
3 changes: 3 additions & 0 deletions examples/window-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ declare_args() {
# Monitor & log memory usage at runtime.
enable_heap_monitoring = false

# Enable Sleepy end device
enable_sleepy_device = false

# Wifi related stuff - they are overriden by gn -args="use_wf200=true"
use_wf200 = false
use_rs911x = false
Expand Down
Loading

0 comments on commit c428576

Please sign in to comment.