Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[K32W] TE2 fixes #6723

Merged
merged 3 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/lighting-app/k32w/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ k32w_executable("light_app") {
"${chip_root}/src/lib",
"${chip_root}/third_party/mbedtls:mbedtls",
"${k32w_platform_dir}/app/support:freertos_mbedtls_utils",
"${openthread_root}:libopenthread-cli-ftd",
"${openthread_root}:libopenthread-ftd",
"${openthread_root}:libopenthread-cli-mtd",
"${openthread_root}:libopenthread-mtd",
]

cflags = [ "-Wconversion" ]
Expand Down
17 changes: 1 addition & 16 deletions examples/lighting-app/k32w/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,12 @@ extern "C" void main_task(void const * argument)
goto exit;
}

ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
if (ret != CHIP_NO_ERROR)
{
goto exit;
}

// Configure the Thread polling behavior for the device.
{
ConnectivityManager::ThreadPollingConfig pollingConfig;
pollingConfig.Clear();
pollingConfig.ActivePollingIntervalMS = THREAD_ACTIVE_POLLING_INTERVAL_MS;
pollingConfig.InactivePollingIntervalMS = THREAD_INACTIVE_POLLING_INTERVAL_MS;

ret = ConnectivityMgr().SetThreadPollingConfig(pollingConfig);
if (ret != CHIP_NO_ERROR)
{
K32W_LOG("Error during ConnectivityMgr().SetThreadPollingConfig(pollingConfig)");
goto exit;
}
}

ret = PlatformMgr().StartEventLoopTask();
if (ret != CHIP_NO_ERROR)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ m_fsl_prodInfo_size = m_sector_size;
m_fsl_prodInfo_end = m_flash_size - 17 * m_sector_size - 1;
m_fsl_prodInfo_start = m_fsl_prodInfo_end - m_fsl_prodInfo_size + 1;

NV_STORAGE_MAX_SECTORS = 32;
NV_STORAGE_MAX_SECTORS = 63;
NV_STORAGE_SIZE = NV_STORAGE_MAX_SECTORS * m_sector_size;
NV_STORAGE_START_ADDRESS = m_fsl_prodInfo_start - 1;
NV_STORAGE_END_ADDRESS = NV_STORAGE_START_ADDRESS - NV_STORAGE_SIZE + 1;
Expand Down
33 changes: 20 additions & 13 deletions examples/platform/k32w/app/project_include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@

#pragma once

#if BUILD_RELEASE // release build

// Security and Authentication enabled for release build.
#define CHIP_CONFIG_SECURITY_TEST_MODE 0
#define CHIP_CONFIG_REQUIRE_AUTH 1

#else // development build

// Security and Authentication disabled for development build.
// For convenience, enable CHIP Security Test Mode and disable the requirement for
// authentication in various protocols.
Expand All @@ -51,7 +43,7 @@
*
* This option is for testing only and should be disabled in production releases.
*/
#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34
//#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34

// Use a default setup PIN code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
Expand All @@ -68,8 +60,6 @@
*/
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN"

#endif // BUILD_RELEASE

/**
* CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID
*
Expand All @@ -92,7 +82,11 @@
* physical device, a change to its packaging, and/or a change to its marketing presentation.
* This value is generally *not* incremented for device software revisions.
*/
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 1
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 100

#ifndef CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION_STRING
#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION_STRING "v0.1.0"
#endif

/**
* CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING
Expand All @@ -102,8 +96,21 @@
* {MAJOR_VERSION}.0d{MINOR_VERSION}
*/
#ifndef CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING
#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING "0.1ALPHA"
#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING "04-2020-te2"
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION
#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION 42020
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME
#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME "NXP Semiconductors"
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME "NXP Demo App"
#endif

/**
* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
*
Expand Down
1 change: 1 addition & 0 deletions examples/platform/k32w/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import("${chip_root}/src/platform/K32W/args.gni")

arm_float_abi = "soft"
arm_cpu = "cortex-m4"
arm_arch = "armv7e-m"

openthread_project_core_config_file = "OpenThreadConfig.h"
openthread_core_config_deps = []
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples/k32w_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ env

"$(dirname "$0")"/../../third_party/k32w_sdk/sdk_fixes/patch_k32w_sdk.sh

gn gen --root="$1" "$2" --args="k32w_sdk_root=\"$K32W061_SDK_ROOT\" is_debug=true"
gn gen --root="$1" "$2" --args="k32w_sdk_root=\"$K32W061_SDK_ROOT\" is_debug=false"
ninja -C "$2"
4 changes: 3 additions & 1 deletion src/platform/K32W/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
#endif // CHIP_DEVICE_CONFIG_BLE_APP_TASK_NAME

#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 1
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 0
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0
#define CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH 0

Expand All @@ -101,3 +101,5 @@

#define CONFIG_CHIP_NFC_COMMISSIONING 1
#define CHIP_DEVICE_CONFIG_ENABLE_NFC 1

#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1
16 changes: 15 additions & 1 deletion src/platform/K32W/K32WConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,20 @@ CHIP_ERROR K32WConfig::FactoryResetConfig(void)
{
CHIP_ERROR err;

err = FactoryResetConfigInternal(kMinConfigKey_ChipConfig, kMaxConfigKey_ChipConfig);

if (err == CHIP_NO_ERROR)
{
err = FactoryResetConfigInternal(kMinConfigKey_KVS, kMaxConfigKey_KVS);
}

return err;
}

CHIP_ERROR K32WConfig::FactoryResetConfigInternal(Key firstKey, Key lastKey)
{
CHIP_ERROR err;

// Iterate over all the CHIP Config PDM ID records and delete each one
err = ForEachRecord(kMinConfigKey_ChipConfig, kMaxConfigKey_ChipConfig, false,
[](const Key & pdmKey, const size_t & length) -> CHIP_ERROR {
Expand Down Expand Up @@ -413,7 +427,7 @@ bool K32WConfig::ValidConfigKey(Key key)
{
// Returns true if the key is in the valid CHIP Config PDM key range.

if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_ChipCounter))
if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_KVS))
{
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/platform/K32W/K32WConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class K32WConfig
* Cleared during factory reset. */
static constexpr uint8_t kPDMId_ChipCounter = 0x03; /**< PDM id for settings containing dynamic counter values set at runtime.
* Retained during factory reset. */
static constexpr uint8_t kPDMId_KVS = 0x04; /**< PDM id for settings containing KVS set at runtime.
* Cleared during factory reset. */

using Key = uint32_t;

Expand Down Expand Up @@ -121,6 +123,8 @@ class K32WConfig
static constexpr Key kMaxConfigKey_ChipConfig = K32WConfigKey(kPDMId_ChipConfig, 0x1E);
static constexpr Key kMinConfigKey_ChipCounter = K32WConfigKey(kPDMId_ChipCounter, 0x00);
static constexpr Key kMaxConfigKey_ChipCounter = K32WConfigKey(kPDMId_ChipCounter, 0x1F); // Allows 32 Counters to be created.
static constexpr Key kMinConfigKey_KVS = K32WConfigKey(kPDMId_KVS, 0x00);
static constexpr Key kMaxConfigKey_KVS = K32WConfigKey(kPDMId_KVS, 0xFF);

static CHIP_ERROR Init(void);

Expand Down Expand Up @@ -154,6 +158,7 @@ class K32WConfig
private:
static CHIP_ERROR MapPdmStatus(PDM_teStatus pdmStatus);
static CHIP_ERROR MapPdmInitStatus(int pdmStatus);
static CHIP_ERROR FactoryResetConfigInternal(Key firstKey, Key lastKey);
};

/**
Expand Down
70 changes: 70 additions & 0 deletions src/platform/K32W/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,85 @@
* @file
* Platform-specific key value storage implementation for K32W
*/
/* this file behaves like a config.h, comes first */
#include <platform/internal/CHIPDeviceLayerInternal.h>

#include "support/CHIPMem.h"
#include <platform/K32W/K32WConfig.h>
#include <platform/KeyValueStoreManager.h>
#include <string>

#include "PDM.h"

namespace chip {
namespace DeviceLayer {
namespace PersistedStorage {

/* TODO: adjust this value */
#define MAX_NO_OF_KEYS 255

KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance;

CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size,
size_t offset_bytes)
{
CHIP_ERROR err = CHIP_NO_ERROR;
std::hash<std::string> hash_fn;
uint16_t key_id;
uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS;
size_t read_bytes;

VerifyOrExit((key != NULL) && (value != NULL), err = CHIP_ERROR_INVALID_ARGUMENT);
key_id = hash_fn(key) % MAX_NO_OF_KEYS;

ChipLogProgress(DeviceLayer, "KVS, get key id:: %i", key_id);

err = chip::DeviceLayer::Internal::K32WConfig::ReadConfigValueBin(
chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id), (uint8_t *) value, value_size, read_bytes);

*read_bytes_size = read_bytes;

exit:
return err;
}

CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size)
{
CHIP_ERROR err = CHIP_NO_ERROR;
std::hash<std::string> hash_fn;
uint16_t key_id;
uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS;

VerifyOrExit((key != NULL) && (value != NULL), err = CHIP_ERROR_INVALID_ARGUMENT);
key_id = hash_fn(key) % MAX_NO_OF_KEYS;

ChipLogProgress(DeviceLayer, "KVS, put key id:: %i", key_id);

err = chip::DeviceLayer::Internal::K32WConfig::WriteConfigValueBin(
chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id), (uint8_t *) value, value_size);

exit:
return err;
}

CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
{
CHIP_ERROR err = CHIP_NO_ERROR;
std::hash<std::string> hash_fn;
uint16_t key_id;
uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS;

VerifyOrExit(key != NULL, err = CHIP_ERROR_INVALID_ARGUMENT);
key_id = hash_fn(key) % MAX_NO_OF_KEYS;

ChipLogProgress(DeviceLayer, "KVS, deleting key id:: %i", key_id);

err = chip::DeviceLayer::Internal::K32WConfig::ClearConfigValue(chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id));

exit:
return err;
}

} // namespace PersistedStorage
} // namespace DeviceLayer
} // namespace chip
11 changes: 4 additions & 7 deletions src/platform/K32W/KeyValueStoreManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager
public:
// NOTE: Currently this platform does not support partial and offset reads
// these will return CHIP_ERROR_NOT_IMPLEMENTED.
CHIP_ERROR _Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size = nullptr, size_t offset = 0)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
CHIP_ERROR _Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size, size_t offset);

CHIP_ERROR _Delete(const char * key) { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR _Delete(const char * key);

CHIP_ERROR _Put(const char * key, const void * value, size_t value_size) { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR _Put(const char * key, const void * value, size_t value_size);

private:
// ===== Members for internal use by the following friends.
Expand All @@ -68,7 +65,7 @@ inline KeyValueStoreManager & KeyValueStoreMgr(void)
* Returns the platform-specific implementation of the KeyValueStoreManager singleton object.
*
* Chip applications can use this to gain access to features of the KeyValueStoreManager
* that are specific to the ESP32 platform.
* that are specific to the K32W platform.
*/
inline KeyValueStoreManagerImpl & KeyValueStoreMgrImpl(void)
{
Expand Down
2 changes: 2 additions & 0 deletions src/platform/K32W/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ chip_inet_config_enable_dns_resolver = false

chip_build_tests = false

chip_mdns = "platform"

mbedtls_target = "${chip_root}/third_party/k32w_sdk:mbedtls"
openthread_external_mbedtls = mbedtls_target

Expand Down
2 changes: 1 addition & 1 deletion src/platform/K32W/gatt_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ VALUE(value_device_name, gBleSig_GapDeviceName_d, (gPermissionFlagReadable_c), 1
CHARACTERISTIC(char_appearance, gBleSig_GapAppearance_d, (gGattCharPropRead_c))
VALUE(value_appearance, gBleSig_GapAppearance_d, (gPermissionFlagReadable_c), 2, 0x00, 0x00)

PRIMARY_SERVICE(service_chipoble, gBleSig_BtpService_d)
PRIMARY_SERVICE(service_chipoble, gChipoBleService_d)
CHARACTERISTIC_UUID128(chipoble_rx, uuid_chipoble_rx, (gGattCharPropWrite_c))
VALUE_UUID128_VARLEN(value_chipoble_rx, uuid_chipoble_rx, (gPermissionFlagWritable_c), gAttMaxMtu_c - 3, gAttMaxMtu_c - 3, 0x00)
CHARACTERISTIC_UUID128(chipoble_tx, uuid_chipoble_tx, (gGattCharPropIndicate_c | gGattCharPropRead_c))
Expand Down
4 changes: 2 additions & 2 deletions src/platform/K32W/gatt_uuid128.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
/* Services */

/* Wireless UART */
UUID128(uuid_service_chipoble, 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xF6, 0xFF, 0x00, 0x00)
#define gChipoBleService_d 0xFFF6

UUID128(uuid_chipoble_tx, 0x12, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18)
UUID128(uuid_chipoble_rx, 0x11, 0x9D, 0x9F, 0x42, 0x9C, 0x4F, 0x9F, 0x95, 0x59, 0x45, 0x3D, 0x26, 0xF5, 0x2E, 0xEE, 0x18)
11 changes: 8 additions & 3 deletions third_party/k32w_sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ config("mbedtls_k32w_config") {
"MBEDTLS_THREADING_ALT=1",
"MBEDTLS_X509_CSR_WRITE_C",
"MBEDTLS_X509_CREATE_C",
"MBEDTLS_PK_WRITE_C",
"MBEDTLS_OID_C",
"MBEDTLS_PEM_WRITE_C",
"MBEDTLS_BASE64_C",
"MBEDTLS_HKDF_C",
"MBEDTLS_ERROR_C",
"MBEDTLS_PKCS5_C",
]

if (chip_mdns == "none") {
defines += [
"MBEDTLS_PK_WRITE_C",
"MBEDTLS_OID_C",
"MBEDTLS_BASE64_C",
]
}

include_dirs = [ chip_root ]
}

Expand Down
Loading