Skip to content

Commit

Permalink
[nrfconnect] Update SDK version to 1.9.0 (#15453)
Browse files Browse the repository at this point in the history
* [nrfconnect] Bump recommended SDK version to 1.9.0

* Adapt the code to nRF Connect SDK 1.9.0

1. Added configs changes related to nrf security upmerge
2. Changed reboot.h include from power to sys.
3. Aligned configuration after switching to Oberon backend
   After switching to using only Oberon backend we don't
   need to have CC3XX backend enabled. Also mbedTLS context
   needed to be aligned.
4. Add missing 802.15.4 driver include directories.
   Also, fix zephyr_include_directories() not working
   correctly with generator expressions - that is,
   prepending a generator expression argument with the
   current build directory as if the argument was a
   relative path.
5. Fix Pigweed build errors

* Align examples with NCS samples

* Bump Docker image version in workflow

* Set the correct default vendor ID

* Restyled by clang-format

* Fix pigweed-app, pump-app and pump-controller-app build

Co-authored-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
3 people authored and pull[bot] committed Jan 19, 2024
1 parent 2cb6af2 commit 431ab82
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/examples-nrfconnect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
if: github.actor != 'restyled-io[bot]'

container:
image: connectedhomeip/chip-build-nrf-platform:0.5.52
image: connectedhomeip/chip-build-nrf-platform:0.5.56
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"

Expand Down
2 changes: 1 addition & 1 deletion config/nrfconnect/.nrfconnect-recommended-revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cfedfdfa08567b2252b511a4d1db15fbeba8152d
v1.9.0
12 changes: 5 additions & 7 deletions config/nrfconnect/app/sample-defaults.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#

CONFIG_CHIP=y
CONFIG_CHIP_DEVICE_VENDOR_ID=65521

CONFIG_STD_CPP14=y

Expand Down Expand Up @@ -51,8 +52,8 @@ CONFIG_NET_BUF_TX_COUNT=80
# Bluetooth Low Energy configs
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=12
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=12
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=36
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=36
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=y
CONFIG_BT_GATT_DYNAMIC_DB=y
CONFIG_BT_DEVICE_APPEARANCE=0
Expand Down Expand Up @@ -86,7 +87,7 @@ CONFIG_OPENTHREAD_MLR=y
# Use mbedTLS from nrf_security library
CONFIG_OPENTHREAD_NRF_SECURITY_CHOICE=y

CONFIG_CC3XX_BACKEND=y
CONFIG_CC3XX_BACKEND=n
CONFIG_OBERON_BACKEND=y

CONFIG_MBEDTLS_ENABLE_HEAP=y
Expand All @@ -106,15 +107,12 @@ CONFIG_MBEDTLS_PK_WRITE_C=y
CONFIG_MBEDTLS_X509_CREATE_C=y
CONFIG_MBEDTLS_X509_CSR_WRITE_C=y

# Use SHA256 implementation from Oberon
CONFIG_CHOICE_OBERON_MBEDTLS_SHA256_C=y

# Disable unneeded crypto operations
CONFIG_MBEDTLS_SHA384_C=n
CONFIG_MBEDTLS_SHA512_C=n
CONFIG_MBEDTLS_CIPHER_MODE_XTS=n
CONFIG_MBEDTLS_CHACHA20_C=n
CONFIG_MBEDTLS_POLY1305_C=n
CONFIG_MBEDTLS_CHACHAPOLY_C=n
CONFIG_MBEDTLS_GCM_C=n
CONFIG_MBEDTLS_RSA_C=n
CONFIG_OBERON_MBEDTLS_AES_C=n
6 changes: 5 additions & 1 deletion config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ endif()

if (CONFIG_NORDIC_SECURITY_BACKEND)
zephyr_include_directories_raw($<TARGET_PROPERTY:mbedtls_external,INTERFACE_INCLUDE_DIRECTORIES>)
zephyr_include_directories_raw($<TARGET_PROPERTY:mbedcrypto_includes,INTERFACE_INCLUDE_DIRECTORIES>)
zephyr_include_directories_raw($<TARGET_PROPERTY:mbedcrypto_common,INTERFACE_INCLUDE_DIRECTORIES>)
if(TARGET platform_cc3xx)
zephyr_include_directories_raw($<TARGET_PROPERTY:platform_cc3xx,INTERFACE_INCLUDE_DIRECTORIES>)
endif()
list(APPEND CHIP_CFLAGS -DMBEDTLS_CONFIG_FILE=<nrf-config.h>)
endif()

if (CONFIG_NRF_802154_RADIO_DRIVER)
zephyr_include_directories_raw($<TARGET_PROPERTY:nrf-802154-driver-interface,INTERFACE_INCLUDE_DIRECTORIES>)
endif()

zephyr_get_compile_flags(CHIP_CFLAGS_C C)
zephyr_get_compile_flags(CHIP_CFLAGS_CC CXX)
zephyr_get_gnu_cpp_standard(CHIP_CFLAGS_CC)
Expand Down
30 changes: 18 additions & 12 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/server/Dnssd.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <lib/support/CHIPMem.h>
Expand All @@ -52,6 +52,8 @@

LOG_MODULE_DECLARE(app);

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

Expand All @@ -63,13 +65,15 @@ constexpr int kExtDiscoveryTimeoutSecs = 20;
constexpr int kAppEventQueueSize = 10;
constexpr uint8_t kButtonPushEvent = 1;
constexpr uint8_t kButtonReleaseEvent = 0;
constexpr chip::EndpointId kIdentifyEndpointId = 1;
constexpr EndpointId kLightEndpointId = 1;
constexpr uint32_t kIdentifyBlinkRateMs = 500;
constexpr uint8_t kDefaultMinLevel = 0;
constexpr uint8_t kDefaultMaxLevel = 254;

K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), kAppEventQueueSize, alignof(AppEvent));
k_timer sFunctionTimer;

Identify sIdentify = { kIdentifyEndpointId, AppTask::IdentifyStartHandler, AppTask::IdentifyStopHandler,
Identify sIdentify = { kLightEndpointId, AppTask::IdentifyStartHandler, AppTask::IdentifyStopHandler,
EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED };

LEDWidget sStatusLED;
Expand Down Expand Up @@ -134,7 +138,14 @@ CHIP_ERROR AppTask::Init()

UpdateStatusLED();

int ret = LightingMgr().Init(LIGHTING_PWM_DEVICE, LIGHTING_PWM_CHANNEL);
// Initialize lighting manager
uint8_t minLightLevel = kDefaultMinLevel;
Clusters::LevelControl::Attributes::MinLevel::Get(kLightEndpointId, &minLightLevel);

uint8_t maxLightLevel = kDefaultMaxLevel;
Clusters::LevelControl::Attributes::MaxLevel::Get(kLightEndpointId, &maxLightLevel);

int ret = LightingMgr().Init(LIGHTING_PWM_DEVICE, LIGHTING_PWM_CHANNEL, minLightLevel, maxLightLevel);
if (ret != 0)
{
return chip::System::MapErrorZephyr(ret);
Expand Down Expand Up @@ -579,20 +590,15 @@ void AppTask::DispatchEvent(AppEvent * aEvent)

void AppTask::UpdateClusterState()
{
uint8_t onoff = LightingMgr().IsTurnedOn();

// write the new on/off value
EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, &onoff,
ZCL_BOOLEAN_ATTRIBUTE_TYPE);
EmberAfStatus status = Clusters::OnOff::Attributes::OnOff::Set(kLightEndpointId, LightingMgr().IsTurnedOn());

if (status != EMBER_ZCL_STATUS_SUCCESS)
{
LOG_ERR("Updating on/off cluster failed: %x", status);
}

uint8_t level = LightingMgr().GetLevel();

status = emberAfWriteAttribute(1, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, &level,
ZCL_INT8U_ATTRIBUTE_TYPE);
status = Clusters::LevelControl::Attributes::CurrentLevel::Set(kLightEndpointId, LightingMgr().GetLevel());

if (status != EMBER_ZCL_STATUS_SUCCESS)
{
Expand Down
16 changes: 11 additions & 5 deletions examples/lighting-app/nrfconnect/main/LightingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "AppConfig.h"

#include <lib/support/CodeUtils.h>

#include <drivers/pwm.h>
#include <logging/log.h>
#include <zephyr.h>
Expand All @@ -28,13 +30,15 @@ LOG_MODULE_DECLARE(app);

LightingManager LightingManager::sLight;

int LightingManager::Init(const device * pwmDevice, uint32_t pwmChannel)
int LightingManager::Init(const device * pwmDevice, uint32_t pwmChannel, uint8_t minLevel, uint8_t maxLevel)
{
// We use a gpioPin instead of a LEDWidget here because we want to use PWM
// and other features instead of just on/off.

mState = kState_On;
mLevel = kMaxLevel;
mMinLevel = minLevel;
mMaxLevel = maxLevel;
mLevel = maxLevel;
mPwmDevice = pwmDevice;
mPwmChannel = pwmChannel;

Expand Down Expand Up @@ -124,7 +128,9 @@ void LightingManager::Set(bool aOn)

void LightingManager::UpdateLight()
{
constexpr uint32_t kPwmWidthUs = 20000u;
const uint8_t level = mState == kState_On ? mLevel : 0;
pwm_pin_set_usec(mPwmDevice, mPwmChannel, kPwmWidthUs, kPwmWidthUs * level / kMaxLevel, 0);
constexpr uint32_t kPwmWidthUs = 20000u;
const uint8_t maxEffectiveLevel = mMaxLevel - mMinLevel;
const uint8_t effectiveLevel = mState == kState_On ? chip::min<uint8_t>(mLevel - mMinLevel, maxEffectiveLevel) : 0;

pwm_pin_set_usec(mPwmDevice, mPwmChannel, kPwmWidthUs, kPwmWidthUs * effectiveLevel / maxEffectiveLevel, 0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ class LightingManager

using LightingCallback_fn = void (*)(Action_t, int32_t);

int Init(const device * pwmDevice, uint32_t pwmChannel);
int Init(const device * pwmDevice, uint32_t pwmChannel, uint8_t minLevel, uint8_t maxLevel);
bool IsTurnedOn() const { return mState == kState_On; }
uint8_t GetLevel() const { return mLevel; }
bool InitiateAction(Action_t aAction, int32_t aActor, uint16_t size, uint8_t * value);
void SetCallbacks(LightingCallback_fn aActionInitiated_CB, LightingCallback_fn aActionCompleted_CB);

private:
static constexpr uint8_t kMaxLevel = 255;

friend LightingManager & LightingMgr();
State_t mState;
uint8_t mMinLevel;
uint8_t mMaxLevel;
uint8_t mLevel;
const device * mPwmDevice;
uint32_t mPwmChannel;
Expand Down
17 changes: 9 additions & 8 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <lib/support/CHIPMem.h>
Expand All @@ -39,11 +39,17 @@
#include <logging/log.h>
#include <zephyr.h>

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

#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
#define APP_EVENT_QUEUE_SIZE 10
#define BUTTON_PUSH_EVENT 1
#define BUTTON_RELEASE_EVENT 0
constexpr EndpointId kLockEndpointId = 1;

LOG_MODULE_DECLARE(app);
K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(AppEvent));
Expand All @@ -59,9 +65,6 @@ static bool sHaveBLEConnections = false;

static k_timer sFunctionTimer;

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

AppTask AppTask::sAppTask;

CHIP_ERROR AppTask::Init()
Expand Down Expand Up @@ -540,11 +543,9 @@ void AppTask::DispatchEvent(AppEvent * aEvent)

void AppTask::UpdateClusterState()
{
uint8_t newValue = !BoltLockMgr().IsUnlocked();

// write the new on/off value
EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, &newValue,
ZCL_BOOLEAN_ATTRIBUTE_TYPE);
EmberAfStatus status = Clusters::OnOff::Attributes::OnOff::Set(kLockEndpointId, !BoltLockMgr().IsUnlocked());

if (status != EMBER_ZCL_STATUS_SUCCESS)
{
LOG_ERR("Updating on/off %x", status);
Expand Down
5 changes: 5 additions & 0 deletions examples/pigweed-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ target_link_libraries(app PUBLIC
pw_rpc.server
)

# Workaround cyclic dependency between nrf_security libraries)
target_link_libraries(mbedcrypto_base PUBLIC
mbedcrypto
)

include(${CHIP_ROOT}/config/nrfconnect/app/flashing.cmake)
1 change: 1 addition & 0 deletions examples/platform/nrfconnect/pw_sys_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ target_compile_options(suppress_zephyr_warnings INTERFACE
-Wno-redundant-decls
-Wno-missing-field-initializers
-Wno-cast-qual
-Wno-undef
)

pw_add_module_library(pw_sys_io.nrfconnect
Expand Down
9 changes: 6 additions & 3 deletions examples/platform/nrfconnect/util/DFUOverSMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

using namespace ::chip::DeviceLayer;

constexpr uint16_t kAdvertisingIntervalMinMs = 400;
constexpr uint16_t kAdvertisingIntervalMaxMs = 500;

DFUOverSMP DFUOverSMP::sDFUOverSMP;

void DFUOverSMP::Init(DFUOverSMPRestartAdvertisingHandler startAdvertisingCb)
Expand Down Expand Up @@ -106,8 +109,8 @@ void DFUOverSMP::StartBLEAdvertising()
BT_DATA(BT_DATA_NAME_COMPLETE, deviceName, static_cast<uint8_t>(strlen(deviceName))) };

int rc;
bt_le_adv_param advParams = BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME, BT_GAP_ADV_FAST_INT_MIN_2,
BT_GAP_ADV_FAST_INT_MAX_2, nullptr);
bt_le_adv_param advParams = BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME, kAdvertisingIntervalMinMs,
kAdvertisingIntervalMaxMs, nullptr);

rc = bt_le_adv_stop();
if (rc)
Expand Down Expand Up @@ -156,7 +159,7 @@ void DFUOverSMP::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* arg
sDFUOverSMP.restartAdvertisingCallback();
}
break;
case DeviceEventType::kCHIPoBLEConnectionClosed:
case DeviceEventType::kCommissioningComplete:
// Check if after closing CHIPoBLE connection advertising is working, if no start SMP advertising.
if (!ConnectivityMgr().IsBLEAdvertisingEnabled())
{
Expand Down
2 changes: 2 additions & 0 deletions examples/pump-app/nrfconnect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ CONFIG_MPU_STACK_GUARD=y

# CHIP configuration
CONFIG_CHIP_PROJECT_CONFIG="main/include/CHIPProjectConfig.h"
# 32784 == 0x8010 (example pump-app)
CONFIG_CHIP_DEVICE_PRODUCT_ID=32784
2 changes: 2 additions & 0 deletions examples/pump-controller-app/nrfconnect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ CONFIG_MPU_STACK_GUARD=y

# CHIP configuration
CONFIG_CHIP_PROJECT_CONFIG="main/include/CHIPProjectConfig.h"
# 32785 == 0x8011 (example pump-controller-app)
CONFIG_CHIP_DEVICE_PRODUCT_ID=32785
11 changes: 6 additions & 5 deletions scripts/setup/nrfconnect/update_ncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import sys


def get_repository_commit_sha(repository_location):
command = ['git', '-C', repository_location, 'rev-parse', 'HEAD']
def get_commit_sha(repository_location, rev):
command = ['git', '-C', repository_location, 'rev-list', '-n', '1', rev]
process = subprocess.run(command, check=True, stdout=subprocess.PIPE)
return process.stdout.decode('ascii').strip()

Expand Down Expand Up @@ -111,11 +111,12 @@ def main():
if not args.quiet:
print("Checking current nRF Connect SDK revision...")

current_revision = get_repository_commit_sha(ncs_base)
current_sha = get_commit_sha(ncs_base, 'HEAD')
recommended_sha = get_commit_sha(ncs_base, recommended_revision)

if current_revision != recommended_revision:
if current_sha != recommended_sha:
print_check_revision_warning_message(
current_revision, recommended_revision)
current_sha, recommended_sha)
sys.exit(1)

if not args.quiet:
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Zephyr/NFCManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace chip {
namespace DeviceLayer {
namespace {
void nfcCallback(void * /* context */, nfc_t2t_event, const uint8_t * /* data */, size_t /* data_length */) {}
void nfcCallback(void * /* context */, nfc_t2t_event_t, const uint8_t * /* data */, size_t /* data_length */) {}
} // namespace

NFCManagerImpl NFCManagerImpl::sInstance;
Expand Down
8 changes: 8 additions & 0 deletions src/platform/nrfconnect/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@

// ==================== Security Adaptations ====================

// Size of the statically allocated context for SHA256 operations in CryptoPAL
// determined empirically.
#ifdef CONFIG_CC3XX_BACKEND
#define CHIP_CONFIG_SHA256_CONTEXT_SIZE 240
#else
#define CHIP_CONFIG_SHA256_CONTEXT_SIZE 208
#endif

// ==================== General Configuration Overrides ====================

#ifndef CHIP_CONFIG_MAX_PEER_NODES
Expand Down
3 changes: 3 additions & 0 deletions src/test_driver/nrfconnect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ CONFIG_STD_CPP14=y
CONFIG_CHIP=y
CONFIG_CHIP_BUILD_TESTS=y
CONFIG_CHIP_ENABLE_DNSSD_SRP=n
CONFIG_CHIP_DEVICE_VENDOR_ID=65521
CONFIG_CHIP_DEVICE_PRODUCT_ID=32768

0 comments on commit 431ab82

Please sign in to comment.