Skip to content

Commit

Permalink
[EFR32] Rework NVM3 instances and refactor our KVS implementation to …
Browse files Browse the repository at this point in the history
…use nvm3 (#16877)

* Merge chip_nvm3 section into silabs default nvm3 section. Rework the efr32Config nvm3 driver, tweaks to linkerfile for the nvm3 section

* Refactore efr32 kvs implementation to use silabs nvm3 driver

* Fix some return codes for KVS

* Update ldscript for mg24. Add verifications in kvs implementation. Regroup nvm3 and kvs init. Set ble default connection params

* Delay keymap commit to nvm, Build argument for kvs entry count, Clean up

* Add build option in efr32_sdk.gni and  detail in build script

* add info in read me

* Fix typo, add NVM to wordlist

* undo unwanted change to zap and pigweed submodule.

* remove mv command
  • Loading branch information
jmartinez-silabs authored and pull[bot] committed Dec 11, 2023
1 parent da0c9c4 commit 9915812
Show file tree
Hide file tree
Showing 28 changed files with 427 additions and 659 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ NTAG
nullable
nullptr
NUM
NVM
nwk
NXP
objcopy
Expand Down
9 changes: 9 additions & 0 deletions examples/light-switch-app/efr32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,12 @@ is_debug
show_qr_code

$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A "show_qr_code=false"

### KVS maximum entry count

kvs_max_entries

Set the maximum Kvs entries that can be stored in NVM (Default 75)
Thresholds: 30 <= kvs_max_entries <= 255

$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A kvs_max_entries=50
1 change: 0 additions & 1 deletion examples/light-switch-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ int main(void)
EFR32_LOG("Init CHIP Stack");
// Init Chip memory management before the stack
chip::Platform::MemoryInit();
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();

CHIP_ERROR ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
Expand Down
9 changes: 9 additions & 0 deletions examples/lighting-app/efr32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,12 @@ is_debug
show_qr_code

$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A "show_qr_code=false"

### KVS maximum entry count

kvs_max_entries

Set the maximum Kvs entries that can be stored in NVM (Default 75)
Thresholds: 30 <= kvs_max_entries <= 255

$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A kvs_max_entries=50
1 change: 0 additions & 1 deletion examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ int main(void)
EFR32_LOG("Init CHIP Stack");
// Init Chip memory management before the stack
chip::Platform::MemoryInit();
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();

CHIP_ERROR ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
Expand Down
9 changes: 9 additions & 0 deletions examples/lock-app/efr32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,12 @@ is_debug
show_qr_code

$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A "show_qr_code=false"

### KVS maximum entry count

kvs_max_entries

Set the maximum Kvs entries that can be stored in NVM (Default 75)
Thresholds: 30 <= kvs_max_entries <= 255

$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A kvs_max_entries=50
1 change: 0 additions & 1 deletion examples/lock-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ int main(void)

// Init Chip memory management before the stack
chip::Platform::MemoryInit();
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();

CHIP_ERROR ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
Expand Down
1 change: 0 additions & 1 deletion examples/ota-requestor-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ int main(void)
EFR32_LOG("Init CHIP Stack");
// Init Chip memory management before the stack
chip::Platform::MemoryInit();
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();

CHIP_ERROR ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
Expand Down
9 changes: 4 additions & 5 deletions examples/persistent-storage/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ efr32_sdk("sdk") {
"${chip_root}/src/platform/EFR32",
"${efr32_project_dir}/include",
"${examples_plat_dir}",
"${chip_root}/src/lib",
]

defines = [ "BOARD_ID=${efr32_board}" ]
Expand All @@ -46,22 +47,20 @@ efr32_executable("persistent_storage") {
output_name = "chip-efr32-persistent_storage-example.out"

sources = [
"${efr32_project_dir}/../KeyValueStorageTest.cpp",
"${examples_plat_dir}/heap_4_silabs.c",
"${examples_plat_dir}/init_efrPlatform.cpp",
"../KeyValueStorageTest.cpp",
"main.cpp",
]

deps = [
":sdk",
"$dir_pw_assert",
"$dir_pw_kvs:crc16",
"${chip_root}/src/lib",
]

include_dirs = [
"${efr32_project_dir}/..",
"${efr32_project_dir}/include",
"..",
"include",
]

ldscript = "${examples_plat_dir}/ldscripts/${efr32_family}.ld"
Expand Down
10 changes: 1 addition & 9 deletions examples/persistent-storage/efr32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ platforms.

## EFR32

The EFR32 platform KVS is fully implemented, the KVS is enabled and configured
using these defines:

```
defines = [
"CHIP_KVS_SECTOR_COUNT=4",
"CHIP_KVS_BASE_SECTOR_INDEX=((FLASH_SIZE/FLASH_PAGE_SIZE)-(CHIP_KVS_SECTOR_COUNT))",
]
```
The EFR32 platform KVS is fully implemented

<a name="building"></a>

Expand Down
2 changes: 2 additions & 0 deletions examples/persistent-storage/efr32/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "KeyValueStorageTest.h"
#include "init_efrPlatform.h"
#include "sl_system_kernel.h"
#include <platform/CHIPDeviceLayer.h>
#include <platform/EFR32/EFR32Config.h>
#include <platform/KeyValueStoreManager.h>

static TaskHandle_t sTestTaskHandle;
Expand Down
45 changes: 13 additions & 32 deletions examples/platform/efr32/ldscripts/efr32mg12.ld
Original file line number Diff line number Diff line change
Expand Up @@ -177,36 +177,6 @@ SECTIONS

__etext = .;

/*******************************************************************/
/* Define flash block for BLE-simee & chip-nvm3 */
/* simee: 9000H (36k) bytes for BLE nvm3 */
/* chipNvm3_section: 4000H (16k) bytes for chip nvm3. */
/* 8K is reserved for OpenThread's NVM which is mapped directly at */
/* the top of flash */
/*******************************************************************/

OPENTHREAD_NVM_SIZE = 8192;

.nvm_dummy (DSECT):
{
__nvm3_dummy_begin = .;
. = ALIGN (8192);
__nvm3_dummy_simee = .;
KEEP(*(.simee));
. = ALIGN (8192);
__nvm3_dummy_chip = .;
KEEP(*(chipNvm3_section));
. = ALIGN (8192);
. += DEFINED(SILABS_WIFI) ? 0 : OPENTHREAD_NVM_SIZE;
. = DEFINED(SILABS_WIFI) ? . : ALIGN (8192);
} > FLASH

/* Set NVM to end of FLASH */
__nvm3Base = LENGTH(FLASH) - SIZEOF(.nvm_dummy) + (__nvm3_dummy_simee - __nvm3_dummy_begin);
__chipNvm3Base = LENGTH(FLASH) - SIZEOF(.nvm_dummy) + (__nvm3_dummy_chip - __nvm3_dummy_begin);


/*******************************************************************/

.data : AT (__etext)
{
Expand Down Expand Up @@ -264,6 +234,8 @@ SECTIONS
KEEP(*(.heap*))
__HeapLimit = .;
} > RAM

__main_flash_end__ = ORIGIN(FLASH) + LENGTH(FLASH);

/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
Expand All @@ -279,9 +251,18 @@ SECTIONS
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);

/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
.nvm (DSECT) : {
KEEP(*(.simee*))
} > FLASH

linker_nvm_end = __main_flash_end__ - 2048;
linker_nvm_begin = linker_nvm_end - SIZEOF(.nvm);
linker_nvm_size = SIZEOF(.nvm);
__nvm3Base = linker_nvm_begin;

/* Check if data + heap + stack exceeds RAM limit */
/*ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")*/
ASSERT( (linker_nvm_begin + SIZEOF(.nvm)) <= __main_flash_end__, "NVM3 is excessing the flash size !")

/* Check if FLASH usage exceeds FLASH size */
ASSERT( LENGTH(FLASH) >= (__etext), "FLASH memory overflowed !")
Expand Down
48 changes: 13 additions & 35 deletions examples/platform/efr32/ldscripts/efr32mg24.ld
Original file line number Diff line number Diff line change
Expand Up @@ -177,36 +177,6 @@ SECTIONS

__etext = .;

/*******************************************************************/
/* Define flash block for BLE-simee & chip-nvm3 */
/* simee: 9000H (36k) bytes for BLE nvm3 */
/* chipNvm3_section: 4000H (16k) bytes for chip nvm3. */
/* 8K is reserved for OpenThread's NVM which is mapped directly at */
/* the top of flash */
/*******************************************************************/

OPENTHREAD_NVM_SIZE = 8192;

.nvm_dummy (DSECT):
{
__nvm3_dummy_begin = .;
. = ALIGN (8192);
__nvm3_dummy_simee = .;
KEEP(*(.simee));
. = ALIGN (8192);
__nvm3_dummy_chip = .;
KEEP(*(chipNvm3_section));
. = ALIGN (8192);
. += DEFINED(SILABS_WIFI) ? 0 : OPENTHREAD_NVM_SIZE;
. = DEFINED(SILABS_WIFI) ? . : ALIGN (8192);
} > FLASH

/* Set NVM to end of FLASH */
__nvm3Base = (ORIGIN(FLASH) + LENGTH(FLASH)) - SIZEOF(.nvm_dummy) + (__nvm3_dummy_simee - __nvm3_dummy_begin);
__chipNvm3Base = (ORIGIN(FLASH) + LENGTH(FLASH)) - SIZEOF(.nvm_dummy) + (__nvm3_dummy_chip - __nvm3_dummy_begin);


/*******************************************************************/

.data : AT (__etext)
{
Expand Down Expand Up @@ -265,6 +235,8 @@ SECTIONS
__HeapLimit = .;
} > RAM

__main_flash_end__ = ORIGIN(FLASH) + LENGTH(FLASH);

/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */
Expand All @@ -279,11 +251,17 @@ SECTIONS
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);

/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
.nvm (DSECT) : {
KEEP(*(.simee*))
} > FLASH

linker_nvm_end = __main_flash_end__;
linker_nvm_begin = linker_nvm_end - SIZEOF(.nvm);
linker_nvm_size = SIZEOF(.nvm);
__nvm3Base = linker_nvm_begin;

/* Check if data + heap + stack exceeds RAM limit */
/*ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")*/
ASSERT( (linker_nvm_begin + SIZEOF(.nvm)) <= __main_flash_end__, "NVM3 is excessing the flash size !")

/* Check if FLASH usage exceeds FLASH size */
ASSERT( (ORIGIN(FLASH) + LENGTH(FLASH)) >= (__etext + SIZEOF(.data)), "FLASH memory overflowed !")
ASSERT((__etext + SIZEOF(.data)) <= __nvm3Base, "FLASH memory overlapped with NVM section.")
}
1 change: 0 additions & 1 deletion examples/shell/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ int main(void)

// Init Chip memory management before the stack
chip::Platform::MemoryInit();
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();

CHIP_ERROR ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
Expand Down
9 changes: 9 additions & 0 deletions examples/window-app/efr32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,12 @@ is_debug
show_qr_code

$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A "show_qr_code=false"

### KVS maximum entry count

kvs_max_entries

Set the maximum Kvs entries that can be stored in NVM (Default 75)
Thresholds: 30 <= kvs_max_entries <= 255

$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A kvs_max_entries=50
1 change: 0 additions & 1 deletion examples/window-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ int main(void)

// Init Chip memory management before the stack
chip::Platform::MemoryInit();
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();

err = PlatformMgr().InitChipStack();
if (err != CHIP_NO_ERROR)
Expand Down
11 changes: 7 additions & 4 deletions scripts/examples/gn_efr32_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ source "$(dirname "$0")/../../scripts/activate.sh"
set -x
env
USE_WIFI=false

CHIP_ROOT="$(dirname "$0")/../.."
USAGE="./scripts/examples/gn_efr32_example.sh <AppRootFolder> <outputFolder> <efr32_board_name> [<Build options>]"

if [ "$#" == "0" ]; then
Expand Down Expand Up @@ -63,6 +63,9 @@ if [ "$#" == "0" ]; then
Monitor & log memory usage at runtime. (Default false)
enable_openthread_cli
Enables openthread cli without matter shell. (Default true)
kvs_max_entries
Set the maxium Kvs entries that can be store in NVM (Default 75)
Thresholds: 30 <= kvs_max_entries <= 255
show_qr_code
Enables QR code on LCD for devices with an LCD
setupDiscriminator
Expand Down Expand Up @@ -144,14 +147,14 @@ else
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"
gn gen --check --fail-on-unused-args --export-compile-commands --root="$ROOT" --dotfile="$ROOT"/build_for_wifi_gnfile.gn --args="efr32_board=\"$EFR32_BOARD\" $optArgs" "$BUILD_DIR"
else
# thread build
#
if [ -z "$optArgs" ]; then
gn gen --check --fail-on-unused-args --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\"" "$BUILD_DIR"
gn gen --check --fail-on-unused-args --export-compile-commands --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"
gn gen --check --fail-on-unused-args --export-compile-commands --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\" $optArgs" "$BUILD_DIR"
fi
fi
ninja -v -C "$BUILD_DIR"/
Expand Down
17 changes: 16 additions & 1 deletion src/platform/EFR32/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ namespace {
#define BLE_CONFIG_RF_PATH_GAIN_TX (0)
#define BLE_CONFIG_RF_PATH_GAIN_RX (0)

// Default Connection parameters
#define BLE_CONFIG_MIN_INTERVAL (16) // Time = Value x 1.25 ms = 30ms
#define BLE_CONFIG_MAX_INTERVAL (80) // Time = Value x 1.25 ms = 100ms
#define BLE_CONFIG_LATENCY (0)
#define BLE_CONFIG_TIMEOUT (100) // Time = Value x 10 ms = 1s
#define BLE_CONFIG_MIN_CE_LENGTH (0) // Leave to min value
#define BLE_CONFIG_MAX_CE_LENGTH (0xFFFF) // Leave to max value

TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer.

/* Bluetooth stack configuration parameters (see "UG136: Silicon Labs Bluetooth C Application Developer's Guide" for
Expand Down Expand Up @@ -249,6 +257,8 @@ void BLEManagerImpl::bluetoothStackEventHandler(void * p_arg)
RAIL_GetVersion(&railVer, true);
ChipLogProgress(DeviceLayer, "RAIL version:, v%d.%d.%d-b%d", railVer.major, railVer.minor, railVer.rev,
railVer.build);
sl_bt_connection_set_default_parameters(BLE_CONFIG_MIN_INTERVAL, BLE_CONFIG_MAX_INTERVAL, BLE_CONFIG_LATENCY,
BLE_CONFIG_TIMEOUT, BLE_CONFIG_MIN_CE_LENGTH, BLE_CONFIG_MAX_CE_LENGTH);
}
break;

Expand All @@ -257,7 +267,7 @@ void BLEManagerImpl::bluetoothStackEventHandler(void * p_arg)
}
break;
case sl_bt_evt_connection_parameters_id: {
// ChipLogProgress(DeviceLayer, "Connection parameter ID received. Nothing to do");
// ChipLogProgress(DeviceLayer, "Connection parameter ID received");
}
break;
case sl_bt_evt_connection_phy_status_id: {
Expand Down Expand Up @@ -307,6 +317,11 @@ void BLEManagerImpl::bluetoothStackEventHandler(void * p_arg)
}
break;

case sl_bt_evt_connection_remote_used_features_id: {
// ChipLogProgress(DeviceLayer, "link layer features supported by the remote device");
}
break;

default:
ChipLogProgress(DeviceLayer, "evt_UNKNOWN id = %08" PRIx32, SL_BT_MSG_ID(bluetooth_evt->header));
break;
Expand Down
Loading

0 comments on commit 9915812

Please sign in to comment.