Skip to content

Commit

Permalink
[Ameba] Fix commissioning and hardfault issue (#16757)
Browse files Browse the repository at this point in the history
* Update chipinterface to fix hardfault error

* Fix ble-wifi commissioning issue, disable ipv4, reduce max fabric to 5

* Control rotating_id enable/disable from chip.cmake instead of chip_main.cmake

* Restyled by whitespace

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Sep 13, 2023
1 parent 43cc0de commit 1180675
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 45 deletions.
14 changes: 10 additions & 4 deletions config/ameba/chip.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set(chip_c_flags "")
set(chip_cpp_flags "")
set(chip-gn chip-gn)

set(matter_enable_rotating_id 1)

get_filename_component(CHIP_ROOT ${chip_dir} REALPATH)
get_filename_component(CHIP_OUTPUT ${chip_dir_output} REALPATH)
get_filename_component(LIB_ROOT ${prj_root}/GCC-RELEASE/project_hp/asdk/lib/application REALPATH)
Expand Down Expand Up @@ -101,6 +103,7 @@ string(APPEND CHIP_GN_ARGS "ameba_ar = \"arm-none-eabi-ar\"\n")
string(APPEND CHIP_GN_ARGS "ameba_cc = \"arm-none-eabi-gcc\"\n")
string(APPEND CHIP_GN_ARGS "ameba_cxx = \"arm-none-eabi-c++\"\n")
string(APPEND CHIP_GN_ARGS "ameba_cpu = \"ameba\"\n")
string(APPEND CHIP_GN_ARGS "chip_inet_config_enable_ipv4 = false\n")

# Build RPC
if (matter_enable_rpc)
Expand All @@ -118,10 +121,13 @@ if (matter_enable_ota_requestor)
string(APPEND CHIP_GN_ARGS "chip_enable_ota_requestor = true\n")
endif (matter_enable_ota_requestor)

if (CONFIG_ENABLE_ROTATING_DEVICE_ID)
string(APPEND CHIP_GN_ARGS "chip_enable_additional_data_advertising" "true")
string(APPEND CHIP_GN_ARGS "chip_enable_rotating_device_id" "true")
endif()
if (matter_enable_rotating_id)
string(APPEND CHIP_GN_ARGS "chip_enable_additional_data_advertising = true\n")
string(APPEND CHIP_GN_ARGS "chip_enable_rotating_device_id = true\n")
else(matter_enable_rotating_id)
string(APPEND CHIP_GN_ARGS "chip_enable_additional_data_advertising = false\n")
string(APPEND CHIP_GN_ARGS "chip_enable_rotating_device_id = false\n")
endif(matter_enable_rotating_id)

file(GENERATE OUTPUT ${CHIP_OUTPUT}/args.gn CONTENT ${CHIP_GN_ARGS})

Expand Down
3 changes: 1 addition & 2 deletions examples/all-clusters-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,12 @@ endif (matter_enable_rpc)
list(
APPEND chip_main_flags

-DINET_CONFIG_ENABLE_IPV4=1
-DINET_CONFIG_ENABLE_IPV4=0
-DCHIP_PROJECT=1
-DCHIP_DEVICE_LAYER_TARGET=Ameba
-DUSE_ZAP_CONFIG
-DCHIP_HAVE_CONFIG_H
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
-DCONFIG_ENABLE_ROTATING_DEVICE_ID=1
-DMATTER_ALL_CLUSTERS_APP=1
)

Expand Down
25 changes: 16 additions & 9 deletions examples/all-clusters-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/af.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <lib/support/ErrorStr.h>
Expand Down Expand Up @@ -56,14 +57,21 @@ using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;
using namespace ::chip::System;

namespace {
namespace { // Network Commissioning
constexpr EndpointId kNetworkCommissioningEndpointMain = 0;
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::AmebaWiFiDriver::GetInstance()));
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */,
&(NetworkCommissioning::AmebaWiFiDriver::GetInstance()));
} // namespace

void NetWorkCommissioningInstInit()
{
sWiFiNetworkCommissioningInstance.Init();

// We only have network commissioning on endpoint 0.
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);
}

Identify gIdentify0 = {
Expand Down Expand Up @@ -102,14 +110,13 @@ AmebaOTAImageProcessor gImageProcessor;
extern "C" void amebaQueryImageCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaQueryImageCmdHandler");
static_cast<OTARequestor *>(GetRequestorInstance())->TriggerImmediateQuery();
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); });
}

extern "C" void amebaApplyUpdateCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaApplyUpdateCmdHandler");

static_cast<OTARequestor *>(GetRequestorInstance())->ApplyUpdate();
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); });
}

static void InitOTARequestor(void)
Expand All @@ -134,6 +141,10 @@ static void InitOTARequestor(void)

static void InitServer(intptr_t context)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

// Init ZCL Data Model and CHIP App Server
chip::Server::GetInstance().Init();

Expand All @@ -146,10 +157,6 @@ static void InitServer(intptr_t context)
// QR code will be used with CHIP Tool
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
}

#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif
}

extern "C" void ChipTest(void)
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ target_include_directories(
list(
APPEND chip_main_flags

-DINET_CONFIG_ENABLE_IPV4=1
-DINET_CONFIG_ENABLE_IPV4=0
-DCHIP_PROJECT=1
-DCHIP_DEVICE_LAYER_TARGET=Ameba
-DUSE_ZAP_CONFIG
Expand Down
29 changes: 16 additions & 13 deletions examples/lighting-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/util/af.h>
#include <lib/support/ErrorStr.h>
#include <platform/Ameba/AmebaConfig.h>
#include <platform/Ameba/NetworkCommissioningDriver.h>
Expand All @@ -55,14 +56,21 @@ using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;
using namespace ::chip::System;

namespace {
namespace { // Network Commissioning
constexpr EndpointId kNetworkCommissioningEndpointMain = 0;
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::AmebaWiFiDriver::GetInstance()));
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */,
&(NetworkCommissioning::AmebaWiFiDriver::GetInstance()));
} // namespace

void NetWorkCommissioningInstInit()
{
sWiFiNetworkCommissioningInstance.Init();

// We only have network commissioning on endpoint 0.
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);
}

#ifdef CONFIG_PLATFORM_8721D
Expand All @@ -87,14 +95,13 @@ AmebaOTAImageProcessor gImageProcessor;
extern "C" void amebaQueryImageCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaQueryImageCmdHandler");
static_cast<OTARequestor *>(GetRequestorInstance())->TriggerImmediateQuery();
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); });
}

extern "C" void amebaApplyUpdateCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaApplyUpdateCmdHandler");

static_cast<OTARequestor *>(GetRequestorInstance())->ApplyUpdate();
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); });
}

static void InitOTARequestor(void)
Expand Down Expand Up @@ -155,6 +162,10 @@ static Identify gIdentify1 = {

static void InitServer(intptr_t context)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif

// Init ZCL Data Model and CHIP App Server
chip::Server::GetInstance().Init();

Expand All @@ -167,10 +178,6 @@ static void InitServer(intptr_t context)
// QR code will be used with CHIP Tool
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
}

#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif
}

extern "C" void ChipTest(void)
Expand All @@ -195,10 +202,6 @@ extern "C" void ChipTest(void)
chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, 0);

statusLED1.Init(STATUS_LED_GPIO_NUM);

#if CONFIG_ENABLE_OTA_REQUESTOR
InitOTARequestor();
#endif
}

bool lowPowerClusterSleep()
Expand Down
2 changes: 1 addition & 1 deletion examples/ota-requestor-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ target_include_directories(
list(
APPEND chip_main_flags

-DINET_CONFIG_ENABLE_IPV4=1
-DINET_CONFIG_ENABLE_IPV4=0
-DCHIP_PROJECT=1
-DCHIP_DEVICE_LAYER_TARGET=Ameba
-DUSE_ZAP_CONFIG
Expand Down
21 changes: 14 additions & 7 deletions examples/ota-requestor-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/server/Server.h>
#include <app/util/af.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

Expand Down Expand Up @@ -65,14 +66,21 @@ using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;

namespace {
namespace { // Network Commissioning
constexpr EndpointId kNetworkCommissioningEndpointMain = 0;
constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::AmebaWiFiDriver::GetInstance()));
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */,
&(NetworkCommissioning::AmebaWiFiDriver::GetInstance()));
} // namespace

void NetWorkCommissioningInstInit()
{
sWiFiNetworkCommissioningInstance.Init();

// We only have network commissioning on endpoint 0.
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);
}

static DeviceCallbacks EchoCallbacks;
Expand All @@ -86,14 +94,13 @@ AmebaOTAImageProcessor gImageProcessor;
extern "C" void amebaQueryImageCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaQueryImageCmdHandler");
static_cast<OTARequestor *>(GetRequestorInstance())->TriggerImmediateQuery();
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); });
}

extern "C" void amebaApplyUpdateCmdHandler()
{
ChipLogProgress(DeviceLayer, "Calling amebaApplyUpdateCmdHandler");

static_cast<OTARequestor *>(GetRequestorInstance())->ApplyUpdate();
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); });
}

static void InitOTARequestor(void)
Expand All @@ -117,14 +124,14 @@ static void InitOTARequestor(void)

static void InitServer(intptr_t context)
{
InitOTARequestor();

// Init ZCL Data Model and CHIP App Server
chip::Server::GetInstance().Init();

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
NetWorkCommissioningInstInit();

InitOTARequestor();
}

extern "C" void ChipTest(void)
Expand Down
2 changes: 1 addition & 1 deletion examples/pigweed-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ link_directories(
list(
APPEND chip_main_flags

-DINET_CONFIG_ENABLE_IPV4=1
-DINET_CONFIG_ENABLE_IPV4=0
-DCHIP_PROJECT=1
-DCHIP_DEVICE_LAYER_TARGET=Ameba
-DUSE_ZAP_CONFIG
Expand Down
4 changes: 4 additions & 0 deletions src/platform/Ameba/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
#define CHIP_CONFIG_MAX_PEER_NODES 16
#endif // CHIP_CONFIG_MAX_PEER_NODES

#ifndef CHIP_CONFIG_MAX_FABRICS
#define CHIP_CONFIG_MAX_FABRICS 5
#endif // CHIP_CONFIG_MAX_FABRICS

#ifndef CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS
#define CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS 16
#endif // CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS
Expand Down
2 changes: 0 additions & 2 deletions src/platform/Ameba/InetPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@
#ifndef INET_CONFIG_NUM_UDP_ENDPOINTS
#define INET_CONFIG_NUM_UDP_ENDPOINTS 10
#endif // INET_CONFIG_NUM_UDP_ENDPOINTS

#define INET_CONFIG_ENABLE_IPV4 1
6 changes: 1 addition & 5 deletions src/platform/Ameba/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,10 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
if (TRUE == ret)
{
err = CHIP_NO_ERROR;
if (read_bytes_size)
{
*read_bytes_size = value_size;
}
}
else
{
err = CHIP_ERROR_INTERNAL;
err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
}

return err;
Expand Down

0 comments on commit 1180675

Please sign in to comment.