Skip to content

Commit

Permalink
[K32W0] SVE fixes (#20471)
Browse files Browse the repository at this point in the history
Main fixes/functionalities brought in this PR:
* add initial enablement for K32W041A/AM
* add linker file fixes for OTA enablement
* add detokenizer support for the elock and
moved the script location to a generic location
* move tinycrypt implementation in a separate class
* enable low power with SDK 2.6.6
* enable MACv2
* refactoring around PDM storage
* add size-optimized BLE libraries

Signed-off-by: Doru Gucea <[email protected]>
Signed-off-by: Marius Tache <[email protected]>
Signed-off-by: Andrei Menzopol <[email protected]>
  • Loading branch information
doru91 authored Jul 22, 2022
1 parent 0629b6e commit 9b2c889
Show file tree
Hide file tree
Showing 42 changed files with 2,224 additions and 641 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/examples-k32w.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-k32w:0.5.84
image: connectedhomeip/chip-build-k32w:0.5.87
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
steps:
Expand Down Expand Up @@ -82,15 +82,15 @@ jobs:
timeout-minutes: 5
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
k32w k32w061+release light \
out/artifacts/k32w-light-release-no-ota/chip-k32w061-light-example \
k32w k32w0+release light \
out/artifacts/k32w-light-release-no-ota/chip-k32w0x-light-example \
/tmp/bloat_reports/
- name: Get lock size stats
timeout-minutes: 5
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
k32w k32w061+release lock \
out/artifacts/k32w-lock-low-power-release/chip-k32w061-lock-example \
k32w k32w0+release lock \
out/artifacts/k32w-lock-low-power-release/chip-k32w0x-lock-example \
/tmp/bloat_reports/
- name: Uploading Size Reports
uses: actions/upload-artifact@v2
Expand Down
18 changes: 13 additions & 5 deletions examples/lighting-app/nxp/k32w/k32w0/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import("${k32w0_sdk_build_root}/k32w0_sdk.gni")

import("${chip_root}/src/crypto/crypto.gni")
import("${chip_root}/src/lib/core/core.gni")
import("${chip_root}/src/lib/core/core.gni")
import("${chip_root}/src/platform/device.gni")

if (chip_pw_tokenizer_logging) {
Expand Down Expand Up @@ -66,7 +65,7 @@ k32w0_sdk("sdk") {
}

k32w0_executable("light_app") {
output_name = "chip-k32w061-light-example"
output_name = "chip-k32w0x-light-example"

sources = [
"${k32w0_platform_dir}/util/LEDWidget.cpp",
Expand Down Expand Up @@ -103,7 +102,7 @@ k32w0_executable("light_app") {

cflags = [ "-Wconversion" ]

ldscript = "${k32w0_platform_dir}/app/ldscripts/chip-k32w061-linker.ld"
ldscript = "${k32w0_platform_dir}/app/ldscripts/chip-k32w0x-linker.ld"

inputs = [ ldscript ]

Expand All @@ -118,15 +117,24 @@ k32w0_executable("light_app") {
]
}

if (chip_enable_ota_requestor) {
ldflags += [
"-Wl,--defsym",
"-Wl,__app_load_address__=0x4000",
"-Wl,--defsym",
"-Wl,__app_stated_size__=0x99A00",
]
}

output_dir = root_out_dir
}

if (chip_pw_tokenizer_logging) {
pw_tokenizer_database("light_app.database") {
database = "$root_build_dir/chip-k32w061-light-example-database.bin"
database = "$root_build_dir/chip-k32w0x-light-example-database.bin"
create = "binary"
deps = [ ":light_app" ]
optional_paths = [ "$root_build_dir/chip-k32w061-light-example" ]
optional_paths = [ "$root_build_dir/chip-k32w0x-light-example" ]
}
}

Expand Down
52 changes: 30 additions & 22 deletions examples/lighting-app/nxp/k32w/k32w0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,23 @@ will be initiated.
In order to build the Project CHIP example, we recommend using a Linux
distribution (the demo-application was compiled on Ubuntu 20.04).

- Download [K32W061 SDK 2.6.4 for Project CHIP](https://mcuxpresso.nxp.com/).
- Download [K32W0 SDK 2.6.6 for Project CHIP](https://mcuxpresso.nxp.com/).
Creating an nxp.com account is required before being able to download the
SDK. Once the account is created, login and follow the steps for downloading
SDK_2_6_4_K32W061DK6. The SDK Builder UI selection should be similar with
the one from the image below.
SDK_2_6_6_K32W061DK6 (required for K32W061 flavor). The SDK Builder UI
selection should be similar with the one from the image below.
![MCUXpresso SDK Download](../../../../platform/nxp/k32w/k32w0/doc/images/mcux-sdk-download.JPG)

- Start building the application either with Secure Element or without
- without Secure Element

```
user@ubuntu:~/Desktop/git/connectedhomeip$ export NXP_K32W061_SDK_ROOT=/home/user/Desktop/SDK_2_6_4_K32W061DK6/
user@ubuntu:~/Desktop/git/connectedhomeip$ ./third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh
user@ubuntu:~/Desktop/git/connectedhomeip$ export NXP_K32W0_SDK_ROOT=/home/user/Desktop/SDK_2_6_6_K32W061DK6/
user@ubuntu:~/Desktop/git/connectedhomeip$ source ./scripts/activate.sh
user@ubuntu:~/Desktop/git/connectedhomeip$ cd examples/lighting-app/nxp/k32w/k32w0
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/nxp/k32w/k32w0$ gn gen out/debug --args="k32w0_sdk_root=\"${NXP_K32W061_SDK_ROOT}\" chip_with_OM15082=1 chip_with_ot_cli=0 is_debug=false chip_crypto=\"mbedtls\" chip_with_se05x=0 mbedtls_use_tinycrypt=true chip_pw_tokenizer_logging=true mbedtls_repo=\"//third_party/connectedhomeip/third_party/nxp/libs/mbedtls\""
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/nxp/k32w/k32w0$ gn gen out/debug --args="k32w0_sdk_root=\"${NXP_K32W0_SDK_ROOT}\" chip_with_OM15082=1 chip_with_ot_cli=0 is_debug=false chip_crypto=\"tinycrypt\" chip_with_se05x=0 chip_pw_tokenizer_logging=true mbedtls_repo=\"//third_party/connectedhomeip/third_party/nxp/libs/mbedtls\""
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/nxp/k32w/k32w0$ ninja -C out/debug
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/nxp/k32w/k32w0$ $NXP_K32W061_SDK_ROOT/tools/imagetool/sign_images.sh out/debug/
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/nxp/k32w/k32w0$ $NXP_K32W0_SDK_ROOT/tools/imagetool/sign_images.sh out/debug/
```

- with Secure element
Expand All @@ -201,8 +200,9 @@ user@ubuntu:~/Desktop/git/connectedhomeip/examples/lighting-app/nxp/k32w/k32w0$
Note that option chip_enable_ota_requestor=false are required for building with
Secure Element. These can be changed if building without Secure Element

Note that "patch_k32w_sdk.sh" script must be run for patching the K32W061 SDK
2.6.4.
- for K32W041AM flavor:
Exactly the same steps as above but set build_for_k32w041am=1 in the gn command.
Also, select the K32W041AM SDK from the SDK Builder.

Also, in case the OM15082 Expansion Board is not attached to the DK6 board, the
build argument (chip_with_OM15082) inside the gn build instruction should be set
Expand All @@ -225,7 +225,7 @@ pycrypto 2.6.1
pycryptodome 3.9.8
```

The resulting output file can be found in out/debug/chip-k32w061-light-example.
The resulting output file can be found in out/debug/chip-k32w0x-light-example.

<a name="flashdebug"></a>

Expand All @@ -235,8 +235,8 @@ Program the firmware using the official
[OpenThread Flash Instructions](https://github.com/openthread/ot-nxp/tree/main/src/k32w0/k32w061#flash-binaries).

All you have to do is to replace the Openthread binaries from the above
documentation with _out/debug/chip-k32w061-light-example.bin_ if DK6Programmer
is used or with _out/debug/chip-k32w061-light-example_ if MCUXpresso is used.
documentation with _out/debug/chip-k32w0x-light-example.bin_ if DK6Programmer is
used or with _out/debug/chip-k32w0x-light-example_ if MCUXpresso is used.

<a name="tokenizer"></a>

Expand All @@ -252,8 +252,10 @@ needed for parsing the hashed scripts.
### Detokenizer script

The python3 script detokenizer.py is a script that decodes the tokenized logs
either from a file or from a serial port. The script can be used in the
following ways:
either from a file or from a serial port. It is located in the following path
`examples/platform/nxp/k32w/k32w0/scripts/detokenizer.py`.

The script can be used in the following ways:

```
usage: detokenizer.py serial [-h] -i INPUT -d DATABASE [-o OUTPUT]
Expand All @@ -268,7 +270,7 @@ the serial to decode from.

The third parameter is _-d DATABASE_ and represents the path to the token
database to be used for decoding. The default path is
_out/debug/chip-k32w061-light-example-database.bin_ after a successful build.
_out/debug/chip-k32w0x-light-example-database.bin_ after a successful build.

The forth parameter is _-o OUTPUT_ and it represents the path to the output file
where the decoded logs will be stored. This parameter is required for file usage
Expand All @@ -284,7 +286,12 @@ argument _chip_pw_tokenizer_logging=true_ was used.

The detokenizer script must be run inside the example's folder after a
successful run of the _scripts/activate.sh_ script. The pw_tokenizer module used
by the script is loaded by the environment.
by the script is loaded by the environment. An example of running the
detokenizer script to see logs of a lighting app:

```
python3 ../../../../../examples/platform/nxp/k32w/k32w0/scripts/detokenizer.py serial -i /dev/ttyACM0 -d out/debug/chip-k32w0x-light-example-database.bin -o device.txt
```

<a name="detokenizer-known-issues"></a>

Expand Down Expand Up @@ -318,11 +325,12 @@ Note: This solution is temporary.
In order to use the tinycrypt ecc operations, use the following build arguments:

- Build without Secure element (_chip_with_se05x=0_), with tinycrypt enabled
(_mbedtls_use_tinycrypt=true_) and with the `NXPmicro/mbedtls` library
(_chip_crypto=\"tinycrypt\"_) and with the `NXPmicro/mbedtls` library
(_mbedtls_repo=`\"//third_party/connectedhomeip/third_party/nxp/libs/mbedtls\"`_).

To disable tinycrypt ecc operations, simply build without
_mbedtls_use_tinycrypt=true_ and without _mbedtls_repo_.
To disable tinycrypt ecc operations, simply build with _chip_crypto=\"mbedtls\"_
and with or without _mbedtls_repo_. If used with _mbedtls_repo_ the mbedtls
implementation from `NXPmicro/mbedtls` library will be used.

<a name="ota"></a>

Expand Down Expand Up @@ -406,7 +414,7 @@ CD04 -> 0x4CD pages of 512-bytes (= 614,5kB)
DK6Programmer can be used for flashing the application:

```
DK6Programmer.exe -V2 -s <COM_PORT> -P 1000000 -Y -p FLASH@0x4000="chip-k32w061-light-example.bin"
DK6Programmer.exe -V2 -s <COM_PORT> -P 1000000 -Y -p FLASH@0x4000="chip-k32w0x-light-example.bin"
```

If debugging is needed, MCUXpresso can be used then for flashing the
Expand Down Expand Up @@ -461,9 +469,9 @@ doru@computer1:~/connectedhomeip$ : ./scripts/examples/gn_build_example.sh examp
Build OTA image and start the OTA Provider Application:

```
doru@computer1:~/connectedhomeip$ : ./src/app/ota_image_tool.py create -v 0xDEAD -p 0xBEEF -vn 1 -vs "1.0" -da sha256 chip-k32w061-light-example.bin chip-k32w061-light-example.ota
doru@computer1:~/connectedhomeip$ : ./src/app/ota_image_tool.py create -v 0xDEAD -p 0xBEEF -vn 1 -vs "1.0" -da sha256 chip-k32w0x-light-example.bin chip-k32w0x-light-example.ota
doru@computer1:~/connectedhomeip$ : rm -rf /tmp/chip_*
doru@computer1:~/connectedhomeip$ : ./out/ota-provider-app/chip-ota-provider-app -f chip-k32w061-light-example.ota
doru@computer1:~/connectedhomeip$ : ./out/ota-provider-app/chip-ota-provider-app -f chip-k32w0x-light-example.ota
```

Build Linux chip-tool:
Expand Down
7 changes: 7 additions & 0 deletions examples/lighting-app/nxp/k32w/k32w0/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern InitFunc __init_array_end;
/* needed for FreeRtos Heap 4 */
uint8_t __attribute__((section(".heap"))) ucHeap[HEAP_SIZE];

extern "C" void sched_enable();

extern "C" void main_task(void const * argument)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -85,6 +87,11 @@ extern "C" void main_task(void const * argument)
goto exit;
}

/* Enable the MAC scheduler after BLEManagerImpl::_Init() and V2MMAC_Enable().
* This is needed to register properly the active protocols.
*/
sched_enable();

err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
if (err != CHIP_NO_ERROR)
{
Expand Down
21 changes: 19 additions & 2 deletions examples/lock-app/nxp/k32w/k32w0/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import("${k32w0_sdk_build_root}/k32w0_executable.gni")
import("${k32w0_sdk_build_root}/k32w0_sdk.gni")

import("${chip_root}/src/crypto/crypto.gni")
import("${chip_root}/src/lib/core/core.gni")

if (chip_pw_tokenizer_logging) {
import("//build_overrides/pigweed.gni")
import("$dir_pw_tokenizer/database.gni")
}

assert(current_os == "freertos")

Expand Down Expand Up @@ -59,7 +65,7 @@ k32w0_sdk("sdk") {
}

k32w0_executable("lock_app") {
output_name = "chip-k32w061-lock-example"
output_name = "chip-k32w0x-lock-example"

sources = [
"${k32w0_platform_dir}/util/LEDWidget.cpp",
Expand Down Expand Up @@ -100,15 +106,26 @@ k32w0_executable("lock_app") {

output_dir = root_out_dir

ldscript = "${k32w0_platform_dir}/app/ldscripts/chip-k32w061-linker.ld"
ldscript = "${k32w0_platform_dir}/app/ldscripts/chip-k32w0x-linker.ld"

inputs = [ ldscript ]

ldflags = [ "-T" + rebase_path(ldscript, root_build_dir) ]
}

if (chip_pw_tokenizer_logging) {
pw_tokenizer_database("lock_app.database") {
database = "$root_build_dir/chip-k32w0x-lock-example-database.bin"
create = "binary"
deps = [ ":lock_app" ]
optional_paths = [ "$root_build_dir/chip-k32w0x-lock-example" ]
}
}
group("k32w0") {
deps = [ ":lock_app" ]
if (chip_pw_tokenizer_logging) {
deps += [ ":lock_app.database" ]
}
}

group("default") {
Expand Down
Loading

0 comments on commit 9b2c889

Please sign in to comment.