Skip to content

Commit

Permalink
[TI] implement CC13X2 CC26X2 OTA feature with ext flash (#14441)
Browse files Browse the repository at this point in the history
* implement CC13X2 CC26X2 OTA feature with ext flash

 * add OTA clusters to doorlock example
 * Implement OTA platform code for cc13x2x7_26x2x7
 * update cc13x2x7_26x2x7 doorlock example to initialize the OTA driver
 * update cc13x2x7_26x2x7 applications to an OTA enabled linkerscript
 * create merge tool for the OTA image and the BIM pre-built hexfile

* fixup CMake builds

* update setBlock and remove old comment

* update zap generated files

* fix ext flash size, default to board sector size

* Update lock diag clusters

* regen zap files
  • Loading branch information
srickardti authored Feb 8, 2022
1 parent 52d0b42 commit b080024
Show file tree
Hide file tree
Showing 28 changed files with 1,849 additions and 99 deletions.
12 changes: 0 additions & 12 deletions examples/lock-app/cc13x2x7_26x2x7/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ ti_sysconfig("sysconfig") {
sources = [ "${project_dir}/chip.syscfg" ]

outputs = [
"ti_devices_config.c",
"ti_radio_config.c",
"ti_radio_config.h",
"ti_drivers_config.c",
Expand Down Expand Up @@ -111,17 +110,6 @@ ti_simplelink_executable("lock_app") {
"-Wconversion",
]

ldscript = "${ti_simplelink_sdk_root}/source/ti/dmm/apps/common/freertos/cc13x2x7_cc26x2x7.lds"

inputs = [ ldscript ]

ldflags = [
"-L${ti_simplelink_sdk_root}/source",
rebase_path("${target_gen_dir}/sysconfig/ti_utils_build_linker.cmd.genlibs",
root_build_dir),
"-T" + rebase_path(ldscript, root_build_dir),
]

output_dir = root_out_dir
}

Expand Down
4 changes: 3 additions & 1 deletion examples/lock-app/cc13x2x7_26x2x7/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ ti_simplelink_board = "LP_CC2652R7"

# Size Optimizations
# use -Os instead of -Og, LWIP release build
#is_debug = false
is_debug = false

chip_enable_ota_requestor = true

# Disable CHIP Logging
#chip_progress_logging = false
Expand Down
14 changes: 8 additions & 6 deletions examples/lock-app/cc13x2x7_26x2x7/chip.syscfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var Button1 = Button.addInstance();
var Button2 = Button.addInstance();
var ECJPAKE = ECJPAKE.addInstance();
var NVS1 = NVS.addInstance();
var NVS2 = NVS.addInstance();
var SHA21 = SHA2.addInstance();
var LED1 = LED.addInstance();
var LED2 = LED.addInstance();
Expand Down Expand Up @@ -84,23 +85,24 @@ Button2.gpioPin.interruptTrigger = "Falling Edge";

/* ======== CCFG ======== */
var CCFG = scripting.addModule("/ti/devices/CCFG");
const deviceName = system.getScript("/ti/ti154stack/ti154stack_common.js").getLaunchPadFromDevice();
const ccfgSettings = system.getScript("/ti/common/lprf_ccfg_settings.js").ccfgSettings;
for(var setting in ccfgSettings)
{
CCFG[setting] = ccfgSettings[setting];
}

// Update LF Clock Source for CC2652RB devices
if(deviceName.includes("RB"))
{
CCFG.srcClkLF = "Derived from HF XOSC";
}
// Disable CCFG generation, this is added by the BIM project
CCFG.enableCodeGeneration = false;

/* NVS */
NVS1.$name = "CONFIG_NVSINTERNAL";
NVS1.internalFlash.regionBase = 0xAA000;
NVS1.internalFlash.regionSize = 0x4000;

NVS2.$name = "CONFIG_NVSEXTERNAL";
NVS2.nvsType = "External"; // NVS Region Type
NVS2.$hardware = system.deviceData.board.components.MX25R8035F;

/* RF */
/* if an antenna component exists, assign it to the rf instance */
if (system.deviceData.board && system.deviceData.board.components.RF) {
Expand Down
34 changes: 29 additions & 5 deletions examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

#include <platform/CHIPDeviceLayer.h>

#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/OTARequestor.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/CHIPPlatformMemory.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/GenericOTARequestorDriver.h>
#include <platform/cc13x2_26x2/OTAImageProcessorImpl.h>

#include <app/server/OnboardingCodesUtil.h>

Expand All @@ -43,6 +48,7 @@
#define APP_TASK_PRIORITY 4
#define APP_EVENT_QUEUE_SIZE 10

using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceLayer;

Expand All @@ -56,6 +62,22 @@ static Button_Handle sAppRightHandle;

AppTask AppTask::sAppTask;

static OTARequestor sRequestorCore;
static GenericOTARequestorDriver sRequestorUser;
static BDXDownloader sDownloader;
static OTAImageProcessorImpl sImageProcessor;

void InitializeOTARequestor(void)
{
// Initialize and interconnect the Requestor and Image Processor objects
SetRequestorInstance(&sRequestorCore);

sRequestorCore.Init(&Server::GetInstance(), &sRequestorUser, &sDownloader);
sImageProcessor.SetOTADownloader(&sDownloader);
sDownloader.SetImageProcessorDelegate(&sImageProcessor);
sRequestorUser.Init(&sRequestorCore, &sImageProcessor);
}

int AppTask::StartAppTask()
{
int ret = 0;
Expand Down Expand Up @@ -87,7 +109,7 @@ int AppTask::Init()
cc13x2_26x2LogInit();

// Init Chip memory management before the stack
chip::Platform::MemoryInit();
Platform::MemoryInit();

CHIP_ERROR ret = PlatformMgr().InitChipStack();
if (ret != CHIP_NO_ERROR)
Expand Down Expand Up @@ -131,7 +153,7 @@ int AppTask::Init()

// Init ZCL Data Model and start server
PLAT_LOG("Initialize Server");
chip::Server::GetInstance().Init();
Server::GetInstance().Init();

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());
Expand Down Expand Up @@ -172,8 +194,10 @@ int AppTask::Init()

ConfigurationMgr().LogDeviceConfig();

InitializeOTARequestor();

// QR code will be used with CHIP Tool
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
PrintOnboardingCodes(RendezvousInformationFlags(RendezvousInformationFlag::kBLE));

return 0;
}
Expand Down Expand Up @@ -322,7 +346,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
// Enable BLE advertisements
if (!ConnectivityMgr().IsBLEAdvertisingEnabled())
{
if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() == CHIP_NO_ERROR)
if (Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() == CHIP_NO_ERROR)
{
PLAT_LOG("Enabled BLE Advertisement");
}
Expand Down
3 changes: 3 additions & 0 deletions examples/lock-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ idf_component_register(INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/network-commissioning-old"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/on-off-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/general-commissioning-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/diagnostic-logs-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ethernet-network-diagnostics-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/thread-network-diagnostics-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/wifi-network-diagnostics-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/software-diagnostics-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/switch-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/general-diagnostics-server"
Expand Down Expand Up @@ -154,6 +156,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/network-commissioning-old"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/on-off-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/general-commissioning-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-configuration-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/power-source-server"
Expand Down
Empty file modified examples/lock-app/lock-common/BUILD.gn
100644 → 100755
Empty file.
144 changes: 144 additions & 0 deletions examples/lock-app/lock-common/lock-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ server cluster EthernetNetworkDiagnostics = 55 {
readonly attribute int64u timeSinceReset = 8;
readonly global attribute bitmap32 featureMap = 65532;
readonly global attribute int16u clusterRevision = 65533;

command ResetCounts(): DefaultSuccess = 0;
}

server cluster FixedLabel = 64 {
Expand Down Expand Up @@ -494,6 +496,140 @@ server cluster NetworkCommissioning = 49 {
command ScanNetworks(ScanNetworksRequest): ScanNetworksResponse = 0;
}

client cluster OtaSoftwareUpdateProvider = 41 {
enum OTAApplyUpdateAction : ENUM8 {
kProceed = 0;
kAwaitNextAction = 1;
kDiscontinue = 2;
}

enum OTADownloadProtocol : ENUM8 {
kBDXSynchronous = 0;
kBDXAsynchronous = 1;
kHttps = 2;
kVendorSpecific = 3;
}

enum OTAQueryStatus : ENUM8 {
kUpdateAvailable = 0;
kBusy = 1;
kNotAvailable = 2;
kDownloadProtocolNotSupported = 3;
}

readonly global attribute int16u clusterRevision = 65533;

request struct ApplyUpdateRequestRequest {
OCTET_STRING updateToken = 0;
INT32U newVersion = 1;
}

request struct NotifyUpdateAppliedRequest {
OCTET_STRING updateToken = 0;
INT32U softwareVersion = 1;
}

request struct QueryImageRequest {
vendor_id vendorId = 0;
INT16U productId = 1;
INT32U softwareVersion = 2;
OTADownloadProtocol protocolsSupported[] = 3;
optional INT16U hardwareVersion = 4;
optional CHAR_STRING location = 5;
optional BOOLEAN requestorCanConsent = 6;
optional OCTET_STRING metadataForProvider = 7;
}

response struct ApplyUpdateResponse {
OTAApplyUpdateAction action = 0;
INT32U delayedActionTime = 1;
}

response struct QueryImageResponse {
OTAQueryStatus status = 0;
optional INT32U delayedActionTime = 1;
optional CHAR_STRING imageURI = 2;
optional INT32U softwareVersion = 3;
optional CHAR_STRING softwareVersionString = 4;
optional OCTET_STRING updateToken = 5;
optional BOOLEAN userConsentNeeded = 6;
optional OCTET_STRING metadataForRequestor = 7;
}

command ApplyUpdateRequest(ApplyUpdateRequestRequest): ApplyUpdateResponse = 2;
command NotifyUpdateApplied(NotifyUpdateAppliedRequest): DefaultSuccess = 4;
command QueryImage(QueryImageRequest): QueryImageResponse = 0;
}

server cluster OtaSoftwareUpdateRequestor = 42 {
enum OTAAnnouncementReason : ENUM8 {
kSimpleAnnouncement = 0;
kUpdateAvailable = 1;
kUrgentUpdateAvailable = 2;
}

enum OTAChangeReasonEnum : ENUM8 {
kUnknown = 0;
kSuccess = 1;
kFailure = 2;
kTimeOut = 3;
kDelayByProvider = 4;
}

enum OTAUpdateStateEnum : ENUM8 {
kUnknown = 0;
kIdle = 1;
kQuerying = 2;
kDelayedOnQuery = 3;
kDownloading = 4;
kApplying = 5;
kDelayedOnApply = 6;
kRollingBack = 7;
kDelayedOnUserConsent = 8;
}

struct ProviderLocation {
fabric_idx fabricIndex = 0;
node_id providerNodeID = 1;
endpoint_no endpoint = 2;
}

info event StateTransition = 0 {
nullable OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum newState = 1;
OTAChangeReasonEnum reason = 2;
nullable INT32U targetSoftwareVersion = 3;
}

critical event VersionApplied = 1 {
INT32U softwareVersion = 0;
INT16U productID = 1;
}

info event DownloadError = 2 {
INT32U softwareVersion = 0;
INT64U bytesDownloaded = 1;
nullable INT8U progressPercent = 2;
nullable INT64S platformCode = 3;
}

attribute ProviderLocation defaultOtaProviders[] = 0;
readonly attribute boolean updatePossible = 1;
readonly attribute OTAUpdateStateEnum updateState = 2;
readonly attribute nullable int8u updateStateProgress = 3;
readonly global attribute int16u clusterRevision = 65533;

request struct AnnounceOtaProviderRequest {
node_id providerNodeId = 0;
vendor_id vendorId = 1;
OTAAnnouncementReason announcementReason = 2;
optional OCTET_STRING metadataForNode = 3;
endpoint_no endpoint = 4;
}

command AnnounceOtaProvider(AnnounceOtaProviderRequest): DefaultSuccess = 0;
}

server cluster OnOff = 6 {
enum OnOffDelayedAllOffEffectVariant : enum8 {
kFadeToOffIn0p8Seconds = 0;
Expand Down Expand Up @@ -738,6 +874,8 @@ server cluster SoftwareDiagnostics = 52 {
readonly attribute int64u currentHeapHighWatermark = 3;
readonly global attribute bitmap32 featureMap = 65532;
readonly global attribute int16u clusterRevision = 65533;

command ResetWatermarks(): DefaultSuccess = 0;
}

server cluster ThreadNetworkDiagnostics = 53 {
Expand Down Expand Up @@ -889,6 +1027,8 @@ server cluster ThreadNetworkDiagnostics = 53 {
readonly attribute NetworkFault activeNetworkFaultsList[] = 62;
readonly global attribute bitmap32 featureMap = 65532;
readonly global attribute int16u clusterRevision = 65533;

command ResetCounts(): DefaultSuccess = 0;
}

server cluster TimeFormatLocalization = 44 {
Expand Down Expand Up @@ -982,6 +1122,8 @@ server cluster WiFiNetworkDiagnostics = 54 {
readonly attribute int64u overrunCount = 12;
readonly global attribute bitmap32 featureMap = 65532;
readonly global attribute int16u clusterRevision = 65533;

command ResetCounts(): DefaultSuccess = 0;
}


Expand All @@ -997,6 +1139,8 @@ endpoint 0 {
server cluster GeneralDiagnostics;
server cluster LocalizationConfiguration;
server cluster NetworkCommissioning;
binding cluster OtaSoftwareUpdateProvider;
server cluster OtaSoftwareUpdateRequestor;
server cluster OperationalCredentials;
server cluster PowerSource;
server cluster PowerSourceConfiguration;
Expand Down
Loading

0 comments on commit b080024

Please sign in to comment.