Skip to content

Commit

Permalink
[Telink] flash usage optimization (#24078)
Browse files Browse the repository at this point in the history
* [Telink] Updated configuration to optimise flash usage

* [Telink] Added CONFIG_OPENTHREAD_MANUAL_START setting

* [Telink] Set default log level 3 & optimized log messages

* [Telink] Added CONFIG_SERIAL field to enable/disable logging

* [Telink] Fix typo

Co-authored-by: Serhii Salamakha <serhii.salamakha@gmail.com>
  • Loading branch information
2 people authored and pull[bot] committed Jan 10, 2023
1 parent 70828d3 commit 1267203
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 179 deletions.
22 changes: 7 additions & 15 deletions config/telink/app/zephyr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@
CONFIG_CHIP=y
CONFIG_STD_CPP14=y

# Logging
# Logging (set CONFIG_SERIAL to 'y' to enable logging and 'n' to disable logging)
CONFIG_SERIAL=y
CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=y
CONFIG_PRINTK=y
CONFIG_ASSERT=y
CONFIG_CBPRINTF_LIBC_SUBSTS=y

# Setting the INFO log level
CONFIG_LOG_DEFAULT_LEVEL=2
# Setting the INFO log level (uncomment INFO log level configs and comment DEBUG log level configs)
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_MATTER_LOG_LEVEL_INF=y
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_INF=y
CONFIG_IEEE802154_DRIVER_LOG_LEVEL_INF=y
CONFIG_NVS_LOG_LEVEL_INF=y
CONFIG_OPENTHREAD_LOG_LEVEL_INFO=y
CONFIG_OPENTHREAD_L2_LOG_LEVEL_INF=y

# Setting the DEBUG log level (Uncomment for set the log level)
# Setting the DEBUG log level (uncomment DEBUG log level configs)
# CONFIG_LOG_DEFAULT_LEVEL=4
# CONFIG_MATTER_LOG_LEVEL_DBG=y
# CONFIG_MCUBOOT_UTIL_LOG_LEVEL_DBG=y
Expand All @@ -60,6 +61,7 @@ CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
# Application stack size
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_INIT_STACKS=y
CONFIG_IDLE_STACK_SIZE=512

# Disable certain parts of Zephyr IPv6 stack
CONFIG_NET_IPV6_NBR_CACHE=n
Expand Down Expand Up @@ -96,18 +98,8 @@ CONFIG_NET_CONFIG_PEER_IPV6_ADDR="fdde:ad00:beef::2"

# OpenThread configs
CONFIG_OPENTHREAD_SLAAC=y
CONFIG_OPENTHREAD_DHCP6_CLIENT=y
CONFIG_OPENTHREAD_SNTP_CLIENT=y
CONFIG_OPENTHREAD_DNS_CLIENT=y
CONFIG_OPENTHREAD_MTD_NETDIAG=y
CONFIG_OPENTHREAD_ENABLE_SERVICE=y
CONFIG_OPENTHREAD_RADIO_WORKQUEUE_STACK_SIZE=608
CONFIG_OPENTHREAD_MANUAL_START=y
CONFIG_OPENTHREAD_THREAD_STACK_SIZE=6144

# Enable Thread 1.2 features
CONFIG_OPENTHREAD_THREAD_VERSION_1_2=y
CONFIG_OPENTHREAD_DUA=y
CONFIG_OPENTHREAD_MLR=y

# mbedTLS tweaks
CONFIG_MBEDTLS_TEST=y
Expand Down
28 changes: 13 additions & 15 deletions examples/all-clusters-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ CHIP_ERROR AppTask::Init()
{
CHIP_ERROR ret;

LOG_INF("Current Software Version: %u, %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION,
CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);
LOG_INF("SW Version: %u, %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION, CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);

// Initialize status LED
LEDWidget::InitGpio(SYSTEM_STATE_LED_PORT);
Expand Down Expand Up @@ -151,7 +150,7 @@ CHIP_ERROR AppTask::Init()
ret = InitBindingHandlers();
if (ret != CHIP_NO_ERROR)
{
LOG_ERR("InitBindingHandlers() failed");
LOG_ERR("InitBindingHandlers fail");
return ret;
}

Expand All @@ -165,7 +164,7 @@ CHIP_ERROR AppTask::Init()
ret = ConnectivityMgr().SetBLEDeviceName("TelinkApp");
if (ret != CHIP_NO_ERROR)
{
LOG_ERR("Fail to set BLE device name");
LOG_ERR("SetBLEDeviceName fail");
return ret;
}

Expand All @@ -178,7 +177,7 @@ CHIP_ERROR AppTask::StartApp()

if (err != CHIP_NO_ERROR)
{
LOG_ERR("AppTask.Init() failed");
LOG_ERR("AppTask Init fail");
return err;
}

Expand Down Expand Up @@ -210,7 +209,7 @@ void AppTask::FactoryResetButtonEventHandler(void)

void AppTask::FactoryResetHandler(AppEvent * aEvent)
{
LOG_INF("Factory Reset triggered.");
LOG_INF("FactoryResetHandler");
chip::Server::GetInstance().ScheduleFactoryReset();
}

Expand All @@ -226,18 +225,17 @@ void AppTask::StartThreadButtonEventHandler(void)

void AppTask::StartThreadHandler(AppEvent * aEvent)
{

LOG_INF("StartThreadHandler");
if (!chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned())
{
// Switch context from BLE to Thread
BLEManagerImpl sInstance;
sInstance.SwitchToIeee802154();
StartDefaultThreadNetwork();
LOG_INF("Device is not commissioned to a Thread network. Starting with the default configuration.");
}
else
{
LOG_INF("Device is commissioned to a Thread network.");
LOG_INF("Device already commissioned");
}
}

Expand All @@ -253,24 +251,24 @@ void AppTask::StartBleAdvButtonEventHandler(void)

void AppTask::StartBleAdvHandler(AppEvent * aEvent)
{
LOG_INF("BLE advertising start button pressed");
LOG_INF("StartBleAdvHandler");

// Don't allow on starting Matter service BLE advertising after Thread provisioning.
if (ConnectivityMgr().IsThreadProvisioned())
{
LOG_INF("Matter service BLE advertising not started - device is commissioned to a Thread network.");
LOG_INF("Device already commissioned");
return;
}

if (ConnectivityMgr().IsBLEAdvertisingEnabled())
{
LOG_INF("BLE advertising is already enabled");
LOG_INF("BLE adv already enabled");
return;
}

if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != CHIP_NO_ERROR)
{
LOG_ERR("OpenBasicCommissioningWindow() failed");
LOG_ERR("OpenBasicCommissioningWindow fail");
}
}

Expand Down Expand Up @@ -326,7 +324,7 @@ void AppTask::PostEvent(AppEvent * aEvent)
return;
if (k_msgq_put(&sAppEventQueue, aEvent, K_NO_WAIT) != 0)
{
LOG_INF("Failed to post event to app task event queue");
LOG_INF("PostEvent fail");
}
}

Expand All @@ -340,7 +338,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
}
else
{
LOG_INF("Event received with no handler. Dropping event.");
LOG_INF("Dropping event without handler");
}
}

Expand Down
15 changes: 6 additions & 9 deletions examples/all-clusters-app/telink/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,28 @@ int main(void)
err = chip::Platform::MemoryInit();
if (err != CHIP_NO_ERROR)
{
LOG_ERR("Platform::MemoryInit() failed");
LOG_ERR("MemoryInit fail");
goto exit;
}

LOG_INF("Init CHIP stack");
err = PlatformMgr().InitChipStack();
if (err != CHIP_NO_ERROR)
{
LOG_ERR("PlatformMgr().InitChipStack() failed");
LOG_ERR("InitChipStack fail");
goto exit;
}

LOG_INF("Starting CHIP task");
err = PlatformMgr().StartEventLoopTask();
if (err != CHIP_NO_ERROR)
{
LOG_ERR("PlatformMgr().StartEventLoopTask() failed");
LOG_ERR("StartEventLoopTask fail");
goto exit;
}

LOG_INF("Init Thread stack");
err = ThreadStackMgr().InitThreadStack();
if (err != CHIP_NO_ERROR)
{
LOG_ERR("ThreadStackMgr().InitThreadStack() failed");
LOG_ERR("InitThreadStack fail");
goto exit;
}

Expand All @@ -71,13 +68,13 @@ int main(void)
#endif
if (err != CHIP_NO_ERROR)
{
LOG_ERR("ConnectivityMgr().SetThreadDeviceType() failed");
LOG_ERR("SetThreadDeviceType fail");
goto exit;
}

err = GetAppTask().StartApp();

exit:
LOG_ERR("Exited with code %" CHIP_ERROR_FORMAT, err.Format());
LOG_ERR("Exit err %" CHIP_ERROR_FORMAT, err.Format());
return (err == CHIP_NO_ERROR) ? EXIT_SUCCESS : EXIT_FAILURE;
}
23 changes: 11 additions & 12 deletions examples/all-clusters-minimal-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ CHIP_ERROR AppTask::Init()
{
CHIP_ERROR ret;

LOG_INF("Current Software Version: %u, %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION,
CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);
LOG_INF("SW Version: %u, %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION, CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);

// Initialize status LED
LEDWidget::InitGpio(SYSTEM_STATE_LED_PORT);
Expand Down Expand Up @@ -111,7 +110,7 @@ CHIP_ERROR AppTask::Init()
ret = InitBindingHandlers();
if (ret != CHIP_NO_ERROR)
{
LOG_ERR("InitBindingHandlers() failed");
LOG_ERR("InitBindingHandlers fail");
return ret;
}

Expand All @@ -125,7 +124,7 @@ CHIP_ERROR AppTask::Init()
ret = ConnectivityMgr().SetBLEDeviceName("TelinkMinApp");
if (ret != CHIP_NO_ERROR)
{
LOG_ERR("Fail to set BLE device name");
LOG_ERR("SetBLEDeviceName fail");
return ret;
}

Expand All @@ -138,7 +137,7 @@ CHIP_ERROR AppTask::StartApp()

if (err != CHIP_NO_ERROR)
{
LOG_ERR("AppTask.Init() failed");
LOG_ERR("AppTask Init fail");
return err;
}

Expand Down Expand Up @@ -170,7 +169,7 @@ void AppTask::FactoryResetButtonEventHandler(void)

void AppTask::FactoryResetHandler(AppEvent * aEvent)
{
LOG_INF("Factory Reset triggered.");
LOG_INF("FactoryResetHandler");
chip::Server::GetInstance().ScheduleFactoryReset();
}

Expand All @@ -186,24 +185,24 @@ void AppTask::StartBleAdvButtonEventHandler(void)

void AppTask::StartBleAdvHandler(AppEvent * aEvent)
{
LOG_INF("BLE advertising start button pressed");
LOG_INF("StartBleAdvHandler");

// Don't allow on starting Matter service BLE advertising after Thread provisioning.
if (ConnectivityMgr().IsThreadProvisioned())
{
LOG_INF("Matter service BLE advertising not started - device is commissioned to a Thread network.");
LOG_INF("Device already commissioned");
return;
}

if (ConnectivityMgr().IsBLEAdvertisingEnabled())
{
LOG_INF("BLE advertising is already enabled");
LOG_INF("BLE adv already enabled");
return;
}

if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != CHIP_NO_ERROR)
{
LOG_ERR("OpenBasicCommissioningWindow() failed");
LOG_ERR("OpenBasicCommissioningWindow fail");
}
}

Expand Down Expand Up @@ -259,7 +258,7 @@ void AppTask::PostEvent(AppEvent * aEvent)
return;
if (k_msgq_put(&sAppEventQueue, aEvent, K_NO_WAIT) != 0)
{
LOG_INF("Failed to post event to app task event queue");
LOG_INF("PostEvent fail");
}
}

Expand All @@ -273,7 +272,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
}
else
{
LOG_INF("Event received with no handler. Dropping event.");
LOG_INF("Dropping event without handler");
}
}

Expand Down
15 changes: 6 additions & 9 deletions examples/all-clusters-minimal-app/telink/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,28 @@ int main(void)
err = chip::Platform::MemoryInit();
if (err != CHIP_NO_ERROR)
{
LOG_ERR("Platform::MemoryInit() failed");
LOG_ERR("MemoryInit fail");
goto exit;
}

LOG_INF("Init CHIP stack");
err = PlatformMgr().InitChipStack();
if (err != CHIP_NO_ERROR)
{
LOG_ERR("PlatformMgr().InitChipStack() failed");
LOG_ERR("InitChipStack fail");
goto exit;
}

LOG_INF("Starting CHIP task");
err = PlatformMgr().StartEventLoopTask();
if (err != CHIP_NO_ERROR)
{
LOG_ERR("PlatformMgr().StartEventLoopTask() failed");
LOG_ERR("StartEventLoopTask fail");
goto exit;
}

LOG_INF("Init Thread stack");
err = ThreadStackMgr().InitThreadStack();
if (err != CHIP_NO_ERROR)
{
LOG_ERR("ThreadStackMgr().InitThreadStack() failed");
LOG_ERR("InitThreadStack fail");
goto exit;
}

Expand All @@ -71,13 +68,13 @@ int main(void)
#endif
if (err != CHIP_NO_ERROR)
{
LOG_ERR("ConnectivityMgr().SetThreadDeviceType() failed");
LOG_ERR("SetThreadDeviceType fail");
goto exit;
}

err = GetAppTask().StartApp();

exit:
LOG_ERR("Exited with code %" CHIP_ERROR_FORMAT, err.Format());
LOG_ERR("Exit err %" CHIP_ERROR_FORMAT, err.Format());
return (err == CHIP_NO_ERROR) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Loading

0 comments on commit 1267203

Please sign in to comment.