Skip to content

Commit 6499d2c

Browse files
jmartinez-silabspull[bot]
authored andcommitted
[EFR32] Rework NVM3 instances and refactor our KVS implementation to 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
1 parent edac4ac commit 6499d2c

File tree

28 files changed

+427
-659
lines changed

28 files changed

+427
-659
lines changed

.github/.wordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ NTAG
865865
nullable
866866
nullptr
867867
NUM
868+
NVM
868869
nwk
869870
NXP
870871
objcopy

examples/light-switch-app/efr32/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,12 @@ is_debug
406406
show_qr_code
407407
408408
$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A "show_qr_code=false"
409+
410+
### KVS maximum entry count
411+
412+
kvs_max_entries
413+
414+
Set the maximum Kvs entries that can be stored in NVM (Default 75)
415+
Thresholds: 30 <= kvs_max_entries <= 255
416+
417+
$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A kvs_max_entries=50

examples/light-switch-app/efr32/src/main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ int main(void)
132132
EFR32_LOG("Init CHIP Stack");
133133
// Init Chip memory management before the stack
134134
chip::Platform::MemoryInit();
135-
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
136135

137136
CHIP_ERROR ret = PlatformMgr().InitChipStack();
138137
if (ret != CHIP_NO_ERROR)

examples/lighting-app/efr32/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,12 @@ is_debug
356356
show_qr_code
357357
358358
$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A "show_qr_code=false"
359+
360+
### KVS maximum entry count
361+
362+
kvs_max_entries
363+
364+
Set the maximum Kvs entries that can be stored in NVM (Default 75)
365+
Thresholds: 30 <= kvs_max_entries <= 255
366+
367+
$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A kvs_max_entries=50

examples/lighting-app/efr32/src/main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ int main(void)
136136
EFR32_LOG("Init CHIP Stack");
137137
// Init Chip memory management before the stack
138138
chip::Platform::MemoryInit();
139-
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
140139

141140
CHIP_ERROR ret = PlatformMgr().InitChipStack();
142141
if (ret != CHIP_NO_ERROR)

examples/lock-app/efr32/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,12 @@ is_debug
321321
show_qr_code
322322
323323
$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A "show_qr_code=false"
324+
325+
### KVS maximum entry count
326+
327+
kvs_max_entries
328+
329+
Set the maximum Kvs entries that can be stored in NVM (Default 75)
330+
Thresholds: 30 <= kvs_max_entries <= 255
331+
332+
$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A kvs_max_entries=50

examples/lock-app/efr32/src/main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ int main(void)
132132

133133
// Init Chip memory management before the stack
134134
chip::Platform::MemoryInit();
135-
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
136135

137136
CHIP_ERROR ret = PlatformMgr().InitChipStack();
138137
if (ret != CHIP_NO_ERROR)

examples/ota-requestor-app/efr32/src/main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ int main(void)
169169
EFR32_LOG("Init CHIP Stack");
170170
// Init Chip memory management before the stack
171171
chip::Platform::MemoryInit();
172-
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
173172

174173
CHIP_ERROR ret = PlatformMgr().InitChipStack();
175174
if (ret != CHIP_NO_ERROR)

examples/persistent-storage/efr32/BUILD.gn

+4-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ efr32_sdk("sdk") {
3737
"${chip_root}/src/platform/EFR32",
3838
"${efr32_project_dir}/include",
3939
"${examples_plat_dir}",
40+
"${chip_root}/src/lib",
4041
]
4142

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

4849
sources = [
49-
"${efr32_project_dir}/../KeyValueStorageTest.cpp",
5050
"${examples_plat_dir}/heap_4_silabs.c",
5151
"${examples_plat_dir}/init_efrPlatform.cpp",
52+
"../KeyValueStorageTest.cpp",
5253
"main.cpp",
5354
]
5455

5556
deps = [
5657
":sdk",
57-
"$dir_pw_assert",
58-
"$dir_pw_kvs:crc16",
5958
"${chip_root}/src/lib",
6059
]
6160

6261
include_dirs = [
63-
"${efr32_project_dir}/..",
64-
"${efr32_project_dir}/include",
62+
"..",
63+
"include",
6564
]
6665

6766
ldscript = "${examples_plat_dir}/ldscripts/${efr32_family}.ld"

examples/persistent-storage/efr32/README.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,7 @@ platforms.
2828

2929
## EFR32
3030

31-
The EFR32 platform KVS is fully implemented, the KVS is enabled and configured
32-
using these defines:
33-
34-
```
35-
defines = [
36-
"CHIP_KVS_SECTOR_COUNT=4",
37-
"CHIP_KVS_BASE_SECTOR_INDEX=((FLASH_SIZE/FLASH_PAGE_SIZE)-(CHIP_KVS_SECTOR_COUNT))",
38-
]
39-
```
31+
The EFR32 platform KVS is fully implemented
4032

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

examples/persistent-storage/efr32/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "KeyValueStorageTest.h"
3232
#include "init_efrPlatform.h"
3333
#include "sl_system_kernel.h"
34+
#include <platform/CHIPDeviceLayer.h>
35+
#include <platform/EFR32/EFR32Config.h>
3436
#include <platform/KeyValueStoreManager.h>
3537

3638
static TaskHandle_t sTestTaskHandle;

examples/platform/efr32/ldscripts/efr32mg12.ld

+13-32
Original file line numberDiff line numberDiff line change
@@ -177,36 +177,6 @@ SECTIONS
177177

178178
__etext = .;
179179

180-
/*******************************************************************/
181-
/* Define flash block for BLE-simee & chip-nvm3 */
182-
/* simee: 9000H (36k) bytes for BLE nvm3 */
183-
/* chipNvm3_section: 4000H (16k) bytes for chip nvm3. */
184-
/* 8K is reserved for OpenThread's NVM which is mapped directly at */
185-
/* the top of flash */
186-
/*******************************************************************/
187-
188-
OPENTHREAD_NVM_SIZE = 8192;
189-
190-
.nvm_dummy (DSECT):
191-
{
192-
__nvm3_dummy_begin = .;
193-
. = ALIGN (8192);
194-
__nvm3_dummy_simee = .;
195-
KEEP(*(.simee));
196-
. = ALIGN (8192);
197-
__nvm3_dummy_chip = .;
198-
KEEP(*(chipNvm3_section));
199-
. = ALIGN (8192);
200-
. += DEFINED(SILABS_WIFI) ? 0 : OPENTHREAD_NVM_SIZE;
201-
. = DEFINED(SILABS_WIFI) ? . : ALIGN (8192);
202-
} > FLASH
203-
204-
/* Set NVM to end of FLASH */
205-
__nvm3Base = LENGTH(FLASH) - SIZEOF(.nvm_dummy) + (__nvm3_dummy_simee - __nvm3_dummy_begin);
206-
__chipNvm3Base = LENGTH(FLASH) - SIZEOF(.nvm_dummy) + (__nvm3_dummy_chip - __nvm3_dummy_begin);
207-
208-
209-
/*******************************************************************/
210180

211181
.data : AT (__etext)
212182
{
@@ -264,6 +234,8 @@ SECTIONS
264234
KEEP(*(.heap*))
265235
__HeapLimit = .;
266236
} > RAM
237+
238+
__main_flash_end__ = ORIGIN(FLASH) + LENGTH(FLASH);
267239

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

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

258+
linker_nvm_end = __main_flash_end__ - 2048;
259+
linker_nvm_begin = linker_nvm_end - SIZEOF(.nvm);
260+
linker_nvm_size = SIZEOF(.nvm);
261+
__nvm3Base = linker_nvm_begin;
262+
263+
/* Check if data + heap + stack exceeds RAM limit */
264+
/*ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")*/
265+
ASSERT( (linker_nvm_begin + SIZEOF(.nvm)) <= __main_flash_end__, "NVM3 is excessing the flash size !")
285266

286267
/* Check if FLASH usage exceeds FLASH size */
287268
ASSERT( LENGTH(FLASH) >= (__etext), "FLASH memory overflowed !")

examples/platform/efr32/ldscripts/efr32mg24.ld

+13-35
Original file line numberDiff line numberDiff line change
@@ -177,36 +177,6 @@ SECTIONS
177177

178178
__etext = .;
179179

180-
/*******************************************************************/
181-
/* Define flash block for BLE-simee & chip-nvm3 */
182-
/* simee: 9000H (36k) bytes for BLE nvm3 */
183-
/* chipNvm3_section: 4000H (16k) bytes for chip nvm3. */
184-
/* 8K is reserved for OpenThread's NVM which is mapped directly at */
185-
/* the top of flash */
186-
/*******************************************************************/
187-
188-
OPENTHREAD_NVM_SIZE = 8192;
189-
190-
.nvm_dummy (DSECT):
191-
{
192-
__nvm3_dummy_begin = .;
193-
. = ALIGN (8192);
194-
__nvm3_dummy_simee = .;
195-
KEEP(*(.simee));
196-
. = ALIGN (8192);
197-
__nvm3_dummy_chip = .;
198-
KEEP(*(chipNvm3_section));
199-
. = ALIGN (8192);
200-
. += DEFINED(SILABS_WIFI) ? 0 : OPENTHREAD_NVM_SIZE;
201-
. = DEFINED(SILABS_WIFI) ? . : ALIGN (8192);
202-
} > FLASH
203-
204-
/* Set NVM to end of FLASH */
205-
__nvm3Base = (ORIGIN(FLASH) + LENGTH(FLASH)) - SIZEOF(.nvm_dummy) + (__nvm3_dummy_simee - __nvm3_dummy_begin);
206-
__chipNvm3Base = (ORIGIN(FLASH) + LENGTH(FLASH)) - SIZEOF(.nvm_dummy) + (__nvm3_dummy_chip - __nvm3_dummy_begin);
207-
208-
209-
/*******************************************************************/
210180

211181
.data : AT (__etext)
212182
{
@@ -265,6 +235,8 @@ SECTIONS
265235
__HeapLimit = .;
266236
} > RAM
267237

238+
__main_flash_end__ = ORIGIN(FLASH) + LENGTH(FLASH);
239+
268240
/* .stack_dummy section doesn't contains any symbols. It is only
269241
* used for linker to calculate size of stack sections, and assign
270242
* values to stack symbols later */
@@ -279,11 +251,17 @@ SECTIONS
279251
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
280252
PROVIDE(__stack = __StackTop);
281253

282-
/* Check if data + heap + stack exceeds RAM limit */
283-
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
254+
.nvm (DSECT) : {
255+
KEEP(*(.simee*))
256+
} > FLASH
257+
258+
linker_nvm_end = __main_flash_end__;
259+
linker_nvm_begin = linker_nvm_end - SIZEOF(.nvm);
260+
linker_nvm_size = SIZEOF(.nvm);
261+
__nvm3Base = linker_nvm_begin;
284262

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

286-
/* Check if FLASH usage exceeds FLASH size */
287-
ASSERT( (ORIGIN(FLASH) + LENGTH(FLASH)) >= (__etext + SIZEOF(.data)), "FLASH memory overflowed !")
288-
ASSERT((__etext + SIZEOF(.data)) <= __nvm3Base, "FLASH memory overlapped with NVM section.")
289267
}

examples/shell/efr32/src/main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ int main(void)
110110

111111
// Init Chip memory management before the stack
112112
chip::Platform::MemoryInit();
113-
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
114113

115114
CHIP_ERROR ret = PlatformMgr().InitChipStack();
116115
if (ret != CHIP_NO_ERROR)

examples/window-app/efr32/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,12 @@ is_debug
356356
show_qr_code
357357
358358
$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A "show_qr_code=false"
359+
360+
### KVS maximum entry count
361+
362+
kvs_max_entries
363+
364+
Set the maximum Kvs entries that can be stored in NVM (Default 75)
365+
Thresholds: 30 <= kvs_max_entries <= 255
366+
367+
$ ./scripts/examples/gn_efr32_example.sh ./examples/lighting-app/efr32 ./out/lighting-app BRD4164A kvs_max_entries=50

examples/window-app/efr32/src/main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ int main(void)
108108

109109
// Init Chip memory management before the stack
110110
chip::Platform::MemoryInit();
111-
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init();
112111

113112
err = PlatformMgr().InitChipStack();
114113
if (err != CHIP_NO_ERROR)

scripts/examples/gn_efr32_example.sh

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ source "$(dirname "$0")/../../scripts/activate.sh"
2424
set -x
2525
env
2626
USE_WIFI=false
27-
27+
CHIP_ROOT="$(dirname "$0")/../.."
2828
USAGE="./scripts/examples/gn_efr32_example.sh <AppRootFolder> <outputFolder> <efr32_board_name> [<Build options>]"
2929

3030
if [ "$#" == "0" ]; then
@@ -63,6 +63,9 @@ if [ "$#" == "0" ]; then
6363
Monitor & log memory usage at runtime. (Default false)
6464
enable_openthread_cli
6565
Enables openthread cli without matter shell. (Default true)
66+
kvs_max_entries
67+
Set the maxium Kvs entries that can be store in NVM (Default 75)
68+
Thresholds: 30 <= kvs_max_entries <= 255
6669
show_qr_code
6770
Enables QR code on LCD for devices with an LCD
6871
setupDiscriminator
@@ -144,14 +147,14 @@ else
144147
BUILD_DIR=$OUTDIR/$EFR32_BOARD
145148
echo BUILD_DIR="$BUILD_DIR"
146149
if [ "$USE_WIFI" == true ]; then
147-
gn gen --check --fail-on-unused-args --root="$ROOT" --dotfile="$ROOT"/build_for_wifi_gnfile.gn --args="efr32_board=\"$EFR32_BOARD\" $optArgs" "$BUILD_DIR"
150+
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"
148151
else
149152
# thread build
150153
#
151154
if [ -z "$optArgs" ]; then
152-
gn gen --check --fail-on-unused-args --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\"" "$BUILD_DIR"
155+
gn gen --check --fail-on-unused-args --export-compile-commands --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\"" "$BUILD_DIR"
153156
else
154-
gn gen --check --fail-on-unused-args --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\" $optArgs" "$BUILD_DIR"
157+
gn gen --check --fail-on-unused-args --export-compile-commands --root="$ROOT" --args="efr32_board=\"$EFR32_BOARD\" $optArgs" "$BUILD_DIR"
155158
fi
156159
fi
157160
ninja -v -C "$BUILD_DIR"/

src/platform/EFR32/BLEManagerImpl.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ namespace {
7676
#define BLE_CONFIG_RF_PATH_GAIN_TX (0)
7777
#define BLE_CONFIG_RF_PATH_GAIN_RX (0)
7878

79+
// Default Connection parameters
80+
#define BLE_CONFIG_MIN_INTERVAL (16) // Time = Value x 1.25 ms = 30ms
81+
#define BLE_CONFIG_MAX_INTERVAL (80) // Time = Value x 1.25 ms = 100ms
82+
#define BLE_CONFIG_LATENCY (0)
83+
#define BLE_CONFIG_TIMEOUT (100) // Time = Value x 10 ms = 1s
84+
#define BLE_CONFIG_MIN_CE_LENGTH (0) // Leave to min value
85+
#define BLE_CONFIG_MAX_CE_LENGTH (0xFFFF) // Leave to max value
86+
7987
TimerHandle_t sbleAdvTimeoutTimer; // FreeRTOS sw timer.
8088

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

@@ -257,7 +267,7 @@ void BLEManagerImpl::bluetoothStackEventHandler(void * p_arg)
257267
}
258268
break;
259269
case sl_bt_evt_connection_parameters_id: {
260-
// ChipLogProgress(DeviceLayer, "Connection parameter ID received. Nothing to do");
270+
// ChipLogProgress(DeviceLayer, "Connection parameter ID received");
261271
}
262272
break;
263273
case sl_bt_evt_connection_phy_status_id: {
@@ -307,6 +317,11 @@ void BLEManagerImpl::bluetoothStackEventHandler(void * p_arg)
307317
}
308318
break;
309319

320+
case sl_bt_evt_connection_remote_used_features_id: {
321+
// ChipLogProgress(DeviceLayer, "link layer features supported by the remote device");
322+
}
323+
break;
324+
310325
default:
311326
ChipLogProgress(DeviceLayer, "evt_UNKNOWN id = %08" PRIx32, SL_BT_MSG_ID(bluetooth_evt->header));
312327
break;

0 commit comments

Comments
 (0)