Skip to content

Commit

Permalink
[K32W0] TE9 fixes (#18952)
Browse files Browse the repository at this point in the history
* [K32W0] TE9 fixes

* patch BLE and PDM libraries
* remove LWIP from K32W0
* add locking mechanism in UDPEndpointImplOpenThread
* re-enable detail logging
* enable BLE 2M bitrate
* updated max number of KVS keys
* undefine OPENTHREAD_CONFIG_PLATFORM_CSL_UNCERT as is not needed anymore
* use the correct OT configuration
* increase the number of packet buffers
* add API "bool _IsAdvertising(void)" implementation on our k32w platform
* fix OTA compilation issue
* fix signing script
* fix compilation error (missing idle task function)
* fix lock-app LEDs states

Signed-off-by: Doru Gucea <[email protected]>

* Fixes

* increase the maximum number of KVS keys
* remove unused file.

Signed-off-by: Doru Gucea <[email protected]>

* Fix section name

Signed-off-by: Doru Gucea <[email protected]>

* Fix section matching for buffer pool

Signed-off-by: Doru Gucea <[email protected]>
  • Loading branch information
doru91 authored and pull[bot] committed Jan 19, 2024
1 parent 76fade6 commit f05834b
Show file tree
Hide file tree
Showing 25 changed files with 177 additions and 72 deletions.
31 changes: 24 additions & 7 deletions examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <platform/CHIPDeviceLayer.h>
#include <platform/internal/DeviceNetworkInfo.h>

#include <inet/EndPointStateOpenThread.h>

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
Expand Down Expand Up @@ -184,12 +186,27 @@ CHIP_ERROR AppTask::Init()
return err;
}

void LockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().LockThreadStack();
}

void UnlockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().UnlockThreadStack();
}

void AppTask::InitServer(intptr_t arg)
{
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();

// Init ZCL Data Model and start server
chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams;
nativeParams.lockCb = LockOpenThreadTask;
nativeParams.unlockCb = UnlockOpenThreadTask;
nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl().OTInstance();
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
VerifyOrDie((chip::Server::GetInstance().Init(initParams)) == CHIP_NO_ERROR);
}

Expand Down Expand Up @@ -690,13 +707,6 @@ void AppTask::OTAResumeEventHandler(AppEvent * aEvent)
}
}

extern "C" void vApplicationIdleHook(void)
{
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
OTA_TransactionResume();
#endif
}

void AppTask::PostEvent(const AppEvent * aEvent)
{
if (sAppEventQueue != NULL)
Expand Down Expand Up @@ -753,3 +763,10 @@ void AppTask::UpdateDeviceStateInternal(intptr_t arg)
/* set the device state */
sLightLED.Set(onoffAttrValue);
}

extern "C" void OTAIdleActivities(void)
{
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
OTA_TransactionResume();
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

#define APP_BUTTON_PUSH 1

#define SYSTEM_STATE_LED LED1
#define LIGHT_STATE_LED LED2
#define SYSTEM_STATE_LED LED2
#define LIGHT_STATE_LED LED1

// Time it takes for the light to switch on/off
#define ACTUATOR_MOVEMENT_PERIOS_MS 50
Expand Down
19 changes: 19 additions & 0 deletions examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <platform/CHIPDeviceLayer.h>
#include <platform/internal/DeviceNetworkInfo.h>

#include <inet/EndPointStateOpenThread.h>

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
Expand Down Expand Up @@ -162,12 +164,27 @@ CHIP_ERROR AppTask::Init()
return err;
}

void LockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().LockThreadStack();
}

void UnlockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().UnlockThreadStack();
}

void AppTask::InitServer(intptr_t arg)
{
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();

// Init ZCL Data Model and start server
chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams;
nativeParams.lockCb = LockOpenThreadTask;
nativeParams.unlockCb = UnlockOpenThreadTask;
nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl().OTInstance();
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
VerifyOrDie((chip::Server::GetInstance().Init(initParams)) == CHIP_NO_ERROR);
}

Expand Down Expand Up @@ -739,3 +756,5 @@ void AppTask::UpdateClusterStateInternal(intptr_t arg)
ChipLogError(NotSpecified, "ERR: updating on/off %x", status);
}
}

extern "C" void OTAIdleActivities(void) {}
4 changes: 2 additions & 2 deletions examples/lock-app/nxp/k32w/k32w0/main/include/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

#define APP_BUTTON_PUSH 1

#define LOCK_STATE_LED LED1
#define SYSTEM_STATE_LED LED2
#define LOCK_STATE_LED LED2
#define SYSTEM_STATE_LED LED1

// Time it takes in ms for the simulated actuator to move from one
// state to another.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ SECTIONS

_etext = .;

.heap_controller (COPY):
.heap_packet_buffer (COPY):
{
*(.ll_exchange_mem)
*(.bss._ZN4chip6System12PacketBuffer11sBufferPoolE)
__HeapBase = .;
_heap = .;
KEEP(*(.heap*))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,80 @@
*
*/

#include "openthread-core-k32w061-config.h"

#pragma once

// Disable the Nxp-supplied OpenThread logging facilities
// and use the facilities provided by the Device Layer
// (see src/platform/K32W/Logging.cpp).
#undef OPENTHREAD_CONFIG_LOG_OUTPUT
#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_APP

// When operating in a less than ideal RF environment, having a more forgiving configuration
// of OpenThread makes thread a great deal more reliable.
#define OPENTHREAD_CONFIG_TMF_ADDRESS_QUERY_MAX_RETRY_DELAY 120 // default is 28800
#undef OPENTHREAD_CONFIG_TMF_ADDRESS_QUERY_MAX_RETRY_DELAY
#define OPENTHREAD_CONFIG_TMF_ADDRESS_QUERY_MAX_RETRY_DELAY 120 // default is 28800

#undef OPENTHREAD_CONFIG_MAC__DEFAULT_MAX_FRAME_RETRIES_DIRECT
#define OPENTHREAD_CONFIG_MAC__DEFAULT_MAX_FRAME_RETRIES_DIRECT 15 // default is 3

#undef OPENTHREAD_CONFIG_MAC_DEFAULT_MAX_FRAME_RETRIES_INDIRECT
#define OPENTHREAD_CONFIG_MAC_DEFAULT_MAX_FRAME_RETRIES_INDIRECT 1 // default is 0
#define OPENTHREAD_CONFIG_MAC_MAX_TX_ATTEMPTS_INDIRECT_POLLS 16 // default is 4

#undef OPENTHREAD_CONFIG_MAC_MAX_TX_ATTEMPTS_INDIRECT_POLLS
#define OPENTHREAD_CONFIG_MAC_MAX_TX_ATTEMPTS_INDIRECT_POLLS 16 // default is 4

// Enable periodic parent search to speed up finding a better parent.
#define OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE 1 // default is 0
#define OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD -45 // default is -65
#undef OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE
#define OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE 1 // default is 0

#undef OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD
#define OPENTHREAD_CONFIG_PARENT_SEARCH_RSS_THRESHOLD -45 // default is -65

#undef OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH
#define OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH 1 // default is 0

// Use smaller maximum interval to speed up reattaching.
#undef OPENTHREAD_CONFIG_MLE_ATTACH_BACKOFF_MAXIMUM_INTERVAL
#define OPENTHREAD_CONFIG_MLE_ATTACH_BACKOFF_MAXIMUM_INTERVAL (60 * 10 * 1000) // default 1200000 ms

// disable unused features
#undef OPENTHREAD_CONFIG_COAP_API_ENABLE
#define OPENTHREAD_CONFIG_COAP_API_ENABLE 0

#undef OPENTHREAD_CONFIG_JOINER_ENABLE
#define OPENTHREAD_CONFIG_JOINER_ENABLE 0

#undef OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
#define OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 0

#undef OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE
#define OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE 0

#undef OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 0

#undef OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE
#define OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE 0

#undef OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE
#define OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE 0

#undef OPENTHREAD_CONFIG_TCP_ENABLE
#define OPENTHREAD_CONFIG_TCP_ENABLE 0

#undef OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 0

#undef OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE 0

#undef OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS
#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 44

#undef OPENTHREAD_CONFIG_PLATFORM_CSL_UNCERT

//#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG

// Use the NXP-supplied default platform configuration for remainder
Expand All @@ -64,4 +104,3 @@
// NB: This file gets included during the build of OpenThread. Hence
// it cannot use "openthread" in the path to the included file.
//
#include "openthread-core-k32w061-config.h"
6 changes: 4 additions & 2 deletions examples/platform/nxp/k32w/k32w0/app/support/FreeRtosHooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime)

OSA_InterruptEnable();
}
#endif /* (cPWR_UsePowerDownMode) && (configUSE_TICKLESS_IDLE != 0) */

static void BOARD_ActionOnIdle(void)
{
Expand All @@ -228,9 +229,10 @@ static void BOARD_ActionOnIdle(void)
#endif
}

extern void OTAIdleActivities();

void vApplicationIdleHook(void)
{
OTAIdleActivities();
BOARD_ActionOnIdle();
}

#endif /* (cPWR_UsePowerDownMode) && (configUSE_TICKLESS_IDLE != 0) */
3 changes: 3 additions & 0 deletions examples/platform/nxp/k32w/k32w0/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ chip_system_project_config_include = "<CHIPProjectConfig.h>"

chip_system_config_provide_statistics = false
chip_with_nlfaultinjection = true

chip_system_config_use_open_thread_inet_endpoints = true
chip_with_lwip = false
19 changes: 19 additions & 0 deletions examples/shell/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <platform/CHIPDeviceLayer.h>
#include <platform/internal/DeviceNetworkInfo.h>

#include <inet/EndPointStateOpenThread.h>

#include "Keyboard.h"
#include "LED.h"
#include "LEDWidget.h"
Expand Down Expand Up @@ -69,13 +71,28 @@ CHIP_ERROR AppTask::StartAppTask()
return err;
}

void LockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().LockThreadStack();
}

void UnlockOpenThreadTask(void)
{
chip::DeviceLayer::ThreadStackMgr().UnlockThreadStack();
}

CHIP_ERROR AppTask::Init()
{
CHIP_ERROR err = CHIP_NO_ERROR;

// Init ZCL Data Model and start server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams;
nativeParams.lockCb = LockOpenThreadTask;
nativeParams.unlockCb = UnlockOpenThreadTask;
nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl().OTInstance();
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
chip::Server::GetInstance().Init(initParams);

// Initialize device attestation config
Expand Down Expand Up @@ -434,3 +451,5 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
K32W_LOG("Event received with no handler. Dropping event.");
}
}

extern "C" void OTAIdleActivities(void) {}
2 changes: 1 addition & 1 deletion examples/shell/nxp/k32w/k32w0/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern InitFunc __init_array_start;
extern InitFunc __init_array_end;

/* needed for FreeRtos Heap 4 */
uint8_t __attribute__((section(".heap"))) ucHeap[0xF000];
uint8_t __attribute__((section(".heap"))) ucHeap[HEAP_SIZE];

extern "C" unsigned int sleep(unsigned int seconds)
{
Expand Down
13 changes: 11 additions & 2 deletions src/platform/nxp/k32w/k32w0/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ CHIP_ERROR BLEManagerImpl::_Init()
VerifyOrExit(bleAppCreated == pdPASS, err = CHIP_ERROR_INCORRECT_STATE);

/* BLE Radio Init */
XCVR_TemperatureUpdate(BOARD_GetTemperature());
VerifyOrExit(XCVR_Init(BLE_MODE, DR_2MBPS) == gXcvrSuccess_c, err = CHIP_ERROR_INCORRECT_STATE);

/* Create BLE Controller Task */
Expand Down Expand Up @@ -245,6 +244,11 @@ bool BLEManagerImpl::_IsAdvertisingEnabled(void)
return mFlags.Has(Flags::kAdvertisingEnabled);
}

bool BLEManagerImpl::_IsAdvertising(void)
{
return mFlags.Has(Flags::kAdvertising);
}

bool BLEManagerImpl::RemoveConnection(uint8_t connectionHandle)
{
CHIPoBLEConState * bleConnState = GetConnectionState(connectionHandle, true);
Expand Down Expand Up @@ -1010,7 +1014,7 @@ void BLEManagerImpl::bleAppTask(void * p_arg)

if (msg->type == BLE_KW_MSG_ERROR)
{
ChipLogProgress(DeviceLayer, "BLE Fatal Error: %d.\n", msg->data.u8);
ChipLogProgress(DeviceLayer, "BLE Error: %d.\n", msg->data.u8);
}
else if (msg->type == BLE_KW_MSG_CONNECTED)
{
Expand Down Expand Up @@ -1276,6 +1280,11 @@ void BLEManagerImpl::blekw_gap_connection_cb(deviceId_t deviceId, gapConnectionE

if (pConnectionEvent->eventType == gConnEvtConnected_c)
{
ChipLogProgress(DeviceLayer, "BLE K32W: Trying to set the PHY to 2M");

(void) Gap_LeSetPhy(FALSE, deviceId, 0, gConnPhyUpdateReqTxPhySettings_c, gConnPhyUpdateReqRxPhySettings_c,
(uint16_t) gConnPhyUpdateReqPhyOptions_c);

/* Notify App Task that the BLE is connected now */
(void) blekw_msg_add_u8(BLE_KW_MSG_CONNECTED, (uint8_t) deviceId);
#if defined(cPWR_UsePowerDownMode) && (cPWR_UsePowerDownMode)
Expand Down
2 changes: 2 additions & 0 deletions src/platform/nxp/k32w/k32w0/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
#include <platform/ConnectivityManager.h>
#include <platform/internal/BLEManager.h>

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/dns.h>
#include <lwip/ip_addr.h>
#include <lwip/nd6.h>
#include <lwip/netif.h>
#endif

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#include <platform/internal/GenericConnectivityManagerImpl_BLE.ipp>
Expand Down
2 changes: 2 additions & 0 deletions src/platform/nxp/k32w/k32w0/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include <platform/DiagnosticDataProvider.h>
#include <platform/nxp/k32w/k32w0/DiagnosticDataProviderImpl.h>

#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/tcpip.h>
#endif

#include <openthread/platform/entropy.h>

Expand Down
2 changes: 1 addition & 1 deletion src/platform/nxp/k32w/k32w0/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace DeviceLayer {
namespace PersistedStorage {

/* TODO: adjust these values */
constexpr size_t kMaxNumberOfKeys = 30;
constexpr size_t kMaxNumberOfKeys = 125;
constexpr size_t kMaxKeyValueBytes = 255;

KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance;
Expand Down
2 changes: 2 additions & 0 deletions src/platform/nxp/k32w/k32w0/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void ENFORCE_FORMAT(3, 0) LogV(const char * module, uint8_t category, const char
#undef K32W_LOG_MODULE_NAME
#define K32W_LOG_MODULE_NAME lwip

#if CHIP_SYSTEM_CONFIG_USE_LWIP
/**
* LwIP log output function.
*/
Expand All @@ -169,6 +170,7 @@ extern "C" void ENFORCE_FORMAT(1, 2) LwIPLog(const char * msg, ...)
GenericLog(msg, v, module, chip::Logging::kLogCategory_None);
va_end(v);
}
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD

Expand Down
Loading

0 comments on commit f05834b

Please sign in to comment.