From 967df46a1b919c283566b68dcabbda336a98fc5c Mon Sep 17 00:00:00 2001 From: Doru Gucea Date: Tue, 31 Aug 2021 00:18:35 -0700 Subject: [PATCH] TE5 fixes As described in https://github.com/project-chip/connectedhomeip/issues/9261 several SRAM optimizations were needed: * decrease the number of Fabrics to 4 (from 16); * use OT MTD lib for the E-Lock App (which is an SED); * decrease the number of OT message buffers to 22(FTD)/10(MTD) - (from 44); * disable LWIP TCP/RAW/Debug/packet buffers. Also, fix a bug in KVS where the deletion of some keys was not done properly. Signed-off-by: Doru Gucea --- examples/lighting-app/k32w/BUILD.gn | 4 ++-- .../k32w/include/CHIPProjectConfig.h | 16 ++++++++++++- examples/lighting-app/k32w/main/AppTask.cpp | 4 ++-- examples/lock-app/k32w/BUILD.gn | 4 ++-- .../lock-app/k32w/include/CHIPProjectConfig.h | 23 ++++++++++++++++++- .../app/project_include/OpenThreadConfig.h | 9 ++++++++ src/lwip/k32w/lwipopts.h | 14 +++++++++-- src/platform/K32W/BUILD.gn | 2 -- src/platform/K32W/K32WConfig.cpp | 15 ++++++------ src/platform/K32W/ThreadStackManagerImpl.cpp | 12 ---------- src/platform/K32W/args.gni | 3 +++ 11 files changed, 74 insertions(+), 32 deletions(-) diff --git a/examples/lighting-app/k32w/BUILD.gn b/examples/lighting-app/k32w/BUILD.gn index 4bcd97e6b91573..b8455a1ba8bbe1 100644 --- a/examples/lighting-app/k32w/BUILD.gn +++ b/examples/lighting-app/k32w/BUILD.gn @@ -73,8 +73,8 @@ k32w_executable("light_app") { "${chip_root}/src/lib", "${chip_root}/third_party/mbedtls:mbedtls", "${k32w_platform_dir}/app/support:freertos_mbedtls_utils", - "${openthread_root}:libopenthread-cli-mtd", - "${openthread_root}:libopenthread-mtd", + "${openthread_root}:libopenthread-cli-ftd", + "${openthread_root}:libopenthread-ftd", ] cflags = [ "-Wconversion" ] diff --git a/examples/lighting-app/k32w/include/CHIPProjectConfig.h b/examples/lighting-app/k32w/include/CHIPProjectConfig.h index f2146ccaddfb72..fe699768250bb8 100644 --- a/examples/lighting-app/k32w/include/CHIPProjectConfig.h +++ b/examples/lighting-app/k32w/include/CHIPProjectConfig.h @@ -176,10 +176,24 @@ */ #define CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT (15 * 60 * 1000) +/** + * CONFIG_CHIP_NFC_COMMISSIONING, CHIP_DEVICE_CONFIG_ENABLE_NFC + * + * Set these defines to 1 if NFC Commissioning is needed + */ #define CONFIG_CHIP_NFC_COMMISSIONING 1 - #define CHIP_DEVICE_CONFIG_ENABLE_NFC 1 +/** + * @def CHIP_CONFIG_MAX_DEVICE_ADMINS + * + * @brief + * Maximum number of administrators that can provision the device. Each admin + * can provision the device with their unique operational credentials and manage + * their access control lists. + */ +#define CHIP_CONFIG_MAX_DEVICE_ADMINS 4 // 3 fabrics + 1 for rotation slack + /** * CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE * diff --git a/examples/lighting-app/k32w/main/AppTask.cpp b/examples/lighting-app/k32w/main/AppTask.cpp index 39457514dd7baf..f5d6657e37d244 100644 --- a/examples/lighting-app/k32w/main/AppTask.cpp +++ b/examples/lighting-app/k32w/main/AppTask.cpp @@ -145,7 +145,7 @@ CHIP_ERROR AppTask::Init() K32W_LOG("Current Firmware Version: %s", currentFirmwareRev); -#ifdef CONFIG_CHIP_NFC_COMMISSIONING +#if CONFIG_CHIP_NFC_COMMISSIONING PlatformMgr().AddEventHandler(ThreadProvisioningHandler, 0); #endif @@ -500,7 +500,7 @@ void AppTask::BleHandler(AppEvent * aEvent) } } -#ifdef CONFIG_CHIP_NFC_COMMISSIONING +#if CONFIG_CHIP_NFC_COMMISSIONING void AppTask::ThreadProvisioningHandler(const ChipDeviceEvent * event, intptr_t) { if (event->Type == DeviceEventType::kCHIPoBLEAdvertisingChange && event->CHIPoBLEAdvertisingChange.Result == kActivity_Stopped) diff --git a/examples/lock-app/k32w/BUILD.gn b/examples/lock-app/k32w/BUILD.gn index b62ad861af7701..3c1846bb87e89f 100644 --- a/examples/lock-app/k32w/BUILD.gn +++ b/examples/lock-app/k32w/BUILD.gn @@ -75,8 +75,8 @@ k32w_executable("lock_app") { "${chip_root}/third_party/mbedtls:mbedtls", "${chip_root}/third_party/simw-top-mini:se05x", "${k32w_platform_dir}/app/support:freertos_mbedtls_utils", - "${openthread_root}:libopenthread-cli-ftd", - "${openthread_root}:libopenthread-ftd", + "${openthread_root}:libopenthread-cli-mtd", + "${openthread_root}:libopenthread-mtd", ] cflags = [ "-Wconversion" ] diff --git a/examples/lock-app/k32w/include/CHIPProjectConfig.h b/examples/lock-app/k32w/include/CHIPProjectConfig.h index f2146ccaddfb72..83ed41b96d1db6 100644 --- a/examples/lock-app/k32w/include/CHIPProjectConfig.h +++ b/examples/lock-app/k32w/include/CHIPProjectConfig.h @@ -176,10 +176,31 @@ */ #define CHIP_DEVICE_CONFIG_BLE_ADVERTISING_TIMEOUT (15 * 60 * 1000) +/** + * CONFIG_CHIP_NFC_COMMISSIONING, CHIP_DEVICE_CONFIG_ENABLE_NFC + * + * Set these defines to 1 if NFC Commissioning is needed + */ #define CONFIG_CHIP_NFC_COMMISSIONING 1 - #define CHIP_DEVICE_CONFIG_ENABLE_NFC 1 +/** + * CHIP_DEVICE_CONFIG_THREAD_FTD + * + * E-Lock Demo Application is a Thread SED (Sleepy End Device) + */ +#define CHIP_DEVICE_CONFIG_THREAD_FTD 0 + +/** + * @def CHIP_CONFIG_MAX_DEVICE_ADMINS + * + * @brief + * Maximum number of administrators that can provision the device. Each admin + * can provision the device with their unique operational credentials and manage + * their access control lists. + */ +#define CHIP_CONFIG_MAX_DEVICE_ADMINS 4 // 3 fabrics + 1 for rotation slack + /** * CHIP_CONFIG_EVENT_LOGGING_DEFAULT_IMPORTANCE * diff --git a/examples/platform/k32w/app/project_include/OpenThreadConfig.h b/examples/platform/k32w/app/project_include/OpenThreadConfig.h index 58dd5de1391497..145e74e0984c7c 100644 --- a/examples/platform/k32w/app/project_include/OpenThreadConfig.h +++ b/examples/platform/k32w/app/project_include/OpenThreadConfig.h @@ -52,6 +52,15 @@ #define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 0 #define OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE 0 #define OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE 0 +#define OPENTHREAD_CONFIG_TCP_ENABLE 0 + +#if CHIP_DEVICE_CONFIG_THREAD_FTD +#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 44 +#else +#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 22 +#endif + +//#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG // Use the NXP-supplied default platform configuration for remainder // of OpenThread config options. diff --git a/src/lwip/k32w/lwipopts.h b/src/lwip/k32w/lwipopts.h index 50bce3c31e956d..d2f0203b1df40b 100644 --- a/src/lwip/k32w/lwipopts.h +++ b/src/lwip/k32w/lwipopts.h @@ -55,9 +55,19 @@ #define LWIP_SOCKET 0 -// TODO: seems like this is unnecessary on Thread-only platforms +#if INET_CONFIG_ENABLE_RAW_ENDPOINT #define LWIP_RAW 1 #define MEMP_NUM_RAW_PCB (5) +#else +#define LWIP_RAW 0 +#define MEMP_NUM_RAW_PCB 0 +#endif // INET_CONFIG_ENABLE_RAW_ENDPOINT +#if INET_CONFIG_ENABLE_TCP_ENDPOINT +#define LWIP_TCP 1 +#else +#define LWIP_TCP 0 +#define MEMP_NUM_TCP_PCB 0 +#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT // TODO: verify count #define MEMP_NUM_UDP_PCB (7) @@ -126,7 +136,7 @@ // TODO: make LWIP_DEBUG conditional on build type -#define LWIP_DEBUG 1 +#define LWIP_DEBUG 0 #define MEMP_OVERFLOW_CHECK (0) #define MEMP_SANITY_CHECK (0) #define MEM_DEBUG (LWIP_DBG_OFF) diff --git a/src/platform/K32W/BUILD.gn b/src/platform/K32W/BUILD.gn index acc122ec6af23e..ee3e724190217d 100644 --- a/src/platform/K32W/BUILD.gn +++ b/src/platform/K32W/BUILD.gn @@ -53,8 +53,6 @@ static_library("K32W") { public_deps = [ "${chip_root}/src/platform:platform_base" ] if (chip_enable_openthread) { - public_deps += [ "${openthread_root}:libopenthread-ftd" ] - sources += [ "../OpenThread/OpenThreadUtils.cpp", "ThreadStackManagerImpl.cpp", diff --git a/src/platform/K32W/K32WConfig.cpp b/src/platform/K32W/K32WConfig.cpp index 5917dc9c063da2..d1d13f5c7533c8 100644 --- a/src/platform/K32W/K32WConfig.cpp +++ b/src/platform/K32W/K32WConfig.cpp @@ -381,16 +381,15 @@ CHIP_ERROR K32WConfig::FactoryResetConfigInternal(Key firstKey, Key lastKey) CHIP_ERROR err; // Iterate over all the CHIP Config PDM ID records and delete each one - err = ForEachRecord(kMinConfigKey_ChipConfig, kMaxConfigKey_ChipConfig, false, - [](const Key & pdmKey, const size_t & length) -> CHIP_ERROR { - CHIP_ERROR err2; + err = ForEachRecord(firstKey, lastKey, false, [](const Key & pdmKey, const size_t & length) -> CHIP_ERROR { + CHIP_ERROR err2; - err2 = ClearConfigValue(pdmKey); - SuccessOrExit(err2); + err2 = ClearConfigValue(pdmKey); + SuccessOrExit(err2); - exit: - return err2; - }); + exit: + return err2; + }); // Return success at end of iterations. if (err == CHIP_END_OF_INPUT) diff --git a/src/platform/K32W/ThreadStackManagerImpl.cpp b/src/platform/K32W/ThreadStackManagerImpl.cpp index d61871e76c225e..3c11ed202c29f7 100644 --- a/src/platform/K32W/ThreadStackManagerImpl.cpp +++ b/src/platform/K32W/ThreadStackManagerImpl.cpp @@ -81,18 +81,6 @@ extern "C" void otTaskletsSignalPending(otInstance * p_instance) ThreadStackMgrImpl().SignalThreadActivityPending(); } -#if (!defined(cPWR_UsePowerDownMode) || (cPWR_UsePowerDownMode == 0)) -/** - * Glue function called directly by the OpenThread stack when system event processing work - * is pending. - */ -extern "C" void otSysEventSignalPending(void) -{ - BaseType_t yieldRequired = ThreadStackMgrImpl().SignalThreadActivityPendingFromISR(); - portYIELD_FROM_ISR(yieldRequired); -} -#endif - extern "C" void * pvPortCallocRtos(size_t num, size_t size) { size_t totalAllocSize = (size_t)(num * size); diff --git a/src/platform/K32W/args.gni b/src/platform/K32W/args.gni index 32c9b4fdb92082..758135675b1e0e 100644 --- a/src/platform/K32W/args.gni +++ b/src/platform/K32W/args.gni @@ -23,6 +23,9 @@ lwip_platform = "k32w" chip_inet_config_enable_ipv4 = false chip_inet_config_enable_dns_resolver = false +chip_inet_config_enable_tcp_endpoint = false +chip_inet_config_enable_raw_endpoint = false + chip_build_tests = false chip_mdns = "platform"