Skip to content

Commit 5477dd4

Browse files
committed
Merge branch 'configs_for_controller_ram_optimizatin' into 'main'
examples/controller: add configs for controller RAM optimization See merge request app-frameworks/esp-matter!1039
2 parents 66dbd75 + 6f68333 commit 5477dd4

6 files changed

+67
-3
lines changed

examples/controller/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,14 @@ I cannot send commands to the light from the controller:
9898
- If you are still facing issues, reproduce the issue on the default example for the device and then raise an [issue](https://github.com/espressif/esp-matter/issues). Make sure to share these:
9999
- The complete device logs for both the devices taken over UART.
100100
- The esp-matter and esp-idf branch you are using.
101+
102+
### A1.3 RAM optimization
103+
- The `sdkconfig.defaults.ram_optimization` file is provided for RAM optimization. These configurations enable SPIRAM (CONFIG_SPIRAM=y) and allow the BSS segment to be placed in SPIRAM (CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY). With these configurations, [linker file](./main/linker.lf) can move move BSS segments of certain main controller libraries to SPIRAM. Build the example with the sdkconfig:
104+
```
105+
idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.ram_optimization" set-target esp32s3 build
106+
```
107+
- The OTBR's sdkconfig file `sdkconfig.defaults.otbr` has RAM optimization configurations enabled by default.
108+
- If you encounter a crash with error message: "PSRAM chip not found or not supported, or wrong PSRAM line mode", please check whether the module has SPIRAM and if the SPIRAM mode is configured correctly:
109+
- For 2MB SPIRAM, set `CONFIG_SPIRAM_MODE_QUAD=y`
110+
- For SPIRAM larger than 2MB, set `CONFIG_SPIRAM_MODE_OCT=y`
111+
- Refer to [linker](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/optimizations.html#configuration-options-to-optimize-ram-and-flash) for other options to optimize RAM and Flash.

examples/controller/main/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
idf_component_register(SRC_DIRS "."
22
INCLUDE_DIRS "."
3-
PRIV_INCLUDE_DIRS "." "${ESP_MATTER_PATH}/examples/common/utils")
3+
PRIV_INCLUDE_DIRS "." "${ESP_MATTER_PATH}/examples/common/utils"
4+
LDFRAGMENTS "linker.lf")
45

56
if(CONFIG_SPIFFS_ATTESTATION_TRUST_STORE)
67
spiffs_create_partition_image(paa_cert ${CMAKE_SOURCE_DIR}/paa_cert FLASH_IN_PROJECT)

examples/controller/main/app_main.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
4848
#if CONFIG_OPENTHREAD_BORDER_ROUTER
4949
static bool sThreadBRInitialized = false;
5050
if (!sThreadBRInitialized) {
51+
// TODO: Remove InitThreadStack() and StartThreadTask() if submodule contains the fix
52+
// (https://github.com/project-chip/connectedhomeip/pull/37033)
53+
if (chip::DeviceLayer::ThreadStackMgr().InitThreadStack() != CHIP_NO_ERROR ||
54+
chip::DeviceLayer::ThreadStackMgr().StartThreadTask() != CHIP_NO_ERROR) {
55+
break;
56+
}
5157
esp_openthread_set_backbone_netif(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"));
5258
esp_openthread_lock_acquire(portMAX_DELAY);
5359
esp_openthread_border_router_init();

examples/controller/main/linker.lf

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[mapping:CHIP]
2+
archive: libCHIP.a
3+
entries:
4+
if SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y:
5+
* (extram_bss)
6+
else:
7+
* (default)
8+
9+
[mapping:esp_matter]
10+
archive: libesp_matter.a
11+
entries:
12+
if SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y:
13+
* (extram_bss)
14+
else:
15+
* (default)
16+
17+
[mapping:main]
18+
archive: libmain.a
19+
entries:
20+
if SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y:
21+
* (extram_bss)
22+
else:
23+
* (default)
24+
25+
[mapping:openthread_bss]
26+
archive: libopenthread.a
27+
entries:
28+
if SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y && OPENTHREAD_ENABLED = y:
29+
* (extram_bss)
30+
else:
31+
* (default)

examples/controller/sdkconfig.defaults.otbr

+6-2
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ CONFIG_CHIP_PROJECT_CONFIG="main/matter_project_config.h"
7474
# Enable ble controller
7575
CONFIG_ENABLE_ESP32_BLE_CONTROLLER=y
7676

77-
# SPIRAM
77+
# Use SPIRAM and external alloc
7878
CONFIG_SPIRAM=y
79+
CONFIG_SPIRAM_MODE_QUAD=y
7980
CONFIG_SPIRAM_SPEED_80M=y
8081
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=512
81-
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=8192
82+
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=16384
8283
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
8384
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
85+
CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL=y
86+
CONFIG_ESP_MATTER_MEM_ALLOC_MODE_EXTERNAL=y
87+
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
8488

8589
# Enable HKDF for mbedtls
8690
CONFIG_MBEDTLS_HKDF_C=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Use SPIRAM and external alloc
2+
CONFIG_SPIRAM=y
3+
CONFIG_SPIRAM_SPEED_80M=y
4+
CONFIG_SPIRAM_MODE_OCT=y
5+
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=512
6+
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=16384
7+
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
8+
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
9+
CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL=y
10+
CONFIG_ESP_MATTER_MEM_ALLOC_MODE_EXTERNAL=y
11+
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y

0 commit comments

Comments
 (0)