Skip to content

Commit

Permalink
[ASR] add asr550x support, fix some platform issue (#27987)
Browse files Browse the repository at this point in the history
* [ASR] add asr550x support

* update CI with all build options

* add Identify implementation example
  • Loading branch information
tx2rx authored Jul 18, 2023
1 parent 7a815f6 commit e9df402
Show file tree
Hide file tree
Showing 22 changed files with 912 additions and 346 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/examples-asr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ jobs:
"./scripts/build/build_examples.py \
--target asr-asr582x-all-clusters \
--target asr-asr582x-all-clusters-minimal \
--target asr-asr582x-lighting \
--target asr-asr582x-light-switch \
--target asr-asr582x-lock \
--target asr-asr582x-lighting-ota \
--target asr-asr582x-light-switch-shell \
--target asr-asr582x-lock-no_logging \
--target asr-asr582x-ota-requestor \
--target asr-asr582x-bridge \
--target asr-asr582x-temperature-measurement \
--target asr-asr582x-thermostat \
--target asr-asr582x-bridge-factory \
--target asr-asr582x-temperature-measurement-rotating_id \
--target asr-asr582x-thermostat-rio \
build \
"
10 changes: 10 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,13 @@
url = https://github.com/google/perfetto.git
branch = master
platforms = linux,android
[submodule "third_party/asr/components"]
path = third_party/asr/components
url = https://github.com/asriot/asriot_components.git
branch = matter
platforms = asr
[submodule "third_party/asr/asr550x/asr_sdk"]
path = third_party/asr/asr550x/asr_sdk
url = https://github.com/asriot/ASR550X_Freertos.git
branch = matter
platforms = asr
5 changes: 3 additions & 2 deletions config/asr/toolchain/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import("//build_overrides/asr.gni")
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

assert(asr_ic_family == "asr582x" || asr_ic_family == "asr595x",
assert(asr_ic_family == "asr582x" || asr_ic_family == "asr595x" ||
asr_ic_family == "asr550x",
"Unsupported ASR IC: ${asr_ic_family}")

if (asr_ic_family == "asr582x") {
if (asr_ic_family == "asr582x" || asr_ic_family == "asr550x") {
import("${build_root}/toolchain/arm_gcc/arm_toolchain.gni")
_tool_name_root = "${asr_toolchain_root}arm-none-eabi-"
}
Expand Down
9 changes: 7 additions & 2 deletions docs/guides/asr_getting_started_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The ASR platform is supported on:

- [ASR582X](http://www.asrmicro.com/en/goods/proinfo/36.html)
- [ASR595X](http://www.asrmicro.com/en/goods/proinfo/42.html)
- [ASR550X](http://www.asrmicro.com/en/goods/proinfo/14.html)

## Matter Example Applications

Expand All @@ -35,9 +36,8 @@ to speed up development. You can find them in the samples with `/asr` subfolder.
- [Setup Matter Environment](./BUILDING.md)

- Setup toolchain
- for ASR582X
- for ASR582X and ASR550X
```
cd toolchain
wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/RC2.1/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2
tar -jxvf gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2
export ASR_TOOLCHAIN_PATH={abs-path-to-toolchain}/gcc-arm-none-eabi-9-2019-q4-major/bin/
Expand All @@ -60,6 +60,10 @@ to speed up development. You can find them in the samples with `/asr` subfolder.
```
export ASR_BOARD=asr595x
```
- for ASR550X:
```
export ASR_BOARD=asr550x
```
- Building the Application
If the lighting example is to be built:
Expand Down Expand Up @@ -91,6 +95,7 @@ There are two commissioning modes supported by ASR platform:
```
./chip-tool pairing ble-wifi <node_id> <ssid> <password> <pin_code> <discriminator>
```
5. Only ASR582X and ASR595X support BLE
### IP mode
Expand Down
44 changes: 44 additions & 0 deletions examples/platform/asr/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
#include <support/CodeUtils.h>
#include <support/ErrorStr.h>

#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER
#include <app/clusters/identify-server/identify-server.h>
#endif

using namespace ::chip;
using namespace ::chip::app;

namespace chip {

Expand Down Expand Up @@ -74,3 +79,42 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
cb->PostAttributeChangeCallback(path.mEndpointId, path.mClusterId, path.mAttributeId, type, size, value);
}
}

#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER
void OnIdentifyStart(Identify *)
{
ChipLogProgress(Zcl, "OnIdentifyStart");
}

void OnIdentifyStop(Identify *)
{
ChipLogProgress(Zcl, "OnIdentifyStop");
}

void OnTriggerEffect(Identify * identify)
{
switch (identify->mCurrentEffectIdentifier)
{
case Clusters::Identify::EffectIdentifierEnum::kBlink:
ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kBlink");
break;
case Clusters::Identify::EffectIdentifierEnum::kBreathe:
ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kBreathe");
break;
case Clusters::Identify::EffectIdentifierEnum::kOkay:
ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kOkay");
break;
case Clusters::Identify::EffectIdentifierEnum::kChannelChange:
ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kChannelChange");
break;
default:
ChipLogProgress(Zcl, "No identifier effect");
return;
}
}

static Identify gIdentify1 = {
chip::EndpointId{ 1 }, OnIdentifyStart, OnIdentifyStop, Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator,
OnTriggerEffect,
};
#endif
2 changes: 2 additions & 0 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ def BuildASRTarget():
target.AppendFixedTargets([
TargetPart('asr582x', board=ASRBoard.ASR582X),
TargetPart('asr595x', board=ASRBoard.ASR595X),
TargetPart('asr550x', board=ASRBoard.ASR550X),
])

# apps
Expand All @@ -436,6 +437,7 @@ def BuildASRTarget():
target.AppendModifier('no_logging', chip_logging=False)
target.AppendModifier('factory', enable_factory=True)
target.AppendModifier('rotating_id', enable_rotating_device_id=True)
target.AppendModifier('rio', enable_lwip_ip6_hook=True)

return target

Expand Down
15 changes: 14 additions & 1 deletion scripts/build/builders/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ def BuildRoot(self, root):
class ASRBoard(Enum):
ASR582X = auto()
ASR595X = auto()
ASR550X = auto()

def GetIC(self):
if self == ASRBoard.ASR582X:
return 'asr582x'
elif self == ASRBoard.ASR595X:
return 'asr595x'
elif self == ASRBoard.ASR550X:
return 'asr550x'
else:
raise Exception('Unknown board #: %r' % self)

Expand All @@ -101,7 +104,8 @@ def __init__(self,
chip_logging: bool = True,
enable_factory: bool = False,
enable_rotating_device_id: bool = False,
enable_ota_requestor: bool = False):
enable_ota_requestor: bool = False,
enable_lwip_ip6_hook: bool = False):
super(ASRBuilder, self).__init__(
root=app.BuildRoot(root),
runner=runner)
Expand All @@ -118,6 +122,9 @@ def __init__(self,
elif asr_chip == "asr595x":
ASR_ARCH = "riscv"
ASR_SDK_ROOT = "//third_party/connectedhomeip/third_party/asr/asr595x"
elif asr_chip == "asr550x":
ASR_ARCH = "arm"
ASR_SDK_ROOT = "//third_party/connectedhomeip/third_party/asr/asr550x"
self.extra_gn_options.append('target_cpu="%s"' % ASR_ARCH)

toolchain = os.path.join(root, os.path.split(os.path.realpath(__file__))[0], '../../../config/asr/toolchain')
Expand All @@ -132,6 +139,9 @@ def __init__(self,
or asr_chip == "asr595x"):
self.extra_gn_options.append('chip_config_network_layer_ble=true')

if (asr_chip == "asr550x"):
self.extra_gn_options.append('chip_config_network_layer_ble=false')

if enable_ota_requestor:
self.extra_gn_options.append('chip_enable_ota_requestor=true')

Expand All @@ -149,6 +159,9 @@ def __init__(self,
self.extra_gn_options.append('chip_enable_additional_data_advertising=true')
self.extra_gn_options.append('chip_enable_rotating_device_id=true')

if enable_lwip_ip6_hook:
self.extra_gn_options.append('chip_lwip_ip6_hook=true')

self.extra_gn_options.append('asr_toolchain_root="%s"' % os.environ['ASR_TOOLCHAIN_PATH'])

def GnBuildArgs(self):
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/testdata/all_targets_linux_x64.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ameba-amebad-{all-clusters,all-clusters-minimal,light,light-switch,pigweed}
asr-{asr582x,asr595x}-{all-clusters,all-clusters-minimal,lighting,light-switch,lock,bridge,temperature-measurement,thermostat,ota-requestor}[-ota][-shell][-no_logging][-factory][-rotating_id]
asr-{asr582x,asr595x,asr550x}-{all-clusters,all-clusters-minimal,lighting,light-switch,lock,bridge,temperature-measurement,thermostat,ota-requestor}[-ota][-shell][-no_logging][-factory][-rotating_id][-rio]
android-{arm,arm64,x86,x64,androidstudio-arm,androidstudio-arm64,androidstudio-x86,androidstudio-x64}-{chip-tool,chip-test,tv-server,tv-casting-app,java-matter-controller}[-no-debug]
bouffalolab-{bl602-iot-matter-v1,bl602-iot-dvk-3s,bl602-night-light,xt-zb6-devkit,bl706-iot-dvk,bl706-night-light,bl704l-dvk}-light[-shell][-115200][-rpc][-cdc][-rotating_device_id]
cc32xx-lock
Expand Down
88 changes: 68 additions & 20 deletions src/platform/ASR/ASRFactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ CHIP_ERROR ASRFactoryDataProvider::GetProductId(uint16_t & productId)
#else
uint32_t productId32;
ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_PRODUCT_ID_PARTITION, productId32));
productId = static_cast<uint16_t>(productId32);
productId = static_cast<uint16_t>(productId32);
#endif
return CHIP_NO_ERROR;
}
Expand All @@ -424,40 +424,88 @@ CHIP_ERROR ASRFactoryDataProvider::GetProductLabel(char * buf, size_t bufSize)

CHIP_ERROR ASRFactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize)
{
ChipError err = CHIP_NO_ERROR;
#if !CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER), CHIP_ERROR_BUFFER_TOO_SMALL);
strcpy(buf, CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER);
#else
#define BUFFER_MAX_SIZE 32
uint8_t buffer[BUFFER_MAX_SIZE + 1] = { 0 };
size_t buffer_len = BUFFER_MAX_SIZE + 1;
ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_SERIAL_NUMBER_PARTITION, buffer, buffer_len, buffer_len));
ReturnErrorCodeIf(bufSize < buffer_len, CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(buf, buffer, buffer_len);
buf[buffer_len] = 0;
#endif
return CHIP_NO_ERROR;
}

size_t serialNumLen = 0; // without counting null-terminator
CHIP_ERROR ASRFactoryDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day)
{
CHIP_ERROR err = CHIP_NO_ERROR;
enum
{
kDateStringLength = 10 // YYYY-MM-DD
};
char dateStr[kDateStringLength + 1];
char * parseEnd;
#if !CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER
memcpy(dateStr, CHIP_DEVICE_CONFIG_TEST_MANUFACTURY_DATE, kDateStringLength + 1);
#else
size_t dateLen;
err = ASRConfig::ReadFactoryConfigValue(ASR_MANUFACTURY_DATE_PARTITION, (uint8_t *) dateStr, sizeof(dateStr), dateLen);
SuccessOrExit(err);

#ifdef CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER
if (CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER[0] != 0)
VerifyOrExit(dateLen == kDateStringLength, err = CHIP_ERROR_INVALID_ARGUMENT);
#endif
// Cast does not lose information, because we then check that we only parsed
// 4 digits, so our number can't be bigger than 9999.
year = static_cast<uint16_t>(strtoul(dateStr, &parseEnd, 10));
VerifyOrExit(parseEnd == dateStr + 4, err = CHIP_ERROR_INVALID_ARGUMENT);

// Cast does not lose information, because we then check that we only parsed
// 2 digits, so our number can't be bigger than 99.
month = static_cast<uint8_t>(strtoul(dateStr + 5, &parseEnd, 10));
VerifyOrExit(parseEnd == dateStr + 7, err = CHIP_ERROR_INVALID_ARGUMENT);

// Cast does not lose information, because we then check that we only parsed
// 2 digits, so our number can't be bigger than 99.
day = static_cast<uint8_t>(strtoul(dateStr + 8, &parseEnd, 10));
VerifyOrExit(parseEnd == dateStr + 10, err = CHIP_ERROR_INVALID_ARGUMENT);

exit:
if (err != CHIP_NO_ERROR && err != CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
ReturnErrorCodeIf(sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER) > bufSize, CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(buf, CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER, sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER));
serialNumLen = sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER) - 1;
err = CHIP_NO_ERROR;
ChipLogError(DeviceLayer, "Invalid manufacturing date: %s", dateStr);
}
#endif // CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER

ReturnErrorCodeIf(serialNumLen >= bufSize, CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorCodeIf(buf[serialNumLen] != 0, CHIP_ERROR_INVALID_STRING_LENGTH);

return err;
}

CHIP_ERROR ASRFactoryDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR ASRFactoryDataProvider::GetHardwareVersion(uint16_t & hardwareVersion)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
#if !CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER
hardwareVersion = static_cast<uint16_t>(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION);
#else
uint32_t hardwareVersion32;
ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_HARDWARE_VERSION_PARTITION, hardwareVersion32));
hardwareVersion = static_cast<uint16_t>(hardwareVersion32);
#endif
return CHIP_NO_ERROR;
}

CHIP_ERROR ASRFactoryDataProvider::GetHardwareVersionString(char * buf, size_t bufSize)
{
#if !CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL);
strcpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING);
#else
#define BUFFER_MAX_SIZE 32
uint8_t buffer[BUFFER_MAX_SIZE + 1] = { 0 };
size_t buffer_len = BUFFER_MAX_SIZE + 1;
ReturnErrorOnFailure(ASRConfig::ReadFactoryConfigValue(ASR_HARDWARE_VERSION_STR_PARTITION, buffer, buffer_len, buffer_len));
ReturnErrorCodeIf(bufSize < buffer_len, CHIP_ERROR_BUFFER_TOO_SMALL);
memcpy(buf, buffer, buffer_len);
buf[buffer_len] = 0;
#endif
return CHIP_NO_ERROR;
}

Expand Down
1 change: 1 addition & 0 deletions src/platform/ASR/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 1024 * 8
#define CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY 1
#define CHIP_DEVICE_CONFIG_ENABLE_TEST_SETUP_PARAMS 1
#define CHIP_DEVICE_CONFIG_TEST_MANUFACTURY_DATE "2023-07-07"

#if defined(CFG_PLF_RV32) || defined(CFG_PLF_DUET)
// ASR582X/ASR595X support Wi-Fi and BLE
Expand Down
3 changes: 1 addition & 2 deletions src/platform/ASR/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ void ASRWiFiDriver::OnNetworkStatusChange()
if (staConnected)
{
mpStatusChangeCallback->OnNetworkingStatusChange(
Status::kSuccess, MakeOptional(ByteSpan(configuredNetwork.networkID, configuredNetwork.networkIDLen)),
MakeOptional(GetLastDisconnectReason()));
Status::kSuccess, MakeOptional(ByteSpan(configuredNetwork.networkID, configuredNetwork.networkIDLen)), NullOptional);
return;
}
mpStatusChangeCallback->OnNetworkingStatusChange(
Expand Down
Loading

0 comments on commit e9df402

Please sign in to comment.