diff --git a/CHANGELOG.md b/CHANGELOG.md index ed2a1ca..2a31d38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,39 +1,63 @@ -# Changelog for Pelion Device Management Client reference example application +# Changelog for Pelion Device Management Client example application + +## Release 2.2.0 (25.02.2019) + +* Updated to Mbed OS 5.11.4. +* [Mbed OS] Client 2.2.0 has fixed the internal initialization of `ns_hal_init()`, which fixes the issue of double initialization of memory when using Mesh network stacks. + * Removed the application configurations of `mbed-client.event-loop-size` for most configurations. The application uses the default configuration defined in `mbed-client`, or from Mbed OS for Mesh network stacks. + * For Wi-Fi stacks, `mbed-client.event-loop-size` needs to be 2048. +* [Linux] Updated CMake minimum version to 3.5. +* [pal-platform] Deprecated the fullBuild option in build tools. +* [Mbed OS] By default, application configuration updated to use secure storage implementation through KVstore. + * K66F now uses internal flash for both storing client credentials and the update image. + * All other boards have been changed to use LittleFS instead of FAT file system by default. FAT file system is not power-loss resilient and should not be used in embedded devices. + * Old SOTP-ESFS based storage configuration files are still available in the `configs/legacy_storage` folder. + * `NUCLEO F411RE` board still uses SOTP-ESFS implementation, as non-TRNG boards are not yet supported in new KVStore-based storage. + * Legacy Wi-Fi configuration `wifi_esp8266_v4_legacy.json` introduced in the 2.1.1 release has been removed. +* Moved the network `init` call to `main()` and added network disconnect call to end of `main()`. +* Removed extern block evice reference from `platform-common`. +* Added `TESTS/PAL/test.py` script to help run PAL porting tests. +* Added basic Device Management acceptance end-to-end tests that use the [Icetea](https://github.com/ARMmbed/icetea) test framework. ## Release 2.1.1 (19.12.2018) + * Updated to Mbed OS 5.11.0. -* Modified WiFi configuration `configs/wifi_esp8266_v4.json` to support [new ESP8266 Wi-Fi chip](https://www.esp8266.com/wiki/doku.php?id=esp8266-module-family) having 2MB or more flash and [ESP8266 AT firmware](https://www.espressif.com/en/support/download/at?keys=) 1.7.0, with serial flow control (`UART0_CTS`, `UART0_RTS`) pins and reset pin (`EXT_RSTB`) connected. For production devices, we recommend that you upgrade your ESP8266 to this version and connect those control pins to corresponding pins on the target hardware. -* Previous WiFi ESP866 is supported via new `configs/wifi_esp8266_v4_legacy.json` file. +* Modified the Wi-Fi configuration `configs/wifi_esp8266_v4.json` to support the [new ESP8266 Wi-Fi chip](https://www.esp8266.com/wiki/doku.php?id=esp8266-module-family) with 2 MB or more flash and [ESP8266 AT firmware](https://www.espressif.com/en/support/download/at?keys=) 1.7.0, with serial flow control (`UART0_CTS`, `UART0_RTS`) pins and reset pin (`EXT_RSTB`) connected. For production devices, we recommend that you upgrade your ESP8266 to this version and connect the control pins to corresponding pins on the target hardware. +* Previous Wi-Fi ESP866 is supported in the new `configs/wifi_esp8266_v4_legacy.json` file. - **Note**: With legacy ESP8266 Wi-Fi with 1 MB flash, the minimum supported firmware version is now 1.6.2. **Without flow control and reset pin connected the device will eventually disconnect and fail to re-connect.** ESP8266 firmware has to be version 1.7.0 (or later) to enable flow control and only boards with 2 MB flash or more can take that firmware in. + **Note**: With legacy ESP8266 Wi-Fi with 1 MB flash, the minimum supported firmware version is now 1.6.2. **Without flow control and reset pin connected, the device will eventually disconnect and fail to re-connect.** ESP8266 firmware has to be version 1.7.0 (or later) to enable flow control and only boards with 2 MB flash or more can take that firmware in. * [Linux] Updated Mbed TLS to 2.15.1. ## Release 2.1.0 (11.12.2018) + * Updated to Mbed OS 5.10.3. ## Release 2.0.1 (12.10.2018) -* Application uses `wait_ms(int)` instead of `wait(float)`, this saves a bit on application size. -* [Mbed OS] Application will print NetworkInterface status over console. + +* The application uses `wait_ms(int)` instead of `wait(float)`. This saves a bit on the application size. +* [Mbed OS] The application prints NetworkInterface status over the console. * Updated to Mbed OS 5.10.1. ## Release 2.0.0 (26.09.2018) + * Updated to Mbed OS 5.10.0. * **Breaking changes** (Due to integration of storage and networking drivers to Mbed OS 5.10 and the introduction of new APIs, the application is not compatible with previous releases of Mbed OS). * Changed the application to use Mbed OS 5.10 network interfaces directly and removed the dependency to `easy-connect.lib`. * Changed the application to use Mbed OS 5.10 storage interfaces directly and removed the dependency to `storage-selector.lib`. * The example uses Mbed OS bootloader binaries and the new Mbed OS feature `FEATURE_BOOTLOADER`. This feature makes the `combine_bootloader_with_app.py` script obsolete. We have removed the obsolete script and old bootloader binaries from the application repository. * The bootloader is now automatically combined with the application binary at compile time: - * `mbed-cloud-client-example.bin` is the binary you need to flash on the development board. - * You can use `mbed-cloud-client-example_update.bin` for the firmware update as long as prequisites for firmware update has been fullfilled. (See the application tutorial). + * `mbed-cloud-client-example.bin` is the binary you need to flash on the development board. + * You can use `mbed-cloud-client-example_update.bin` for the firmware update as long as the prequisites for firmware update are fullfilled. (See the application tutorial). * Removed the legacy configuration file `configs/eth_v4_legacy.json` that was used for Mbed Cloud Client 1.2.6. -* Removed the `.autostart` configurations used by Online Compiler. +* Removed the `.autostart` configurations used by the online compiler. * Enabled serial buffer in all `.json` files. - * This improves the reliability of the connection with tracing enabled, for example Nucleo F429ZI had connectivity problems with UDP & traces enabled. + * This improves the reliability of the connection with tracing enabled, for example Nucleo F429ZI had connectivity problems with UDP and traces enabled. * Increased LWIP buffers for all STM-based targets to improve the stability of DTLS connection. -* Disabled Hardware acceleration for Ublox EVK Odin W2 and Nucleo F411RE. See Mbed OS [issue](https://github.com/ARMmbed/mbed-os/issues/6545). +* Disabled hardware acceleration for Ublox EVK Odin W2 and Nucleo F411RE. See Mbed OS [issue](https://github.com/ARMmbed/mbed-os/issues/6545). * [LINUX] Updated Mbed TLS to 2.13.1. ## Release 1.5.0 (11.9.2018) + * Added a hardcoded RoT injection when application is configured to use developer mode. This preserves the Device Management Client credentials even when SOTP is erased (for example due to reflashing of the application binary). * Updated to Mbed OS 5.9.6. * Updated easy-connect to v1.2.16. @@ -44,47 +68,54 @@ ## Release 1.4.0 (13.07.2018) + * Increased application main stack-size to 5120 to fix Stack overflow with ARMCC compiled binaries when tracing is enabled. -* Linux: Updated Mbedtls to 2.10.0 in pal-platform. +* Linux: Updated Mbed TLS to 2.10.0 in `pal-platform`. * Updated to Mbed OS 5.9.2. * Updated easy-connect to v1.2.12. * Updated storage-selector with support for SPI flash frequency, and Nucleo F411RE board. * Moved the initialization of `mbed_trace()` as the first step in the application initialization. This allows the printing of any early debug information from the PAL layer when debug tracing is enabled. * Added support for Nucleo F411RE board with Wifi-X-Nucleo shield. -* Increased the event loop thread stack size to 8192 bytes from a default value of 6144. This fixes stack overflows in some cases where crypto operations result in deep callstacks. +* Increased the event loop thread stack size to 8192 bytes from the default value of 6144. This fixes stack overflows in some cases where crypto operations result in deep callstacks. ## Release 1.3.3 (08.06.2018) + * Updated to Mbed OS 5.8.5. * The example application prints information about the validity of the stored Cloud credentials (including Connect and Update certificates). * Added a start-up delay of two seconds as a workaround for the SD driver initialization [issue](https://github.com/ARMmbed/sd-driver/issues/93). -* Fixed the heap corruption that took place with `print_m2mobject_stats()` when building the code with the MBED_HEAP_STATS_ENABLED flag. +* Fixed the heap corruption that took place with `print_m2mobject_stats()` when building the code with the `MBED_HEAP_STATS_ENABLED` flag. * Added the `-DMBED_STACK_STATS_ENABLED` flag. It enables printing information on the application thread stack usage. ## Release 1.3.2 (22.05.2018) + * Updated easy-connect to v1.2.9. * Updated to Mbed OS 5.8.4. * Added the `partition_mode` configuration. It is enabled by default and supposed to be used with a data storage, such as an SD card. -* Linux: Updated Mbedtls to 2.7.1 in pal-platform. +* Linux: Updated Mbed TLS to 2.7.1 in pal-platform. * Linux: Fixed CMake generation and performed generic cleanup in pal-platform scripts. #### Platform Adaptation Layer (PAL) + * Linux: Converted all timers to use signal-based timer (`SIGEV_SIGNAL`) instead of (`SIGEV_THREAD`). * This fixes the Valgrind warnings for possible memory leaks caused by LIBC's internal timer helper thread. - **Note**: If the client application is creating a pthread before instantiating MbedCloudClient, - it needs to block the PAL_TIMER_SIGNAL from it. Otherwise the thread may get an exception caused + + **Note**: If the client application is creating a pthread before instantiating MbedCloudClient, + it needs to block the `PAL_TIMER_SIGNAL` from it. Otherwise, the thread may get an exception caused by the default signal handler with a message such as "Process terminating with default action - of signal 34 (`SIGRT2`)". For a suggested way to handle this please see `mcc_platform_init()` in [here](https://github.com/ARMmbed/mbed-cloud-client-example/blob/master/source/platform/Linux/common_setup.c). + of signal 34 (`SIGRT2`)". For a suggested way to handle this, see `mcc_platform_init()` in [the code](https://github.com/ARMmbed/mbed-cloud-client-example/blob/master/source/platform/Linux/common_setup.c). ## Release 1.3.1.1 (27.04.2018) + * No changes. ## Release 1.3.1 (19.04.2018) + * Converted LED blinking callback from a blocking loop to event based tasklet. * Updated to Mbed OS 5.8.1. -* Rewrote platform-specific code to have common implementation which can be shared between other Cloud applications (source/platform/). - * enabled multipartition support for application. - * enabled LittleFS support. - * enabled autoformat/autopartition for storage (controllable via compile-time flags). +* Rewrote platform-specific code to have common implementation that can be shared between other Cloud applications (source/platform/). + * Enabled multipartition support for application. + * Enabled LittleFS support. + * Enabled autoformat/autopartition for storage (controllable via compile-time flags). ## Release 1.3.0 (27.3.2018) diff --git a/CMakeLists.txt b/CMakeLists.txt index df9b77c..54b7ace 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ INCLUDE(CMakeForceCompiler) # CROSS COMPILER SETTING -cmake_minimum_required (VERSION 2.8) +cmake_minimum_required (VERSION 3.5) SET(CMAKE_SYSTEM_NAME Generic) project(mbedCloudClientExample) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..93302cf --- /dev/null +++ b/Makefile @@ -0,0 +1,152 @@ +## ---------------------------------------------------------------------------- +## Copyright 2016-2018 ARM Ltd. +## +## SPDX-License-Identifier: Apache-2.0 +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## ---------------------------------------------------------------------------- + +## This makefile is only for SX OS platform + +## ----------------------------------------------------------- ## +## Don't touch the next line unless you know what you're doing.## +## ----------------------------------------------------------- ## +include ${SOFT_WORKDIR}/env/compilation/compilevars.mk + +export MBED_CLOUD_SERVICE = ${EXTERNAL_APP_FOLDER} + +# Name of the module +LOCAL_NAME := ${MBED_CLOUD_SERVICE} + +# list all modules APIs that are necessary to compile this module +LOCAL_API_DEPENDS := \ + ${LOCAL_NAME}/mbed-cloud-client \ + platform/service/posix \ + ${API_PLATFORM_DEPENDS} \ + +LOCAL_ADD_INCLUDE += . \ + ${LOCAL_NAME} \ + ${LOCAL_NAME}/source \ + ${LOCAL_NAME}/source/include \ + ${LOCAL_NAME}/source/platform/include \ + ${LOCAL_NAME}/mbed-cloud-client/factory-configurator-client/key-config-manager/source/include \ + ${LOCAL_NAME}/mbed-cloud-client/factory-configurator-client/key-config-manager/key-config-manager \ + ${LOCAL_NAME}/mbed-cloud-client/factory-configurator-client/factory-configurator-client/factory-configurator-client \ + ${LOCAL_NAME}/mbed-cloud-client/factory-configurator-client/fcc-output-info-handler/fcc-output-info-handler \ + ${LOCAL_NAME}/mbed-cloud-client/factory-configurator-client/fcc-bundle-handler/fcc-bundle-handler \ + ${LOCAL_NAME}/mbed-cloud-client/factory-configurator-client/storage/storage \ + ${LOCAL_NAME}/mbed-cloud-client/factory-configurator-client/mbed-client-esfs/source/include \ + ${LOCAL_NAME}/mbed-cloud-client/factory-configurator-client/crypto-service/crypto-service \ + ${LOCAL_NAME}/mbed-cloud-client/factory-configurator-client/mbed-trace-helper/mbed-trace-helper \ + ${LOCAL_NAME}/mbed-cloud-client \ + ${LOCAL_NAME}/mbed-cloud-client/mbed-client \ + ${LOCAL_NAME}/mbed-cloud-client/mbed-client/mbed-client \ + ${LOCAL_NAME}/mbed-cloud-client/mbed-trace \ + ${LOCAL_NAME}/mbed-cloud-client/source \ + ${LOCAL_NAME}/mbed-cloud-client/ns-hal-pal \ + ${LOCAL_NAME}/mbed-cloud-client/nanostack-libservice/mbed-client-libservice \ + ${LOCAL_NAME}/mbed-cloud-client/mbed-client-pal/Source/PAL-Impl/Services-API \ + ${LOCAL_NAME}/mbed-cloud-client/mbed-client-pal/Configs/pal_config \ + ${LOCAL_NAME}/mbed-cloud-client/mbed-client-pal/Configs/pal_config/SXOS \ + ${LOCAL_NAME}/mbed-cloud-client/mbed-client/mbed-client-c \ + ${LOCAL_NAME}/mbed-cloud-client/mbed-coap/mbed-coap \ + ${LOCAL_NAME}/mbed-cloud-client/nanostack-libservice \ + ${LOCAL_NAME}/mbed-cloud-client/sal-stack-nanostack-eventloop \ + ${LOCAL_NAME}/mbed-cloud-client/certificate-enrollment-client/certificate-enrollment-client \ + ${LOCAL_NAME}/mbed-cloud-client/update-client-hub \ + ${LOCAL_NAME}/mbed-cloud-client/update-client-hub/modules/common \ + +LOCAL_EXPORT_FLAG += __SXOS__ + +LOCAL_EXPORT_FLAG += "'PAL_USER_DEFINED_CONFIGURATION=\"SXOS/sxos_sotp.h\"'" +LOCAL_EXPORT_FLAG += "'MBED_CLIENT_USER_CONFIG_FILE=\"mbed_cloud_client_user_config.h\"'" +LOCAL_EXPORT_FLAG += "'MBED_CLOUD_CLIENT_USER_CONFIG_FILE=\"mbed_cloud_client_user_config.h\"'" + +LOCAL_EXPORT_FLAG += "'MBED_CONF_MBED_CLIENT_EVENT_LOOP_SIZE=12000'" +LOCAL_EXPORT_FLAG += "PAL_SIMULATOR_FLASH_OVER_FILE_SYSTEM=1" +LOCAL_EXPORT_FLAG += "MBED_CONF_MBED_TRACE_ENABLE" +LOCAL_EXPORT_FLAG += "MBED_CONF_APP_CLOUD_MODE=1" +LOCAL_EXPORT_FLAG += "MBED_CONF_APP_DEVELOPER_MODE=1" + +# not yet +LOCAL_EXPORT_FLAG += "MBED_CONF_MBED_CLOUD_CLIENT_DISABLE_CERTIFICATE_ENROLLMENT=1" + +# Disable code using STL as it not available on SDK +LOCAL_EXPORT_FLAG += "MBED_CLOUD_CLIENT_STL_API=0" +LOCAL_EXPORT_FLAG += "MBED_CLOUD_CLIENT_STD_NAMESPACE_POLLUTION=0" + +# Compile the sub-modules, except when the "service" must be used as a library. +# list all the modules that need to be compiled prior to using this module + +LOCAL_MODULE_DEPENDS += \ + ${LOCAL_NAME}/mbed-cloud-client \ + +# One can compile and run the PAL unit tests instead of example-app +# by "PAL_UNIT_TESTING=1 ctmake CT_PRODUCT=20180930 dbmerge -j" command. +# +# By default, the example app itself is built. By having the PAL tests in +# same makefile, one can easily be sure the configuration is the same and +# the changes in PAL during porting can be tested by its own unit tests and +# then running the example itself. +ifndef PAL_UNIT_TESTING + +# this enables the mbed_cloud_application_entrypoint(void) from main.cpp +LOCAL_EXPORT_FLAG += MBED_CLOUD_APPLICATION_NONSTANDARD_ENTRYPOINT + +else +# the PAL tests have mbed_cloud_application_entrypoint(void) too, which is enabled +# from pal_tests_nonstandard_entrypoint.c by PAL_UNIT_TESTING_NONSTANDARD_ENTRYPOINT. +LOCAL_EXPORT_FLAG += "PAL_UNIT_TESTING_NONSTANDARD_ENTRYPOINT" + +# build the tests +LOCAL_MODULE_DEPENDS += ${LOCAL_NAME}/mbed-cloud-client/mbed-client-pal/Test + +# These are needed for building PAL SOTP tests. Note: the flag is renamed on yet-to-be-merged +# version of esfs without backwards compatibility, so we need to have both here for some time. +LOCAL_EXPORT_FLAG += "SOTP_TESTING" +LOCAL_EXPORT_FLAG += "RBP_TESTING" +endif + +# Generate the revision (version) file automatically during the make process. +AUTO_GEN_REVISION_HEADER := no + +# This is a top-level module +IS_TOP_LEVEL := yes + +# Generates the CoolWatcher headers automatically. +AUTO_XMD2H ?= no + +# code is not in one "src/" directory as SDK expects by default +USE_DIFFERENT_SOURCE_LAYOUT := yes +USE_DIFFERENT_SOURCE_LAYOUT_ARM := yes + +C_SRC := ${wildcard *.c} +C++_SRC := ${wildcard *.cpp} + +C_SRC += ${wildcard source/*.c} +C++_SRC += ${wildcard source/*.cpp} + +C_SRC += ${wildcard source/platform/*.c} +C++_SRC += ${wildcard source/platform/*.cpp} + +C_SRC += ${wildcard source/platform/SXOS/*.c} +C++_SRC += ${wildcard source/platform/SXOS/*.cpp} + +C_SRC += ${wildcard mbed-cloud-client/mbed-trace/source/*.c} +C_SRC += ${wildcard mbed-cloud-client/nanostack-libservice/source/libip6string/*.c} + + +## ------------------------------------- ## +## Do Not touch below this line ## +## ------------------------------------- ## +include ${SOFT_WORKDIR}/env/compilation/compilerules.mk diff --git a/TESTS/E2E/README.md b/TESTS/E2E/README.md new file mode 100644 index 0000000..80ce4f7 --- /dev/null +++ b/TESTS/E2E/README.md @@ -0,0 +1,84 @@ +# Device Management E2E testing + +Device Management E2E tests are platform-agnostic. They verify that a target platform can reliably perform basic critical operations. +There are two different test sets: +- The tests are designed for verifying the basic functionality of a target platform. +- Advanced tests for more complex use cases (for example `device_update` test case). + +## Requirements + +1. [IceTea](https://github.com/ARMmbed/icetea) v1.0.0 or later. +1. [Mbed Cloud SDK for Python](https://cloud.mbed.com/docs/current/mbed-cloud-sdk-python/index.html) v2.0.0 or later. + +## Installation + +``` +pip install icetea mbed-cloud-sdk +``` + +## Basic usage + +1. Register your device to Device Management. For examples see the [tutorials](https://cloud.mbed.com/docs/current/connecting/device-management-client-tutorials.html). +1. Input your [device_id](https://cloud.mbed.com/docs/current/connecting/device-identity.html) to `TESTS/E2E/pelion.tc_cfg`. +1. Input your [API key](https://cloud.mbed.com/docs/current/integrate-web-app/api-keys.html) to `TESTS/E2E/pelion.tc_cfg`. + +### Running test-suite + +``` +icetea --suite basic_tests.json --suitedir TESTS/E2E/ --tcdir ./TESTS/E2E/ --tc_cfg TESTS/E2E/pelion.tc_cfg +``` +If you have prepared a manifest (See below notes for `device_update` testcase), you can run the full suite with: +``` +icetea --suite full_tests.json --suitedir TESTS/E2E/ --tcdir ./TESTS/E2E/ --tc_cfg TESTS/E2E/pelion.tc_cfg +``` + + +### Running single test +``` +icetea --tc basic_get --tcdir ./TESTS/E2E/ --tc_cfg TESTS/E2E/pelion.tc_cfg +``` + +## Current tests + +| Testname | Main functions | Notes | +| ---------------- | ------------------------------------------ | --------------------------------------| +| `register` | Verify that device is registered. | | +| `get` | Verify that device responds to GET. | Uses OMA resource `/3/0/0` | +| `put` | Verify that device responds to PUT. | Uses custom resource `/3201/0/5853` | +| `post` | Verify that device responds to POST. | Uses custom resource `/3201/0/5850` | +| `observation` | Verify that device can send otifications. | Uses custom resource `/3201/0/5853` | +| `deregister` | Verify that device can deregister . | Uses custom resource `/5000/0/1` | +| `device_update` | Performs firmware update | This testcase verifies that the endpoint can perform a firmware update. For this testcase, you need to manually generate an update image and a manifest.| + +### Executing `device_update` test case + +The test case does not automatically generate an update image or generate a manifest. We recommend that you read [Update documentation](https://cloud.mbed.com/docs/current/updating-firmware/index.html). + +You need to do the following: + +1. Compile a new update image. +1. Upload the image to Device Management. +1. Generate a manifest for the update image. +1. Upload the manifest to Device Management. +1. Add the `` to `TESTS/E2E/pelion.tc_cfg`. + +#### Example for executing the `device_update` test case on Mbed OS platform + +To prepare the latest Device Management Client example on Mbed OS for testing, run the following commands: + +1. `mbed dm init -d arm.com --model-name example-app --force -q` +1. `mbed compile -t -m ` +1. `mbed dm update prepare` + +The last command uploads the `mbed-cloud-client-example_update.bin`, generates a new manifest and uploads the manifest to Device Management. Record the resulting Manifest ID and add it to `TESTS/E2E/pelion.tc_cfg`. + +``` +[INFO] 2018-12-12 15:06:42 - manifesttool.prepare - Manifest ID: +``` + +To execute the test, use the following command: +``` +icetea --tc device_update --tcdir ./TESTS/E2E/ --tc_cfg TESTS/E2E/pelion.tc_cfg +``` + + **Note**: After each successful update you need to generate a new manifest for a new firmware update test. Otherwise the test will pass without actually performing any device side updates. The update campaign ends automatically because the manifest has already been applied to the device. diff --git a/TESTS/E2E/__init__.py b/TESTS/E2E/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/TESTS/E2E/basic_tests.json b/TESTS/E2E/basic_tests.json new file mode 100644 index 0000000..a98dadb --- /dev/null +++ b/TESTS/E2E/basic_tests.json @@ -0,0 +1,10 @@ +{ + "testcases": [ + {"name" : "register"}, + {"name" : "get"}, + {"name" : "put"}, + {"name" : "post"}, + {"name" : "observation"}, + {"name" : "deregister"} + ] +} diff --git a/TESTS/E2E/deregister.py b/TESTS/E2E/deregister.py new file mode 100644 index 0000000..18cf07b --- /dev/null +++ b/TESTS/E2E/deregister.py @@ -0,0 +1,53 @@ +""" +Copyright 2019 ARM Limited +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +# pylint: disable=missing-docstring,useless-super-delegation +# pylint: disable=line-too-long,method-hidden,relative-import + +from icetea_lib.bench import TestStepFail +from mbed_cloud.exceptions import CloudApiException +from pelion_helper import PelionBase + + +class Testcase(PelionBase): + def __init__(self): + PelionBase.__init__(self, + name="deregister", + title="Example application can deregister", + status="released", + type="acceptance", + component=["mbed_cloud_client_example"]) + + def setup(self): + super(Testcase, self).setup() + + def case(self): + resource_path = '/5000/0/1' + # Deregister device via POST (/5000/0/1) + self.logger.info("Deregister via POST %s", resource_path) + try: + self.connect_api.execute_resource(device_id=self.device_id, + resource_path=resource_path, + timeout=self.restTimeout) + except CloudApiException as error: + raise TestStepFail("POST request failed with %d and msg %s" % (error.status, error.message)) + + # Verify client is deregistered + self.logger.info("POST done") + + self.verify_registration("deregistered") + + def teardown(self): + self.connect_api.stop_notifications() diff --git a/TESTS/E2E/device_update.py b/TESTS/E2E/device_update.py new file mode 100644 index 0000000..51c70cd --- /dev/null +++ b/TESTS/E2E/device_update.py @@ -0,0 +1,64 @@ +""" +Copyright 2019 ARM Limited +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +# pylint: disable=missing-docstring +# pylint: disable=line-too-long,method-hidden,relative-import + +import time +from icetea_lib.bench import TestStepFail +from pelion_helper import PelionBase + + +class Testcase(PelionBase): + def __init__(self): + PelionBase.__init__(self, + name="device_update", + title="Example application can perform firmware update", + status="released", + type="acceptance", + component=["mbed_cloud_client_example"]) + def setup(self): + super(Testcase, self).setup() + super(Testcase, self).setup_update() + + def case(self): + # Create filter for update campaign generation, with automatic startup + update_filter = self.prepare_campaign_filter(state="scheduled") + # Start the update campaign + campaign_id = self.post_campaign(update_filter) + # Wait for the campaign to reach autostopped state + timeout = 600 + _endtime = time.time() + timeout + + while True: + self.delay(10) + result = self.check_campaign_state(campaign_id) + # Update campaign has stopped + if result[0] == "autostopped": + break + + if time.time() > _endtime: + self.logger.error("Campaign in state: %s, Device in state: %s", result[0], result[1]) + raise TestStepFail("Campaign did not finish in %d" % timeout) + + # Check for final state of the device + final_result = self.check_campaign_state(campaign_id) + if final_result[1] != "deployed": + raise TestStepFail("Device in %s state, expected deployed" % result[1]) + + self.logger.info("Firmware update finished successfully") + + def teardown(self): + self.connect_api.stop_notifications() diff --git a/TESTS/E2E/full_tests.json b/TESTS/E2E/full_tests.json new file mode 100644 index 0000000..47bae4d --- /dev/null +++ b/TESTS/E2E/full_tests.json @@ -0,0 +1,11 @@ +{ + "testcases": [ + {"name" : "register"}, + {"name" : "get"}, + {"name" : "put"}, + {"name" : "post"}, + {"name" : "observation"}, + {"name" : "device_update"}, + {"name" : "deregister"} + ] +} diff --git a/TESTS/E2E/get.py b/TESTS/E2E/get.py new file mode 100644 index 0000000..26f3a88 --- /dev/null +++ b/TESTS/E2E/get.py @@ -0,0 +1,49 @@ +""" +Copyright 2019 ARM Limited +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +# pylint: disable=missing-docstring,useless-super-delegation +# pylint: disable=line-too-long,method-hidden,relative-import + +from icetea_lib.bench import TestStepFail +from mbed_cloud.exceptions import CloudApiException +from pelion_helper import PelionBase + + +class Testcase(PelionBase): + def __init__(self): + PelionBase.__init__(self, + name="get", + title="Example application can perform basic CoAP operation (GET)", + status="released", + type="acceptance", + component=["mbed_cloud_client_example"]) + + def setup(self): + super(Testcase, self).setup() + + def case(self): + resource_path = '/3/0/0' + self.logger.info("Testing GET %s", resource_path) + try: + resource_manufacturer = self.connect_api.get_resource_value(device_id=self.device_id, + resource_path=resource_path, + timeout=self.restTimeout) + except CloudApiException as error: + raise TestStepFail("GET request failed with %d and msg %s" % (error.status, error.message)) + + self.logger.info("Received value %s for %s", resource_manufacturer, resource_path) + + def teardown(self): + self.connect_api.stop_notifications() diff --git a/TESTS/E2E/observation.py b/TESTS/E2E/observation.py new file mode 100644 index 0000000..bde84d1 --- /dev/null +++ b/TESTS/E2E/observation.py @@ -0,0 +1,110 @@ +""" +Copyright 2019 ARM Limited +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +# pylint: disable=missing-docstring,useless-super-delegation +# pylint: disable=line-too-long,method-hidden,relative-import + +import time +from icetea_lib.bench import TestStepFail +from mbed_cloud.exceptions import CloudApiException +from pelion_helper import PelionBase + + +class Testcase(PelionBase): + def __init__(self): + PelionBase.__init__(self, + name="observation", + title="Example application can respond to resource subscription)", + status="released", + type="acceptance", + component=["mbed_cloud_client_example"]) + + def setup(self): + super(Testcase, self).setup() + + def case(self): + # Test resource subscription + resource_path = '/3201/0/5853' + + # 1) Add initial resource value + self.logger.info("PUT %s with value %s", resource_path, self.pattern_value1) + try: + self.connect_api.set_resource_value(device_id=self.device_id, + resource_path=resource_path, + resource_value=self.pattern_value1, + timeout=self.restTimeout) + except CloudApiException as error: + raise TestStepFail("PUT request failed with %d and msg %s" % (error.status, error.message)) + + # Create resource subscription for custom resource (/3201/0/5853) + self.logger.info("Testing subscription for %s", resource_path) + self.connect_api.start_notifications() + + try: + self.connect_api.add_resource_subscription_async(device_id=self.device_id, + resource_path=resource_path, + callback_fn=self._callback_fn) + except CloudApiException as error: + raise TestStepFail("Subscription request failed with %d and msg %s" % (error.status, error.message)) + + # 2) Update resource value + self.logger.info("PUT %s with value %s", resource_path, self.pattern_value2) + try: + self.connect_api.set_resource_value(device_id=self.device_id, + resource_path=resource_path, + resource_value=self.pattern_value2, + timeout=self.restTimeout) + except CloudApiException as error: + raise TestStepFail("PUT request failed with %d and msg %s" % (error.status, error.message)) + + self.logger.info("Waiting for resource notification") + notif_timeout = time.time() + self.restTimeout + + # 3) Wait until we receive some value or timeout + while time.time() < notif_timeout: + if self.notified_value != "": + break + + if self.notified_value != self.pattern_value2: + self.logger.error("Web-application received %s as notification, expected %s", self.notified_value, self.pattern_value2) + raise TestStepFail("Incorrect/No notification received") + else: + self.logger.info("Web-application received %s as notification.", self.notified_value) + + # 4) Remove subscription + try: + self.connect_api.delete_resource_subscription(device_id=self.device_id) + except CloudApiException as error: + raise TestStepFail("Subscription removal failed with %d and msg %s" % (error.status, error.message)) + + # 5) Update resource value to trigger reset from server + # This is needed to clean the client subscription status for any follow-up tests + self.logger.info("PUT %s with value %s", resource_path, self.pattern_value3) + try: + self.connect_api.set_resource_value(device_id=self.device_id, + resource_path=resource_path, + resource_value=self.pattern_value3, + timeout=self.restTimeout) + except CloudApiException as error: + raise TestStepFail("PUT request failed with %d and msg %s" % (error.status, error.message)) + + def teardown(self): + # Remove subscription + try: + self.connect_api.delete_resource_subscription(device_id=self.device_id) + except CloudApiException as error: + raise TestStepFail("Subscription removal failed with %d and msg %s" % (error.status, error.message)) + + self.connect_api.stop_notifications() diff --git a/TESTS/E2E/pelion.tc_cfg b/TESTS/E2E/pelion.tc_cfg new file mode 100644 index 0000000..7b872ea --- /dev/null +++ b/TESTS/E2E/pelion.tc_cfg @@ -0,0 +1,6 @@ +{ + "device_id" : "your-device-id", + "api_key" : "your-api-key", + "host" : "https://api.us-east-1.mbedcloud.com", + "manifest_id": "your-manifest-id" +} diff --git a/TESTS/E2E/pelion_helper.py b/TESTS/E2E/pelion_helper.py new file mode 100644 index 0000000..cb641aa --- /dev/null +++ b/TESTS/E2E/pelion_helper.py @@ -0,0 +1,146 @@ +""" +Copyright 2019 ARM Limited +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +# pylint: disable=missing-docstring,too-many-instance-attributes +# pylint: disable=line-too-long,method-hidden + +import json +import uuid +import requests +from mbed_cloud import AccountManagementAPI +from mbed_cloud import ConnectAPI +from mbed_cloud import DeviceDirectoryAPI +from mbed_cloud import UpdateAPI +from icetea_lib.bench import Bench +from icetea_lib.bench import TestStepFail + + +class PelionBase(Bench): + """ + Base class containing common implementation shared by tests + """ + + def __init__(self, **kwargs): + Bench.__init__(self, **kwargs) + self.test_config = None + self.device_id = None + self.manifest_id = None + self.account_api = None + self.connect_api = None + self.device_api = None + self.update_api = None + self.rest_headers = None + self.rest_address = None + self.pattern_value1 = "1000:1000:1000:1000" + self.pattern_value2 = "2000:1000:2000:1000" + self.pattern_value3 = "3000:1000:3000:1000" + self.notified_value = "" + + def setup(self): + self.device_id = self.config.get("device_id") + api_key = self.config.get("api_key") + host = self.config.get("host") + self.test_config = {"api_key": api_key, "host": host} + self.account_api = AccountManagementAPI(self.test_config) + self.connect_api = ConnectAPI(self.test_config) + self.device_api = DeviceDirectoryAPI(self.test_config) + + # Additional parameters for handling REST requests without SDK + self.rest_headers = {'Authorization': 'Bearer ' + self.config.get("api_key")} + self.rest_address = self.config.get("host") + + # Init delay due to internal usage of PULL notification in SDK. Notications might be lost between + # tests. + # TODO: Remove workaround after limitation in SDK has been fixed. + self.delay(5) + + def setup_update(self): + self.manifest_id = self.config.get("manifest_id") + self.update_api = UpdateAPI(self.test_config) + + def _callback_fn(self, device_id, path, value): + self.logger.info("Notification for %s received: %r value: %r", device_id, path, value) + self.notified_value = value + + def verify_registration(self, expected_state): + self.logger.info("Verify device to in state %s", expected_state) + device = self.device_api.get_device(self.device_id) + if device is None: + raise TestStepFail("device_id %s does not exist/is not listed in Device Directory" % self.device_id) + else: + if device.state == expected_state: + self.logger.info("Endpoint %s is in state: %s", self.device_id, expected_state) + else: + raise TestStepFail("Endpoint %s is in state %s, expected %s" % (self.device_id, device.state, expected_state)) + + def prepare_campaign_filter(self, state): + # Create filter for the update campaign. Here we only update one endpoint. + payload = {} + payload["device_filter"] = "id=" + self.device_id + payload["root_manifest_id"] = self.manifest_id + payload["name"] = str(uuid.uuid4()) + payload["state"] = state + return payload + + ## Function for starting a update campaign + ## TODO: Replace with Python SDK implementation + def post_campaign(self, payload): + req_address = self.rest_address + '/v3/update-campaigns' + res = requests.post(req_address, json=payload, headers=self.rest_headers) + if res.status_code == 409: + # Endpoint can be targeted by only one active campaign. The older campaign must be deleted/stopped. + raise TestStepFail("Campaign already exists for device %s" % self.device_id) + elif res.status_code != 201: + raise TestStepFail("Campaign creation failed with %d" % res.status_code) + + data = res.json() + campaign_id = data["id"] + return campaign_id + + ## Function for checking firmware update status from Cloud + ## TODO: Replace with Python SDK implementation + def check_campaign_state(self, campaign_id): + results = [] + base_url = self.rest_address + "/v3/update-campaigns" + campaign_url = base_url + "/" + campaign_id + metadata_url = campaign_url + "/" + "campaign-device-metadata" + + # Short wait until campaign has been initialized properly. + self.delay(5) + + # Fetch basic campaign information + response = requests.get(campaign_url, headers=self.rest_headers) + if response.status_code != 200: + raise TestStepFail("Get Campaign state returned %d" % response.status_code) + + resp = json.loads(response.content) + results.append(resp["state"]) + + # Fetch campaign metadata information + response = requests.get(metadata_url, headers=self.rest_headers) + if response.status_code != 200: + raise TestStepFail("Get Campaign metadata returned %d" % response.status_code) + + resp = json.loads(response.content) + if 'data' in resp and resp['data'] > 0: + meta_data = resp['data'] + device_state = meta_data[0]['deployment_state'] + results.append(device_state) + else: + raise TestStepFail("No metadata for %d" % self.device_id) + + return results + + restTimeout = 60 diff --git a/TESTS/E2E/post.py b/TESTS/E2E/post.py new file mode 100644 index 0000000..b5446ec --- /dev/null +++ b/TESTS/E2E/post.py @@ -0,0 +1,51 @@ +""" +Copyright 2019 ARM Limited +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +# pylint: disable=missing-docstring,useless-super-delegation +# pylint: disable=line-too-long,method-hidden,relative-import + +from icetea_lib.bench import TestStepFail +from mbed_cloud.exceptions import CloudApiException +from pelion_helper import PelionBase + + +class Testcase(PelionBase): + def __init__(self): + PelionBase.__init__(self, + name="post", + title="Example application can perform basic CoAP operation (POST)", + status="released", + type="acceptance", + component=["mbed_cloud_client_example"]) + + def setup(self): + super(Testcase, self).setup() + + def case(self): + resource_path = '/3201/0/5850' + # Test basic POST operation + # Post/Execute at custom resource (/3201/0/5850) + self.logger.info("Testing POST %s", resource_path) + try: + self.connect_api.execute_resource(device_id=self.device_id, + resource_path=resource_path, + timeout=self.restTimeout) + except CloudApiException as error: + raise TestStepFail("POST request failed with %d and msg %s" % (error.status, error.message)) + + self.logger.info("POST done") + + def teardown(self): + self.connect_api.stop_notifications() diff --git a/TESTS/E2E/put.py b/TESTS/E2E/put.py new file mode 100644 index 0000000..7299bb3 --- /dev/null +++ b/TESTS/E2E/put.py @@ -0,0 +1,63 @@ +""" +Copyright 2019 ARM Limited +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +# pylint: disable=missing-docstring,useless-super-delegation +# pylint: disable=line-too-long,method-hidden,relative-import + +from icetea_lib.bench import TestStepFail +from mbed_cloud.exceptions import CloudApiException +from pelion_helper import PelionBase + + +class Testcase(PelionBase): + def __init__(self): + PelionBase.__init__(self, + name="put", + title="Example application can perform basic CoAP operation (PUT)", + status="released", + type="acceptance", + component=["mbed_cloud_client_example"]) + + def setup(self): + super(Testcase, self).setup() + + def case(self): + resource_path = '/3201/0/5853' + # Write new value to custom resource (/3201/0/5853) + self.logger.info("Testing PUT %s with value %s", self.pattern_value1, resource_path) + try: + self.connect_api.set_resource_value(device_id=self.device_id, + resource_path=resource_path, + resource_value=self.pattern_value1, + timeout=self.restTimeout) + except CloudApiException as error: + raise TestStepFail("PUT request failed with %d and msg %s" % (error.status, error.message)) + + # Read and verify that new value is in effect + try: + pattern_value_new = self.connect_api.get_resource_value(device_id=self.device_id, + resource_path=resource_path, + timeout=self.restTimeout) + except CloudApiException as error: + raise TestStepFail("GET request failed with %d and msg %s" % (error.status, error.message)) + + self.logger.info("Read back value %s for %s", pattern_value_new, resource_path) + + if self.pattern_value1 != pattern_value_new: + raise TestStepFail("Pattern %s written does not match the pattern %s read back" % (self.pattern_value1, + pattern_value_new)) + + def teardown(self): + self.connect_api.stop_notifications() diff --git a/TESTS/E2E/register.py b/TESTS/E2E/register.py new file mode 100644 index 0000000..0b1545b --- /dev/null +++ b/TESTS/E2E/register.py @@ -0,0 +1,37 @@ +""" +Copyright 2019 ARM Limited +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +# pylint: disable=missing-docstring,useless-super-delegation +# pylint: disable=method-hidden,relative-import + +from pelion_helper import PelionBase + + +class Testcase(PelionBase): + def __init__(self): + PelionBase.__init__(self, + name="register", + title="Example application can perform basic CoAP operation (GET)", + status="released", + type="acceptance", + component=["mbed_cloud_client_example"]) + def setup(self): + super(Testcase, self).setup() + + def case(self): + self.verify_registration("registered") + + def teardown(self): + self.connect_api.stop_notifications() diff --git a/TESTS/PAL/templates/suite.json b/TESTS/PAL/templates/suite.json new file mode 100644 index 0000000..d5be54a --- /dev/null +++ b/TESTS/PAL/templates/suite.json @@ -0,0 +1,3 @@ +{ + "testcases": [] +} diff --git a/TESTS/PAL/templates/testcase.json b/TESTS/PAL/templates/testcase.json new file mode 100644 index 0000000..6dc2137 --- /dev/null +++ b/TESTS/PAL/templates/testcase.json @@ -0,0 +1,16 @@ +{ + "name": "pal_test_runner", + "config": { + "requirements": { + "duts": { + "*": { + "platform_name": null, + "type": null, + "application": { + "bin": null + } + } + } + } + } +} \ No newline at end of file diff --git a/TESTS/PAL/test.py b/TESTS/PAL/test.py new file mode 100755 index 0000000..6c19cce --- /dev/null +++ b/TESTS/PAL/test.py @@ -0,0 +1,277 @@ +#!/usr/bin/env python +""" +Copyright 2019 ARM Limited +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import os +import re +import json +import logging +import argparse + + +class SuiteBuilder(object): + """ + SuiteBuilder class contains logic to search + test binaries and create icetea test suites. + """ + + # pylint: disable=too-many-instance-attributes + # All the path attributes have a logical meaning to them + # and use case for error reporting. + + def __init__(self): + self.build_data = None + self.pal_test_binaries = None + self.logger = logging.getLogger(__name__) + self.root_path = os.path.dirname(__file__) + self.suite_dir = os.path.join(self.root_path, "cache") + self.suite_path = os.path.join(self.suite_dir, "dynamic.json") + self.template_path = os.path.join(self.root_path, "templates") + self.testcase_path = os.path.join(self.root_path, "testcases") + self.suite_template_path = os.path.join( + self.template_path, "suite.json") + self.testcase_template_path = os.path.join( + self.template_path, "testcase.json") + + def _find_mbed_build_data(self, path): + """ + Finds latest mbed OS build_data.json. + :param path: this is the path to search build_data.json + """ + # Find every "build_data.json" + build_data_files = [] + build_data_filename = "build_data.json" + for root, _, files in os.walk(path): + if build_data_filename in files: + build_data_file = os.path.join(root, build_data_filename) + self.logger.debug( + "found build_data.json from \"%s\"", build_data_file) + build_data_files.append(build_data_file) + + # Choose latest "build_data.json" + build_data_file = max(build_data_files, key=os.path.getmtime) + + # Read "build_data.json" + with open(build_data_file) as fid: + self.build_data = json.load(fid) + + def find_mbed_pal_tests(self, path): + """ + Find mbed OS test case binaries. + This is achieved by parsing build_data.json + :param path: this is the path to search build_data.json + """ + # Find build_data.json + self._find_mbed_build_data(path) + + # PAL test ID checker + re_pal_test = re.compile( + r"MBED-CLOUD-CLIENT-MBED-CLIENT-PAL-TEST-TESTS-.*(?TEST\((?P.*?), (?P.*?)\)\<\/\*\*\*UnityTest\*\*\*\>") # noqa: E501 # pylint: disable=line-too-long + re_unity_result = re.compile( + r".*\<\*\*\*UnityResult\*\*\*\>(?P.*?)\<\/\*\*\*UnityResult\*\*\*\>") # noqa: E501 # pylint: disable=line-too-long + + test_output = "" + test_active = False + test_results = ResultList() + for line in dut.traces: + line = line.strip() + + # Activate test output logging + match = re_unity_test.match(line) + if match: + test_active = True + test_output = "" + unity_name = match.group("test") + unity_suite = match.group("suite") + self.logger.info("parsing %s.%s", unity_suite, unity_name) + + # Log test output + if test_active: + test_output += line + "\n" + + # Check if test is over + match = re_unity_result.match(line) + if match and test_active: + unity_result = match.group("result") + + # Create icetea Result() + test_result = Result( + { + "testcase": unity_suite + "." + unity_name, + "stdout": test_output, + "reason": line if unity_result == "FAIL" else "" + }) + test_result.build_result_metadata({"toolchain": unity_name}) + # Would need to do runtime analysis to get duration + test_result.set_verdict(unity_result, 0, 0.0) + test_results.append(test_result) + test_active = False + self.logger.info("finished %s", unity_name) + return test_results + + def print_dut_log_to_trace(self): + """ + Workaround to print all DUT log without all icetea logs. + """ + for line in self.duts[0].traces[self.workaround_dut_lineno:]: + self.logger.info(line) + self.workaround_dut_lineno += 1 + + def check_execution_errors(self): + """ + Checks that there are no execution errors during PAL Unity tests. + """ + errors = ["MbedOS Fault Handler", "CMSIS-RTOS error"] + for error in errors: + if self.verify_trace(0, error, False): + raise TestStepError(error) + + def wait_trace(self, stop_match_str, duration): + """ + Waits a given trace for the given time. + :param stop_match_str: Stop waiting when this string is found + :param duration: How long to wait for a string + """ + # Wait tests to pass (set timeout on suite level) + wait_start = time.time() + while (time.time()-wait_start) < duration: + if self.verify_trace(0, stop_match_str, False): + return + self.logger.info("waiting \"%s\"...%.2fs", + stop_match_str, duration-(time.time()-wait_start)) + self.print_dut_log_to_trace() + self.check_execution_errors() + time.sleep(1) + raise TestStepTimeout( + "Didn't get \"{}\" in {}".format(stop_match_str, duration)) + + def fail_testcase(self, error): + """ + Workaround that overwrites icetea's result value in order to + store the test binary name in the results. Without this workaround + the testcase name would be "pal_test_runner" which is not descriptive. + :param error: Python error that failed the test case + """ + # Overwrite test case result + self._results = ResultList() + self._results.append( + Result({ + "testcase": (self.config["requirements"] + ["duts"]["*"]["application"]["bin"]), + "reason": repr(error), + "verdict": "FAIL" + }) + ) + + def setup(self): # pylint: disable=method-hidden + """ + Pre-test activities. + """ + pass + + def case(self): + """ + Testcase activities. + """ + try: + # Wait test case + self.wait_trace("PAL_TEST_START", 60) + self.wait_trace("PAL_TEST_END", 600) + except (TestStepError, TestStepTimeout) as error: + self.fail_testcase(error) + return + + # Overwrite previously written test case result. + # If no errors during execution, parse errors. + # Don't put this into teardown() as it is executed even if + # the case raises TestStepFail. This then causes test to "pass" + # even with stack overflow on DUT + self._results = self.parse_unity_result(self.duts[0]) + + def teardown(self): # pylint: disable=method-hidden + """ + Post-test activities + """ + pass diff --git a/configs/eth_v4.json b/configs/eth_v4.json index 9b00c90..a73d50f 100644 --- a/configs/eth_v4.json +++ b/configs/eth_v4.json @@ -1,46 +1,93 @@ { "macros": [ - "ARM_UC_USE_PAL_BLOCKDEVICE=1", - "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + "ARM_UC_USE_PAL_BLOCKDEVICE=1" ], "target_overrides": { "*": { - "target.features_add" : ["BOOTLOADER", "STORAGE"], - "target.components_add" : ["SD"], - "platform.stdio-baud-rate" : 115200, - "platform.stdio-convert-newlines" : true, - "platform.stdio-buffered-serial" : true, - "mbed-client.event-loop-size" : 1024, + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-cloud-client.external-sst-support" : 1, "nanostack-hal.event_loop_thread_stack_size": 8192, - "update-client.storage-address" : "(1024*1024*64)", - "update-client.storage-size" : "(1024*1024*2)", - "update-client.storage-locations" : 1, - "mbed-trace.enable": null + "update-client.storage-locations" : 1, + "mbed-trace.enable" : null }, "STM_EMAC": { "lwip.pbuf-pool-size" : 16, "lwip.mem-size" : 12500 }, "K64F": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x00007188", - "update-client.application-details" : "(40*1024)" + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-k64f-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(32*1024)", + "storage_filesystem.rbp_internal_size" : "(8*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD" }, "K66F": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x00007188", - "update-client.application-details" : "(40*1024)" + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-k66f-internal_flash-no_rot-v4.0.0.bin", + "target.header_offset" : "0x8000", + "target.app_offset" : "0x8400", + "update-client.bootloader-details" : "0x4D58", + "update-client.application-details" : "(32*1024)", + "update-client.storage-address" : "(MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS+MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE)", + "update-client.storage-size" : "(1024*1024-MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE)", + "update-client.storage-page" : 8, + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP", + "storage_tdb_internal.internal_base_address": "(1024*1024)", + "storage_tdb_internal.internal_size" : "(96*1024)", + "storage.storage_type" : "TDB_INTERNAL" }, "NUCLEO_F429ZI": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x080078CC", - "update-client.application-details" : "(0x08000000+64*1024)" + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-nucleo_f429zi-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x080078CC", + "update-client.application-details" : "(0x08000000+64*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(0x08000000+32*1024)", + "storage_filesystem.rbp_internal_size" : "(32*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD", + "sd.SPI_MOSI" : "PC_12", + "sd.SPI_MISO" : "PC_11", + "sd.SPI_CLK" : "PC_10", + "sd.SPI_CS" : "PA_15" }, "UBLOX_EVK_ODIN_W2": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x08007300", - "update-client.application-details" : "(0x08000000+64*1024)", - "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-ublox_evk_odin_w2-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x08007300", + "update-client.application-details" : "(0x08000000+64*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(0x08000000+32*1024)", + "storage_filesystem.rbp_internal_size" : "(32*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD", + "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] } }, "config": { diff --git a/configs/eth_v6.json b/configs/eth_v6.json index fefc465..d49656b 100644 --- a/configs/eth_v6.json +++ b/configs/eth_v6.json @@ -1,48 +1,95 @@ { "macros": [ - "ARM_UC_USE_PAL_BLOCKDEVICE=1", - "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + "ARM_UC_USE_PAL_BLOCKDEVICE=1" ], "target_overrides": { "*": { - "target.features_add" : ["BOOTLOADER", "STORAGE"], - "target.components_add" : ["SD"], - "platform.stdio-baud-rate" : 115200, - "platform.stdio-convert-newlines" : true, - "platform.stdio-buffered-serial" : true, - "mbed-client.event-loop-size" : 1024, + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-cloud-client.external-sst-support" : 1, "nanostack-hal.event_loop_thread_stack_size": 8192, - "update-client.storage-address" : "(1024*1024*64)", - "update-client.storage-size" : "(1024*1024*2)", - "update-client.storage-locations" : 1, - "mbed-trace.enable": null, - "lwip.ipv4-enabled": false, - "lwip.ipv6-enabled": true + "update-client.storage-locations" : 1, + "mbed-trace.enable" : null, + "lwip.ipv4-enabled" : false, + "lwip.ipv6-enabled" : true }, "STM_EMAC": { - "lwip.pbuf-pool-size" : 16, - "lwip.mem-size" : 12500 + "lwip.pbuf-pool-size" : 16, + "lwip.mem-size" : 12500 }, "K64F": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x00007188", - "update-client.application-details" : "(40*1024)" + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-k64f-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(32*1024)", + "storage_filesystem.rbp_internal_size" : "(8*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD" }, "K66F": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x00007188", - "update-client.application-details" : "(40*1024)" + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-k66f-internal_flash-no_rot-v4.0.0.bin", + "target.header_offset" : "0x8000", + "target.app_offset" : "0x8400", + "update-client.bootloader-details" : "0x4D58", + "update-client.application-details" : "(32*1024)", + "update-client.storage-address" : "(MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS+MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE)", + "update-client.storage-size" : "(1024*1024-MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE)", + "update-client.storage-page" : 8, + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP", + "storage.storage_type" : "TDB_INTERNAL", + "storage_tdb_internal.internal_base_address": "(1024*1024)", + "storage_tdb_internal.internal_size" : "(96*1024)" }, "NUCLEO_F429ZI": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x080078CC", - "update-client.application-details" : "(0x08000000+64*1024)" + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-nucleo_f429zi-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x080078CC", + "update-client.application-details" : "(0x08000000+64*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(0x08000000+32*1024)", + "storage_filesystem.rbp_internal_size" : "(32*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD", + "sd.SPI_MOSI" : "PC_12", + "sd.SPI_MISO" : "PC_11", + "sd.SPI_CLK" : "PC_10", + "sd.SPI_CS" : "PA_15" }, "UBLOX_EVK_ODIN_W2": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x08007300", - "update-client.application-details" : "(0x08000000+64*1024)", - "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-ublox_evk_odin_w2-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x08007300", + "update-client.application-details" : "(0x08000000+64*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(0x08000000+32*1024)", + "storage_filesystem.rbp_internal_size" : "(32*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD", + "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] } }, "config": { diff --git a/configs/legacy_storage/eth_v4.json b/configs/legacy_storage/eth_v4.json new file mode 100644 index 0000000..aca560c --- /dev/null +++ b/configs/legacy_storage/eth_v4.json @@ -0,0 +1,87 @@ +{ + "macros": [ + "ARM_UC_USE_PAL_BLOCKDEVICE=1", + "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + ], + "target_overrides": { + "*": { + "client_app.pal-user-defined-configuration" : "\"pal_config_legacy_MbedOS.h\"", + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "target.components_add" : ["SD"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-client.event-loop-size" : 1024, + "nanostack-hal.event_loop_thread_stack_size": 8192, + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "(1024*1024*2)", + "update-client.storage-locations" : 1, + "mbed-trace.enable": null + }, + "STM_EMAC": { + "lwip.pbuf-pool-size" : 16, + "lwip.mem-size" : 12500 + }, + "K64F": { + "target.network-default-interface-type" : "ETHERNET", + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(32*1024)", + "client_app.sotp-section-1-size" : "( 4*1024)", + "client_app.sotp-section-2-address" : "(36*1024)", + "client_app.sotp-section-2-size" : "( 4*1024)" + }, + "K66F": { + "target.network-default-interface-type" : "ETHERNET", + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(32*1024)", + "client_app.sotp-section-1-size" : "( 4*1024)", + "client_app.sotp-section-2-address" : "(36*1024)", + "client_app.sotp-section-2-size" : "( 4*1024)" + }, + "NUCLEO_F429ZI": { + "target.network-default-interface-type" : "ETHERNET", + "update-client.bootloader-details" : "0x080078CC", + "update-client.application-details" : "(0x08000000+64*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(0x08000000+32*1024)", + "client_app.sotp-section-1-size" : "(16*1024)", + "client_app.sotp-section-2-address" : "(0x08000000+48*1024)", + "client_app.sotp-section-2-size" : "(16*1024)", + "sd.SPI_MOSI" : "PC_12", + "sd.SPI_MISO" : "PC_11", + "sd.SPI_CLK" : "PC_10", + "sd.SPI_CS" : "PA_15" + }, + "UBLOX_EVK_ODIN_W2": { + "target.network-default-interface-type" : "ETHERNET", + "update-client.bootloader-details" : "0x08007300", + "update-client.application-details" : "(0x08000000+64*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(0x08000000+32*1024)", + "client_app.sotp-section-1-size" : "(16*1024)", + "client_app.sotp-section-2-address" : "(0x08000000+48*1024)", + "client_app.sotp-section-2-size" : "(16*1024)", + "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] + } + }, + "config": { + "developer-mode": { + "help" : "Enable Developer mode to skip Factory enrollment", + "options" : [null, 1], + "value" : 1 + }, + "button-pinname": { + "help" : "PinName for button.", + "value" : "BUTTON1" + }, + "led-pinname" : { + "help" : "PinName for led, which is attached to led blink resource.", + "value" : "LED_RED" + } + } +} diff --git a/configs/legacy_storage/eth_v6.json b/configs/legacy_storage/eth_v6.json new file mode 100644 index 0000000..e8b7bef --- /dev/null +++ b/configs/legacy_storage/eth_v6.json @@ -0,0 +1,89 @@ +{ + "macros": [ + "ARM_UC_USE_PAL_BLOCKDEVICE=1", + "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + ], + "target_overrides": { + "*": { + "client_app.pal-user-defined-configuration" : "\"pal_config_legacy_MbedOS.h\"", + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "target.components_add" : ["SD"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-client.event-loop-size" : 1024, + "nanostack-hal.event_loop_thread_stack_size": 8192, + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "(1024*1024*2)", + "update-client.storage-locations" : 1, + "mbed-trace.enable": null, + "lwip.ipv4-enabled": false, + "lwip.ipv6-enabled": true + }, + "STM_EMAC": { + "lwip.pbuf-pool-size" : 16, + "lwip.mem-size" : 12500 + }, + "K64F": { + "target.network-default-interface-type" : "ETHERNET", + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(32*1024)", + "client_app.sotp-section-1-size" : "( 4*1024)", + "client_app.sotp-section-2-address" : "(36*1024)", + "client_app.sotp-section-2-size" : "( 4*1024)" + }, + "K66F": { + "target.network-default-interface-type" : "ETHERNET", + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(32*1024)", + "client_app.sotp-section-1-size" : "( 4*1024)", + "client_app.sotp-section-2-address" : "(36*1024)", + "client_app.sotp-section-2-size" : "( 4*1024)" + }, + "NUCLEO_F429ZI": { + "target.network-default-interface-type" : "ETHERNET", + "update-client.bootloader-details" : "0x080078CC", + "update-client.application-details" : "(0x08000000+64*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(0x08000000+32*1024)", + "client_app.sotp-section-1-size" : "(16*1024)", + "client_app.sotp-section-2-address" : "(0x08000000+48*1024)", + "client_app.sotp-section-2-size" : "(16*1024)", + "sd.SPI_MOSI" : "PC_12", + "sd.SPI_MISO" : "PC_11", + "sd.SPI_CLK" : "PC_10", + "sd.SPI_CS" : "PA_15" + }, + "UBLOX_EVK_ODIN_W2": { + "target.network-default-interface-type" : "ETHERNET", + "update-client.bootloader-details" : "0x08007300", + "update-client.application-details" : "(0x08000000+64*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(0x08000000+32*1024)", + "client_app.sotp-section-1-size" : "(16*1024)", + "client_app.sotp-section-2-address" : "(0x08000000+48*1024)", + "client_app.sotp-section-2-size" : "(16*1024)", + "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] + } + }, + "config": { + "developer-mode": { + "help" : "Enable Developer mode to skip Factory enrollment", + "options" : [null, 1], + "value" : 1 + }, + "button-pinname": { + "help" : "PinName for button.", + "value" : "BUTTON1" + }, + "led-pinname" : { + "help" : "PinName for led, which is attached to led blink resource.", + "value" : "LED_RED" + } + } +} diff --git a/configs/legacy_storage/mesh_6lowpan.json b/configs/legacy_storage/mesh_6lowpan.json new file mode 100644 index 0000000..96c9d8c --- /dev/null +++ b/configs/legacy_storage/mesh_6lowpan.json @@ -0,0 +1,78 @@ +{ + "macros": [ + "ARM_UC_USE_PAL_BLOCKDEVICE=1", + "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + ], + "target_overrides": { + "*": { + "client_app.pal-user-defined-configuration" : "\"pal_config_legacy_MbedOS.h\"", + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "target.components_add" : ["SD"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-client.event-loop-size" : 32768, + "mbed-client.reconnection-count" : 6, + "mbed-client-pal.pal-dns-api-version": 2, + "mbed-client.sn-coap-blockwise-max-time-data-stored": 120, + "client_app.pal_dtls_peer_min_timeout": "10000", + "nanostack-hal.event_loop_thread_stack_size": 8192, + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "(1024*1024*2)", + "update-client.storage-locations" : 1, + "mbed-trace.enable": null, + "mbed-mesh-api.6lowpan-nd-channel" : 12, + "mbed-mesh-api.6lowpan-nd-panid-filter" : "0xFFFF", + "mbed-mesh-api.6lowpan-nd-security-mode": "NONE", + "nsapi.default-mesh-type" : "LOWPAN", + "nanostack.configuration" : "lowpan_router", + "atmel-rf.provide-default" : true, + "target.device_has_add" : ["802_15_4_PHY"] + }, + "STM_EMAC": { + "lwip.pbuf-pool-size" : 16, + "lwip.mem-size" : 12500 + }, + "K64F": { + "target.network-default-interface-type" : "MESH", + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(32*1024)", + "client_app.sotp-section-1-size" : "( 4*1024)", + "client_app.sotp-section-2-address" : "(36*1024)", + "client_app.sotp-section-2-size" : "( 4*1024)" + }, + "NUCLEO_F429ZI": { + "target.network-default-interface-type" : "MESH", + "update-client.bootloader-details" : "0x080078CC", + "update-client.application-details" : "(0x08000000+64*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(0x08000000+32*1024)", + "client_app.sotp-section-1-size" : "(16*1024)", + "client_app.sotp-section-2-address" : "(0x08000000+48*1024)", + "client_app.sotp-section-2-size" : "(16*1024)", + "target.macros_add": ["ATMEL_SPI_MOSI=PB_5"], + "sd.SPI_MOSI" : "PC_12", + "sd.SPI_MISO" : "PC_11", + "sd.SPI_CLK" : "PC_10", + "sd.SPI_CS" : "PA_15" + } + }, + "config": { + "developer-mode": { + "help" : "Enable Developer mode to skip Factory enrollment", + "options" : [null, 1], + "value" : 1 + }, + "button-pinname": { + "help" : "PinName for button.", + "value" : "BUTTON1" + }, + "led-pinname" : { + "help" : "PinName for led, which is attached to led blink resource.", + "value" : "LED_RED" + } + } +} diff --git a/configs/legacy_storage/mesh_thread.json b/configs/legacy_storage/mesh_thread.json new file mode 100644 index 0000000..305da83 --- /dev/null +++ b/configs/legacy_storage/mesh_thread.json @@ -0,0 +1,80 @@ +{ + "macros": [ + "ARM_UC_USE_PAL_BLOCKDEVICE=1", + "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE", + "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED", + "MBEDTLS_ECJPAKE_C" + ], + "target_overrides": { + "*": { + "client_app.pal-user-defined-configuration" : "\"pal_config_legacy_MbedOS.h\"", + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "target.components_add" : ["SD"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-client.event-loop-size" : 32768, + "mbed-client.reconnection-count" : 6, + "mbed-client-pal.pal-dns-api-version": 2, + "mbed-client.sn-coap-blockwise-max-time-data-stored": 120, + "client_app.pal_dtls_peer_min_timeout": "10000", + "nanostack-hal.event_loop_thread_stack_size": 8192, + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "(1024*1024*2)", + "update-client.storage-locations" : 1, + "mbed-trace.enable": null, + "mbed-mesh-api.thread-config-channel" : 22, + "mbed-mesh-api.thread-config-panid" : "0x0700", + + "nsapi.default-mesh-type" : "THREAD", + "nanostack.configuration" : "thread_router", + "atmel-rf.provide-default" : true, + "target.device_has_add" : ["802_15_4_PHY"] + }, + "STM_EMAC": { + "lwip.pbuf-pool-size" : 16, + "lwip.mem-size" : 12500 + }, + "K64F": { + "target.network-default-interface-type" : "MESH", + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(32*1024)", + "client_app.sotp-section-1-size" : "( 4*1024)", + "client_app.sotp-section-2-address" : "(36*1024)", + "client_app.sotp-section-2-size" : "( 4*1024)" + }, + "NUCLEO_F429ZI": { + "target.network-default-interface-type" : "MESH", + "update-client.bootloader-details" : "0x080078CC", + "update-client.application-details" : "(0x08000000+64*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(0x08000000+32*1024)", + "client_app.sotp-section-1-size" : "(16*1024)", + "client_app.sotp-section-2-address" : "(0x08000000+48*1024)", + "client_app.sotp-section-2-size" : "(16*1024)", + "target.macros_add": ["ATMEL_SPI_MOSI=PB_5"], + "sd.SPI_MOSI" : "PC_12", + "sd.SPI_MISO" : "PC_11", + "sd.SPI_CLK" : "PC_10", + "sd.SPI_CS" : "PA_15" + } + }, + "config": { + "developer-mode": { + "help" : "Enable Developer mode to skip Factory enrollment", + "options" : [null, 1], + "value" : 1 + }, + "button-pinname": { + "help" : "PinName for button.", + "value" : "BUTTON1" + }, + "led-pinname" : { + "help" : "PinName for led, which is attached to led blink resource.", + "value" : "LED_RED" + } + } +} diff --git a/configs/legacy_storage/wifi_esp8266_v4.json b/configs/legacy_storage/wifi_esp8266_v4.json new file mode 100644 index 0000000..a99b8fa --- /dev/null +++ b/configs/legacy_storage/wifi_esp8266_v4.json @@ -0,0 +1,60 @@ +{ + "macros": [ + "ARM_UC_USE_PAL_BLOCKDEVICE=1", + "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + ], + "target_overrides": { + "*": { + "client_app.pal-user-defined-configuration" : "\"pal_config_legacy_MbedOS.h\"", + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "target.components_add" : ["SD"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-client.event-loop-size" : 2048, + "nanostack-hal.event_loop_thread_stack_size": 8192, + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "update-client.storage-locations" : 1, + "mbed-trace.enable": null, + "drivers.uart-serial-rxbuf-size" : 1024, + "drivers.uart-serial-txbuf-size" : 1024, + "events.shared-stacksize" : 2048, + "esp8266.rx" : "PTC3", + "esp8266.tx" : "PTC4", + "esp8266.rst" : "D8", + "esp8266.rts" : "PTC1", + "esp8266.cts" : "PTC2", + "esp8266.provide-default" : true, + "nsapi.default-wifi-security" : "WPA_WPA2", + "nsapi.default-wifi-ssid" : "\"SSID\"", + "nsapi.default-wifi-password" : "\"Password\"" + }, + "K64F": { + "target.network-default-interface-type" : "WIFI", + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(32*1024)", + "client_app.sotp-section-1-size" : "( 4*1024)", + "client_app.sotp-section-2-address" : "(36*1024)", + "client_app.sotp-section-2-size" : "( 4*1024)" + } + }, + "config": { + "developer-mode": { + "help" : "Enable Developer mode to skip Factory enrollment", + "options" : [null, 1], + "value" : 1 + }, + "button-pinname": { + "help" : "PinName for button.", + "value" : "BUTTON1" + }, + "led-pinname" : { + "help" : "PinName for led, which is attached to led blink resource.", + "value" : "LED_RED" + } + } +} diff --git a/configs/wifi_esp8266_v4_legacy.json b/configs/legacy_storage/wifi_odin_v4.json similarity index 68% rename from configs/wifi_esp8266_v4_legacy.json rename to configs/legacy_storage/wifi_odin_v4.json index 346c858..259b18f 100644 --- a/configs/wifi_esp8266_v4_legacy.json +++ b/configs/legacy_storage/wifi_odin_v4.json @@ -5,24 +5,19 @@ ], "target_overrides": { "*": { + "client_app.pal-user-defined-configuration" : "\"pal_config_legacy_MbedOS.h\"", "target.features_add" : ["BOOTLOADER", "STORAGE"], "target.components_add" : ["SD"], "platform.stdio-baud-rate" : 115200, "platform.stdio-convert-newlines" : true, "platform.stdio-buffered-serial" : true, - "mbed-client.event-loop-size" : 1024, + "platform.stdio-flush-at-exit" : true, + "mbed-client.event-loop-size" : 2048, "nanostack-hal.event_loop_thread_stack_size": 8192, "update-client.storage-address" : "(1024*1024*64)", "update-client.storage-size" : "(1024*1024*2)", "update-client.storage-locations" : 1, "mbed-trace.enable": null, - "drivers.uart-serial-rxbuf-size" : 1024, - "drivers.uart-serial-txbuf-size" : 1024, - "events.shared-stacksize" : 2048, - "esp8266.rx" : "D0", - "esp8266.tx" : "D1", - "esp8266.socket-bufsize" : 32768, - "esp8266.provide-default" : true, "nsapi.default-wifi-security" : "WPA_WPA2", "nsapi.default-wifi-ssid" : "\"SSID\"", "nsapi.default-wifi-password" : "\"Password\"" @@ -31,15 +26,17 @@ "lwip.pbuf-pool-size" : 16, "lwip.mem-size" : 12500 }, - "K64F": { + "UBLOX_EVK_ODIN_W2": { "target.network-default-interface-type" : "WIFI", - "update-client.bootloader-details" : "0x00007188", - "update-client.application-details" : "(40*1024)" - }, - "NUCLEO_F429ZI": { - "target.network-default-interface-type" : "WIFI", - "update-client.bootloader-details" : "0x080078CC", - "update-client.application-details" : "(0x08000000+64*1024)" + "update-client.bootloader-details" : "0x08007300", + "update-client.application-details" : "(0x08000000+64*1024)", + "mbed-cloud-client.external-sst-support": null, + "client_app.sotp-section-1-address" : "(0x08000000+32*1024)", + "client_app.sotp-section-1-size" : "(16*1024)", + "client_app.sotp-section-2-address" : "(0x08000000+48*1024)", + "client_app.sotp-section-2-size" : "(16*1024)", + "target.lse_available" : 0, + "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] } }, "config": { diff --git a/configs/mesh_6lowpan.json b/configs/mesh_6lowpan.json index 7efb293..d98815f 100644 --- a/configs/mesh_6lowpan.json +++ b/configs/mesh_6lowpan.json @@ -1,47 +1,46 @@ { "macros": [ - "ARM_UC_USE_PAL_BLOCKDEVICE=1", - "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + "ARM_UC_USE_PAL_BLOCKDEVICE=1" ], "target_overrides": { "*": { - "target.features_add" : ["BOOTLOADER", "STORAGE"], - "target.components_add" : ["SD"], - "platform.stdio-baud-rate" : 115200, - "platform.stdio-convert-newlines" : true, - "platform.stdio-buffered-serial" : true, - "mbed-client.event-loop-size" : 32768, - "mbed-client.reconnection-count" : 6, - "mbed-client-pal.pal-dns-api-version": 2, + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-client.reconnection-count" : 6, + "mbed-client-pal.pal-dns-api-version" : 2, "mbed-client.sn-coap-blockwise-max-time-data-stored": 120, - "client_app.pal_dtls_peer_min_timeout": "10000", + "mbed-cloud-client.external-sst-support" : 1, + "client_app.pal_dtls_peer_min_timeout" : "10000", "nanostack-hal.event_loop_thread_stack_size": 8192, - "update-client.storage-address" : "(1024*1024*64)", - "update-client.storage-size" : "(1024*1024*2)", - "update-client.storage-locations" : 1, - "mbed-trace.enable": null, - "mbed-mesh-api.6lowpan-nd-channel" : 12, - "mbed-mesh-api.6lowpan-nd-panid-filter" : "0xFFFF", - "mbed-mesh-api.6lowpan-nd-security-mode": "NONE", - "nsapi.default-mesh-type" : "LOWPAN", - "nanostack.configuration" : "lowpan_router", - "atmel-rf.provide-default" : true, - "target.device_has_add" : ["802_15_4_PHY"] - }, - "STM_EMAC": { - "lwip.pbuf-pool-size" : 16, - "lwip.mem-size" : 12500 + "update-client.storage-locations" : 1, + "mbed-trace.enable" : null, + "mbed-mesh-api.6lowpan-nd-channel" : 12, + "mbed-mesh-api.6lowpan-nd-panid-filter" : "0xFFFF", + "mbed-mesh-api.6lowpan-nd-security-mode" : "NONE", + "nsapi.default-mesh-type" : "LOWPAN", + "nanostack.configuration" : "lowpan_router", + "atmel-rf.provide-default" : true, + "target.device_has_add" : ["802_15_4_PHY"] }, "K64F": { - "target.network-default-interface-type" : "MESH", - "update-client.bootloader-details" : "0x00007188", - "update-client.application-details" : "(40*1024)" - }, - "NUCLEO_F429ZI": { - "target.network-default-interface-type" : "MESH", - "update-client.bootloader-details" : "0x080078CC", - "update-client.application-details" : "(0x08000000+64*1024)", - "target.macros_add": ["ATMEL_SPI_MOSI=PB_5"] + "target.network-default-interface-type" : "MESH", + "target.bootloader_img" : "tools/mbed-bootloader-k64f-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(32*1024)", + "storage_filesystem.rbp_internal_size" : "(8*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD" } }, "config": { diff --git a/configs/mesh_thread.json b/configs/mesh_thread.json index 26d56a6..81b2dc2 100644 --- a/configs/mesh_thread.json +++ b/configs/mesh_thread.json @@ -1,49 +1,47 @@ { "macros": [ "ARM_UC_USE_PAL_BLOCKDEVICE=1", - "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE", "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED", "MBEDTLS_ECJPAKE_C" ], "target_overrides": { "*": { - "target.features_add" : ["BOOTLOADER", "STORAGE"], - "target.components_add" : ["SD"], - "platform.stdio-baud-rate" : 115200, - "platform.stdio-convert-newlines" : true, - "platform.stdio-buffered-serial" : true, - "mbed-client.event-loop-size" : 32768, - "mbed-client.reconnection-count" : 6, - "mbed-client-pal.pal-dns-api-version": 2, + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-client.reconnection-count" : 6, + "mbed-client-pal.pal-dns-api-version" : 2, "mbed-client.sn-coap-blockwise-max-time-data-stored": 120, - "client_app.pal_dtls_peer_min_timeout": "10000", + "mbed-cloud-client.external-sst-support" : 1, + "client_app.pal_dtls_peer_min_timeout" : "10000", "nanostack-hal.event_loop_thread_stack_size": 8192, - "update-client.storage-address" : "(1024*1024*64)", - "update-client.storage-size" : "(1024*1024*2)", - "update-client.storage-locations" : 1, - "mbed-trace.enable": null, - "mbed-mesh-api.thread-config-channel" : 22, - "mbed-mesh-api.thread-config-panid" : "0x0700", - - "nsapi.default-mesh-type" : "THREAD", - "nanostack.configuration" : "thread_router", - "atmel-rf.provide-default" : true, - "target.device_has_add" : ["802_15_4_PHY"] - }, - "STM_EMAC": { - "lwip.pbuf-pool-size" : 16, - "lwip.mem-size" : 12500 + "update-client.storage-locations" : 1, + "mbed-trace.enable" : null, + "mbed-mesh-api.thread-config-channel" : 22, + "mbed-mesh-api.thread-config-panid" : "0x0700", + "nsapi.default-mesh-type" : "THREAD", + "nanostack.configuration" : "thread_router", + "atmel-rf.provide-default" : true, + "target.device_has_add" : ["802_15_4_PHY"] }, "K64F": { - "target.network-default-interface-type" : "MESH", - "update-client.bootloader-details" : "0x00007188", - "update-client.application-details" : "(40*1024)" - }, - "NUCLEO_F429ZI": { - "target.network-default-interface-type" : "MESH", - "update-client.bootloader-details" : "0x080078CC", - "update-client.application-details" : "(0x08000000+64*1024)", - "target.macros_add": ["ATMEL_SPI_MOSI=PB_5"] + "target.network-default-interface-type" : "MESH", + "target.bootloader_img" : "tools/mbed-bootloader-k64f-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(32*1024)", + "storage_filesystem.rbp_internal_size" : "(8*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD" } }, "config": { diff --git a/configs/wifi_esp8266_v4.json b/configs/wifi_esp8266_v4.json index 58f27e5..8863c24 100644 --- a/configs/wifi_esp8266_v4.json +++ b/configs/wifi_esp8266_v4.json @@ -1,38 +1,48 @@ { "macros": [ - "ARM_UC_USE_PAL_BLOCKDEVICE=1", - "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + "ARM_UC_USE_PAL_BLOCKDEVICE=1" ], "target_overrides": { "*": { - "target.features_add" : ["BOOTLOADER", "STORAGE"], - "target.components_add" : ["SD"], - "platform.stdio-baud-rate" : 115200, - "platform.stdio-convert-newlines" : true, - "platform.stdio-buffered-serial" : true, - "mbed-client.event-loop-size" : 1024, + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-client.event-loop-size" : 2048, + "mbed-cloud-client.external-sst-support" : 1, "nanostack-hal.event_loop_thread_stack_size": 8192, - "update-client.storage-address" : "(1024*1024*64)", - "update-client.storage-size" : "(1024*1024*2)", - "update-client.storage-locations" : 1, - "mbed-trace.enable": null, - "drivers.uart-serial-rxbuf-size" : 1024, - "drivers.uart-serial-txbuf-size" : 1024, - "events.shared-stacksize" : 2048, - "esp8266.rx" : "PTC3", - "esp8266.tx" : "PTC4", - "esp8266.rst" : "D8", - "esp8266.rts" : "PTC1", - "esp8266.cts" : "PTC2", - "esp8266.provide-default" : true, - "nsapi.default-wifi-security" : "WPA_WPA2", - "nsapi.default-wifi-ssid" : "\"SSID\"", - "nsapi.default-wifi-password" : "\"Password\"" + "update-client.storage-locations" : 1, + "mbed-trace.enable" : null, + "drivers.uart-serial-rxbuf-size" : 1024, + "drivers.uart-serial-txbuf-size" : 1024, + "events.shared-stacksize" : 2048, + "esp8266.rx" : "PTC3", + "esp8266.tx" : "PTC4", + "esp8266.rst" : "D8", + "esp8266.rts" : "PTC1", + "esp8266.cts" : "PTC2", + "esp8266.provide-default" : true, + "nsapi.default-wifi-security" : "WPA_WPA2", + "nsapi.default-wifi-ssid" : "\"SSID\"", + "nsapi.default-wifi-password" : "\"Password\"" }, "K64F": { - "target.network-default-interface-type" : "WIFI", - "update-client.bootloader-details" : "0x00007188", - "update-client.application-details" : "(40*1024)" + "target.network-default-interface-type" : "WIFI", + "target.bootloader_img" : "tools/mbed-bootloader-k64f-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(32*1024)", + "storage_filesystem.rbp_internal_size" : "(8*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD" } }, "config": { diff --git a/configs/wifi_f411re_v4.json b/configs/wifi_f411re_v4.json index c32274f..323d34d 100644 --- a/configs/wifi_f411re_v4.json +++ b/configs/wifi_f411re_v4.json @@ -1,42 +1,53 @@ { "macros": [ "ARM_UC_USE_PAL_BLOCKDEVICE=1", - "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + "MBED_CLOUD_CLIENT_STL_API=0", + "MBED_CLOUD_CLIENT_STD_NAMESPACE_POLLUTION=1" ], "target_overrides": { "*": { - "target.features_add" : ["BOOTLOADER", "STORAGE"], - "target.components_add" : ["SD"], - "platform.stdio-baud-rate" : 115200, - "platform.stdio-convert-newlines" : true, - "platform.stdio-buffered-serial" : true, - "mbed-client.event-loop-size" : 1024, + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-client.event-loop-size" : 2048, + "mbed-cloud-client.external-sst-support" : null, "nanostack-hal.event_loop_thread_stack_size": 8192, - "update-client.storage-address" : "(1024*1024*64)", - "update-client.storage-size" : "(1024*1024*2)", - "update-client.storage-locations" : 1, - "mbed-trace.enable": null, - "nsapi.default-wifi-security" : "WPA_WPA2", - "nsapi.default-wifi-ssid" : "\"SSID\"", - "nsapi.default-wifi-password" : "\"Password\"" - }, - "STM_EMAC": { - "lwip.pbuf-pool-size" : 16, - "lwip.mem-size" : 12500 + "update-client.storage-locations" : 1, + "mbed-trace.enable" : null, + "nsapi.default-wifi-security" : "WPA_WPA2", + "nsapi.default-wifi-ssid" : "\"SSID\"", + "nsapi.default-wifi-password" : "\"Password\"" }, "NUCLEO_F411RE": { - "client_app.mbedtls-user-config-file" : "\"mbedTLSConfig_mbedOS_SW_TRNG.h\"", - "client_app.pal-user-defined-configuration": "\"sotp_non_trng_config_MbedOS.h\"", - "target.network-default-interface-type" : "WIFI", - "update-client.bootloader-details" : "(0x08000000+30*1024)", - "update-client.application-details" : "(0x08000000+64*1024)", - "drivers.uart-serial-rxbuf-size" : 1024, - "drivers.uart-serial-txbuf-size" : 1024, - "events.shared-stacksize" : 2048, - "idw0xx1.provide-default": true, - "idw0xx1.tx": "PA_9", - "idw0xx1.rx": "PA_10", - "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] + "target.components_add" : ["SD"], + "client_app.mbedtls-user-config-file" : "\"mbedTLSConfig_mbedOS_SW_TRNG.h\"", + "client_app.pal-user-defined-configuration" : "\"pal_config_legacy_non_trng_MbedOS.h\"", + "target.network-default-interface-type" : "WIFI", + "update-client.bootloader-details" : "(0x08000000+30*1024)", + "update-client.application-details" : "(0x08000000+64*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "mbed-cloud-client.external-sst-support" : null, + "client_app.sotp-section-1-address" : "(0x08000000+32*1024)", + "client_app.sotp-section-1-size" : "(16*1024)", + "client_app.sotp-section-2-address" : "(0x08000000+48*1024)", + "client_app.sotp-section-2-size" : "(16*1024)", + "drivers.uart-serial-rxbuf-size" : 1024, + "drivers.uart-serial-txbuf-size" : 1024, + "events.shared-stacksize" : 2048, + "idw0xx1.provide-default" : true, + "idw0xx1.tx" : "PA_9", + "idw0xx1.rx" : "PA_10", + "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"], + "target.macros_add" : ["DISABLE_ERROR_DESCRIPTION"], + "mbed-client-pal.pal-dns-api-version" : 0, + "sd.SPI_MOSI" : "PC_3", + "sd.SPI_MISO" : "PC_2", + "sd.SPI_CLK" : "PC_7", + "sd.SPI_CS" : "PB_9" } }, "config": { diff --git a/configs/wifi_odin_v4.json b/configs/wifi_odin_v4.json index 5ae9859..a973678 100644 --- a/configs/wifi_odin_v4.json +++ b/configs/wifi_odin_v4.json @@ -1,35 +1,45 @@ { "macros": [ - "ARM_UC_USE_PAL_BLOCKDEVICE=1", - "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + "ARM_UC_USE_PAL_BLOCKDEVICE=1" ], "target_overrides": { "*": { - "target.features_add" : ["BOOTLOADER", "STORAGE"], - "target.components_add" : ["SD"], - "platform.stdio-baud-rate" : 115200, - "platform.stdio-convert-newlines" : true, - "platform.stdio-buffered-serial" : true, - "mbed-client.event-loop-size" : 1024, + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-client.event-loop-size" : 2048, + "mbed-cloud-client.external-sst-support" : 1, "nanostack-hal.event_loop_thread_stack_size": 8192, - "update-client.storage-address" : "(1024*1024*64)", - "update-client.storage-size" : "(1024*1024*2)", - "update-client.storage-locations" : 1, - "mbed-trace.enable": null, - "nsapi.default-wifi-security" : "WPA_WPA2", - "nsapi.default-wifi-ssid" : "\"SSID\"", - "nsapi.default-wifi-password" : "\"Password\"" + "update-client.storage-locations" : 1, + "mbed-trace.enable" : null, + "nsapi.default-wifi-security" : "WPA_WPA2", + "nsapi.default-wifi-ssid" : "\"SSID\"", + "nsapi.default-wifi-password" : "\"Password\"" }, "STM_EMAC": { "lwip.pbuf-pool-size" : 16, "lwip.mem-size" : 12500 }, "UBLOX_EVK_ODIN_W2": { - "target.network-default-interface-type" : "WIFI", - "update-client.bootloader-details" : "0x08007300", - "update-client.application-details" : "(0x08000000+64*1024)", - "target.lse_available" : 0, - "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] + "target.network-default-interface-type" : "WIFI", + "target.bootloader_img" : "tools/mbed-bootloader-ublox_evk_odin_w2-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x08007300", + "update-client.application-details" : "(0x08000000+64*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(0x08000000+32*1024)", + "storage_filesystem.rbp_internal_size" : "(32*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD", + "target.lse_available" : 0, + "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] } }, "config": { diff --git a/main.cpp b/main.cpp index 204280e..4566ae7 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,5 @@ // ---------------------------------------------------------------------------- -// Copyright 2016-2018 ARM Ltd. +// Copyright 2016-2019 ARM Ltd. // // SPDX-License-Identifier: Apache-2.0 // @@ -32,7 +32,12 @@ static Blinky blinky; static void main_application(void); +#if defined(MBED_CLOUD_APPLICATION_NONSTANDARD_ENTRYPOINT) +extern "C" +int mbed_cloud_application_entrypoint(void) +#else int main(void) +#endif { mcc_platform_run_program(main_application); } @@ -72,7 +77,7 @@ void blink_callback(void *) } } -void button_status_callback(const M2MBase& object, +void notification_status_callback(const M2MBase& object, const M2MBase::MessageDeliveryStatus status, const M2MBase::MessageType /*type*/) { @@ -155,6 +160,13 @@ void main_application(void) // Print platform information mcc_platform_sw_build_info(); + // Initialize network + if (!mcc_platform_init_connection()) { + printf("Network initialized, connecting...\n"); + } else { + return; + } + // Print some statistics of the object sizes and their heap memory consumption. // NOTE: This *must* be done before creating MbedCloudClient, as the statistic calculation // creates and deletes M2MSecurity and M2MDevice singleton objects, which are also used by @@ -188,15 +200,15 @@ void main_application(void) // Create resource for button count. Path of this resource will be: 3200/0/5501. button_res = mbedClient.add_cloud_resource(3200, 0, 5501, "button_resource", M2MResourceInstance::INTEGER, - M2MBase::GET_ALLOWED, 0, true, NULL, (void*)button_status_callback); + M2MBase::GET_ALLOWED, 0, true, NULL, (void*)notification_status_callback); // Create resource for led blinking pattern. Path of this resource will be: 3201/0/5853. pattern_res = mbedClient.add_cloud_resource(3201, 0, 5853, "pattern_resource", M2MResourceInstance::STRING, - M2MBase::GET_PUT_ALLOWED, "500:500:500:500", false, (void*)pattern_updated, NULL); + M2MBase::GET_PUT_ALLOWED, "500:500:500:500", true, (void*)pattern_updated, (void*)notification_status_callback); // Create resource for starting the led blinking. Path of this resource will be: 3201/0/5850. blink_res = mbedClient.add_cloud_resource(3201, 0, 5850, "blink_resource", M2MResourceInstance::STRING, - M2MBase::POST_ALLOWED, "", false, (void*)blink_callback, (void*)button_status_callback); + M2MBase::POST_ALLOWED, "", false, (void*)blink_callback, (void*)notification_status_callback); // Use delayed response blink_res->set_delayed_response(true); @@ -226,5 +238,6 @@ void main_application(void) } } - // Client unregistered, exit program. + // Client unregistered, disconnect and exit program. + mcc_platform_close_connection(); } diff --git a/mbed-cloud-client.lib b/mbed-cloud-client.lib index 3d37e14..794abb2 100644 --- a/mbed-cloud-client.lib +++ b/mbed-cloud-client.lib @@ -1 +1 @@ -https://github.com/ARMmbed/mbed-cloud-client/#004a8cb0fa9c0a32eca2265efb6d4530e578a63d +https://github.com/ARMmbed/mbed-cloud-client/#d1142c05f53c5ce4804932346b3108db135311bb diff --git a/mbed-os.lib b/mbed-os.lib index 69fff22..adfc4d7 100644 --- a/mbed-os.lib +++ b/mbed-os.lib @@ -1 +1 @@ -https://github.com/ARMmbed/mbed-os/#6a0a86538c0b9b2bfcc4583b1e2b7fea8f4e71e9 +https://github.com/ARMmbed/mbed-os/#ecb3c8c837162c73537bd0f3592c6e2a42994045 diff --git a/mbed_app.json b/mbed_app.json index 6114bec..b1fdf61 100644 --- a/mbed_app.json +++ b/mbed_app.json @@ -1,64 +1,130 @@ { "macros": [ - "ARM_UC_USE_PAL_BLOCKDEVICE=1", - "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE" + "ARM_UC_USE_PAL_BLOCKDEVICE=1" ], "target_overrides": { "*": { - "target.features_add" : ["BOOTLOADER", "STORAGE"], - "target.components_add" : ["SD"], - "platform.stdio-baud-rate" : 115200, - "platform.stdio-convert-newlines" : true, - "platform.stdio-buffered-serial" : true, - "mbed-client.event-loop-size" : 1024, + "target.features_add" : ["BOOTLOADER", "STORAGE"], + "platform.stdio-baud-rate" : 115200, + "platform.stdio-convert-newlines" : true, + "platform.stdio-buffered-serial" : true, + "platform.stdio-flush-at-exit" : true, + "mbed-cloud-client.external-sst-support" : 1, "nanostack-hal.event_loop_thread_stack_size": 8192, - "update-client.storage-address" : "(1024*1024*64)", - "update-client.storage-size" : "(1024*1024*2)", - "update-client.storage-locations" : 1, - "mbed-trace.enable": null, - "nsapi.default-wifi-security" : "WPA_WPA2", - "nsapi.default-wifi-ssid" : "\"SSID\"", - "nsapi.default-wifi-password" : "\"Password\"" + "update-client.storage-locations" : 1, + "mbed-trace.enable" : null, + "nsapi.default-wifi-security" : "WPA_WPA2", + "nsapi.default-wifi-ssid" : "\"SSID\"", + "nsapi.default-wifi-password" : "\"Password\"" }, "STM_EMAC": { - "lwip.pbuf-pool-size" : 16, - "lwip.mem-size" : 12500 + "lwip.pbuf-pool-size" : 16, + "lwip.mem-size" : 12500 }, "K64F": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x00007188", - "update-client.application-details" : "(40*1024)" + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-k64f-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x00007188", + "update-client.application-details" : "(40*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "storage_filesystem.internal_base_address" : "(32*1024)", + "storage_filesystem.rbp_internal_size" : "(8*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD" }, "K66F": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x00007188", - "update-client.application-details" : "(40*1024)" + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-k66f-internal_flash-no_rot-v4.0.0.bin", + "target.header_offset" : "0x8000", + "target.app_offset" : "0x8400", + "update-client.bootloader-details" : "0x4D58", + "update-client.application-details" : "(32*1024)", + "update-client.storage-address" : "(MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS+MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE)", + "update-client.storage-size" : "(1024*1024-MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE)", + "update-client.storage-page" : 8, + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP", + "storage_tdb_internal.internal_base_address": "(1024*1024)", + "storage_tdb_internal.internal_size" : "(96*1024)", + "storage.storage_type" : "TDB_INTERNAL" }, "NUCLEO_F429ZI": { - "target.network-default-interface-type" : "ETHERNET", - "update-client.bootloader-details" : "0x080078CC", - "update-client.application-details" : "(0x08000000+64*1024)" + "target.network-default-interface-type" : "ETHERNET", + "target.bootloader_img" : "tools/mbed-bootloader-nucleo_f429zi-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x080078CC", + "update-client.application-details" : "(0x08000000+64*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "mbed-cloud-client.external-sst-support" : 1, + "storage_filesystem.internal_base_address" : "(0x08000000+32*1024)", + "storage_filesystem.rbp_internal_size" : "(32*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD", + "sd.SPI_MOSI" : "PC_12", + "sd.SPI_MISO" : "PC_11", + "sd.SPI_CLK" : "PC_10", + "sd.SPI_CS" : "PA_15" }, "UBLOX_EVK_ODIN_W2": { - "target.network-default-interface-type" : "WIFI", - "update-client.bootloader-details" : "0x08007300", - "update-client.application-details" : "(0x08000000+64*1024)", - "target.lse_available" : 0, - "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] + "target.network-default-interface-type" : "WIFI", + "target.bootloader_img" : "tools/mbed-bootloader-ublox_evk_odin_w2-block_device-kvstore-v4.0.0.bin", + "target.components_add" : ["SD"], + "update-client.bootloader-details" : "0x08007300", + "update-client.application-details" : "(0x08000000+64*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "mbed-cloud-client.external-sst-support" : 1, + "mbed-client.event-loop-size" : 2048, + "storage_filesystem.internal_base_address" : "(0x08000000+32*1024)", + "storage_filesystem.rbp_internal_size" : "(32*1024)", + "storage_filesystem.external_base_address" : "(0x0)", + "storage_filesystem.external_size" : "(1024*1024*64)", + "storage.storage_type" : "FILESYSTEM", + "storage_filesystem.filesystem" : "LITTLE", + "storage_filesystem.blockdevice" : "SD", + "target.lse_available" : 0, + "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] }, "NUCLEO_F411RE": { - "client_app.mbedtls-user-config-file" : "\"mbedTLSConfig_mbedOS_SW_TRNG.h\"", - "client_app.pal-user-defined-configuration": "\"sotp_non_trng_config_MbedOS.h\"", - "target.network-default-interface-type" : "WIFI", - "drivers.uart-serial-rxbuf-size" : 1024, - "drivers.uart-serial-txbuf-size" : 1024, - "update-client.bootloader-details" : "(0x08000000+30*1024)", - "update-client.application-details" : "(0x08000000+64*1024)", - "events.shared-stacksize" : 2048, - "idw0xx1.provide-default": true, - "idw0xx1.tx": "PA_9", - "idw0xx1.rx": "PA_10", - "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"] + "target.components_add" : ["SD"], + "client_app.mbedtls-user-config-file" : "\"mbedTLSConfig_mbedOS_SW_TRNG.h\"", + "client_app.pal-user-defined-configuration" : "\"pal_config_legacy_non_trng_MbedOS.h\"", + "target.network-default-interface-type" : "WIFI", + "update-client.bootloader-details" : "(0x08000000+30*1024)", + "update-client.application-details" : "(0x08000000+64*1024)", + "update-client.storage-address" : "(1024*1024*64)", + "update-client.storage-size" : "((MBED_ROM_START + MBED_ROM_SIZE - APPLICATION_ADDR) * MBED_CONF_UPDATE_CLIENT_STORAGE_LOCATIONS)", + "mbed-cloud-client.update-storage" : "ARM_UCP_FLASHIAP_BLOCKDEVICE", + "mbed-cloud-client.external-sst-support" : null, + "mbed-client.event-loop-size" : 2048, + "client_app.sotp-section-1-address" : "(0x08000000+32*1024)", + "client_app.sotp-section-1-size" : "(16*1024)", + "client_app.sotp-section-2-address" : "(0x08000000+48*1024)", + "client_app.sotp-section-2-size" : "(16*1024)", + "drivers.uart-serial-rxbuf-size" : 1024, + "drivers.uart-serial-txbuf-size" : 1024, + "events.shared-stacksize" : 2048, + "idw0xx1.provide-default" : true, + "idw0xx1.tx" : "PA_9", + "idw0xx1.rx" : "PA_10", + "target.macros_remove" : ["MBEDTLS_CONFIG_HW_SUPPORT"], + "target.macros_add" : ["DISABLE_ERROR_DESCRIPTION"], + "mbed-client-pal.pal-dns-api-version" : 0, + "sd.SPI_MOSI" : "PC_3", + "sd.SPI_MISO" : "PC_2", + "sd.SPI_CLK" : "PC_7", + "sd.SPI_CS" : "PB_9" } }, "config": { diff --git a/mbed_cloud_client_user_config.h b/mbed_cloud_client_user_config.h index e92ac2e..b1e213f 100644 --- a/mbed_cloud_client_user_config.h +++ b/mbed_cloud_client_user_config.h @@ -21,17 +21,22 @@ #define MBED_CLOUD_CLIENT_USER_CONFIG_H #define MBED_CLOUD_CLIENT_ENDPOINT_TYPE "default" -#define MBED_CLOUD_CLIENT_TRANSPORT_MODE_TCP + #define MBED_CLOUD_CLIENT_LIFETIME 3600 #ifdef __FREERTOS__ #define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 512 + #define MBED_CLOUD_CLIENT_TRANSPORT_MODE_TCP +#elif defined(__SXOS__) + #define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 512 + #define MBED_CLOUD_CLIENT_TRANSPORT_MODE_UDP_QUEUE #else #define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 1024 + #define MBED_CLOUD_CLIENT_TRANSPORT_MODE_TCP #endif /* set flag to enable update support in mbed Cloud client */ -#ifndef __FREERTOS__ +#if defined(__linux__) || defined(TARGET_LIKE_MBED) || defined(__SXOS__) #define MBED_CLOUD_CLIENT_SUPPORT_UPDATE #endif /* set download buffer size in bytes (min. 1024 bytes) */ diff --git a/mbed_lib.json b/mbed_lib.json index fe6ddc6..95a35ac 100644 --- a/mbed_lib.json +++ b/mbed_lib.json @@ -61,7 +61,7 @@ "pal-user-defined-configuration": { "help": "Defines which PAL configuration the board should use.", "macro_name": "PAL_USER_DEFINED_CONFIGURATION", - "value": "\"sotp_fs_config_MbedOS.h\"" + "value": "\"pal_config_MbedOS.h\"" } }, "target_overrides": { @@ -69,36 +69,6 @@ "pal_number_of_partition": 1, "partition_mode": 1, "auto_partition": 1 - }, - "K64F": { - "sotp-section-1-address" : "(32*1024)", - "sotp-section-1-size" : "( 4*1024)", - "sotp-section-2-address" : "(36*1024)", - "sotp-section-2-size" : "( 4*1024)" - }, - "K66F": { - "sotp-section-1-address" : "(32*1024)", - "sotp-section-1-size" : "( 4*1024)", - "sotp-section-2-address" : "(36*1024)", - "sotp-section-2-size" : "( 4*1024)" - }, - "NUCLEO_F411RE": { - "sotp-section-1-address" : "(0x08000000+32*1024)", - "sotp-section-1-size" : "(16*1024)", - "sotp-section-2-address" : "(0x08000000+48*1024)", - "sotp-section-2-size" : "(16*1024)" - }, - "NUCLEO_F429ZI": { - "sotp-section-1-address" : "(0x08000000+32*1024)", - "sotp-section-1-size" : "(16*1024)", - "sotp-section-2-address" : "(0x08000000+48*1024)", - "sotp-section-2-size" : "(16*1024)" - }, - "UBLOX_EVK_ODIN_W2": { - "sotp-section-1-address" : "(0x08000000+32*1024)", - "sotp-section-1-size" : "(16*1024)", - "sotp-section-2-address" : "(0x08000000+48*1024)", - "sotp-section-2-size" : "(16*1024)" } } } diff --git a/pal-platform/pal-platform.py b/pal-platform/pal-platform.py index 1dcda18..04ebd44 100644 --- a/pal-platform/pal-platform.py +++ b/pal-platform/pal-platform.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ################################################################################# -# Copyright 2016-2018 ARM Ltd. +# Copyright 2016-2019 ARM Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -939,7 +939,7 @@ def checkToolchainEnv(toolchain): @cli.command( context_settings=CONTEXT_SETTINGS, - short_help='fullBuild deploy and build the project (run "%s fullBuild -h" for help)' % PROG_NAME) + short_help='[DEPRECATED] fullBuild deploy and build the project (run "%s fullBuild -h" for help)' % PROG_NAME) @click.option( '--target', 'target_name', @@ -983,6 +983,7 @@ def checkToolchainEnv(toolchain): def fullbuild(config, target_name, toolchain, external, name, keep_sources, numOfBuildThreads): """deploy and build target files""" config.target_name = target_name + logger.info('fullBuild option has been DEPRECATED and will be removed in future release.') logger.info('fullBuild running for target = %s with toolchain = %s', target_name, toolchain) ctx = click.get_current_context() @@ -1011,6 +1012,7 @@ def fullbuild(config, target_name, toolchain, external, name, keep_sources, numO runCmakeAndMake(out_dir, isDebug, toolchain, output, envPair, external, name, numOfBuildThreads) # CMAKE + build release version + logger.info('fullBuild option has been DEPRECATED and will be removed in future release.') logger.info('\nCompleted fullBuild running for target = %s\nWith toolchain = %s.\nOutput directory: %s\n', target_name, toolchain, output) diff --git a/pal_config_MbedOS.h b/pal_config_MbedOS.h new file mode 100644 index 0000000..c6ba274 --- /dev/null +++ b/pal_config_MbedOS.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2019 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PAL_USER_CONFIG +#define PAL_USER_CONFIG + +#define PAL_USE_HW_ROT 0 +#define PAL_USE_HW_RTC 0 +#define PAL_USE_HW_TRNG 1 +#define PAL_SIMULATOR_FLASH_OVER_FILE_SYSTEM 0 +#define PAL_USE_INTERNAL_FLASH 0 +#define PAL_USE_SECURE_TIME 1 + + +#include "mbedOS_SST.h" + + +#endif //PAL_USER_CONFIG diff --git a/pal_config_legacy_MbedOS.h b/pal_config_legacy_MbedOS.h new file mode 100644 index 0000000..b1e1547 --- /dev/null +++ b/pal_config_legacy_MbedOS.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018-2019 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PAL_CONFIG_LEGACY_MBEDOS +#define PAL_CONFIG_LEGACY_MBEDOS + +#define PAL_USE_HW_ROT 0 +#define PAL_USE_HW_RTC 0 +#define PAL_USE_HW_TRNG 1 +#define PAL_SIMULATOR_FLASH_OVER_FILE_SYSTEM 0 +#define PAL_USE_INTERNAL_FLASH 1 +#define PAL_USE_SECURE_TIME 1 + +#include "mbedOS_default.h" + +#endif //PAL_CONFIG_LEGACY_MBEDOS diff --git a/pal_config_legacy_non_trng_MbedOS.h b/pal_config_legacy_non_trng_MbedOS.h new file mode 100644 index 0000000..fa47016 --- /dev/null +++ b/pal_config_legacy_non_trng_MbedOS.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018-2019 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PAL_CONFIG_LEGACY_NON_TRNG_MBEDOS +#define PAL_CONFIG_LEGACY_NON_TRNG_MBEDOS + +#define PAL_USE_HW_ROT 0 +#define PAL_USE_HW_RTC 0 +#define PAL_USE_HW_TRNG 0 +#define PAL_SIMULATOR_FLASH_OVER_FILE_SYSTEM 0 +#define PAL_USE_INTERNAL_FLASH 1 +#define PAL_USE_SECURE_TIME 1 + +#define PAL_INT_FLASH_NUM_SECTIONS 2 + +#include "mbedOS_default.h" + +#endif //PAL_CONFIG_LEGACY_NON_TRNG_MBEDOS diff --git a/sotp_fs_config_ARIA_MbedOS.h b/sotp_fs_config_ARIA_MbedOS.h deleted file mode 100644 index 64ff392..0000000 --- a/sotp_fs_config_ARIA_MbedOS.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef PAL_HEADER_SOTP_FS_ARIA_MBEDOS -#define PAL_HEADER_SOTP_FS_ARIA_MBEDOS - -#define PAL_USE_HW_ROT 0 -#define PAL_USE_HW_RTC 0 -#define PAL_USE_HW_TRNG 1 -#define PAL_SIMULATOR_FLASH_OVER_FILE_SYSTEM 0 -#define PAL_USE_INTERNAL_FLASH 1 -#define PAL_USE_SECURE_TIME 1 - -#define PAL_TLS_CIPHER_SUITE PAL_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256_SUITE - -#include "mbedOS_default.h" - -#endif //PAL_HEADER_SOTP_FS_ARIA_MBEDOS diff --git a/sotp_fs_config_ARIA_linux.h b/sotp_fs_config_ARIA_linux.h index dbf217e..6b9ccbb 100644 --- a/sotp_fs_config_ARIA_linux.h +++ b/sotp_fs_config_ARIA_linux.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2018-2019 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef PAL_HEADER_SOTP_FS_ARIA_LINUX #define PAL_HEADER_SOTP_FS_ARIA_LINUX diff --git a/sotp_fs_config_MbedOS.h b/sotp_fs_config_MbedOS.h index 1f5912d..fe4646f 100644 --- a/sotp_fs_config_MbedOS.h +++ b/sotp_fs_config_MbedOS.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2018-2019 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef PAL_HEADER_SOTP_FS #define PAL_HEADER_SOTP_FS diff --git a/sotp_fs_config_MbedOS_legacy.h b/sotp_fs_config_MbedOS_legacy.h deleted file mode 100644 index 14e8fd9..0000000 --- a/sotp_fs_config_MbedOS_legacy.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef PAL_HEADER_SOTP_FS_MBEDOS -#define PAL_HEADER_SOTP_FS_MBEDOS - -#define PAL_USE_HW_ROT 1 -#define PAL_USE_HW_RTC 0 -#define PAL_USE_HW_TRNG 1 -#define PAL_SIMULATOR_FLASH_OVER_FILE_SYSTEM 0 -#define PAL_USE_INTERNAL_FLASH 1 -#define PAL_USE_SECURE_TIME 1 - -#include "mbedOS_default.h" - -#endif //PAL_HEADER_SOTP_FS_MBEDOS diff --git a/sotp_fs_config_linux.h b/sotp_fs_config_linux.h index a2bc479..10f539f 100644 --- a/sotp_fs_config_linux.h +++ b/sotp_fs_config_linux.h @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2018-2019 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef PAL_HEADER_SOTP_FS_LINUX #define PAL_HEADER_SOTP_FS_LINUX diff --git a/sotp_non_trng_config_MbedOS.h b/sotp_non_trng_config_MbedOS.h deleted file mode 100644 index edd9c67..0000000 --- a/sotp_non_trng_config_MbedOS.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SOTP_NON_TRNG_CONFIG_MBEDOS -#define SOTP_NON_TRNG_CONFIG_MBEDOS - -#define PAL_USE_HW_ROT 0 -#define PAL_USE_HW_RTC 0 -#define PAL_USE_HW_TRNG 0 -#define PAL_SIMULATOR_FLASH_OVER_FILE_SYSTEM 0 -#define PAL_USE_INTERNAL_FLASH 1 -#define PAL_USE_SECURE_TIME 1 - -#define PAL_INT_FLASH_NUM_SECTIONS 2 - -#include "mbedOS_default.h" - -#endif //SOTP_NON_TRNG_CONFIG_MBEDOS diff --git a/source/app_platform_setup.c b/source/app_platform_setup.c index 1e4c29c..16f1b6d 100644 --- a/source/app_platform_setup.c +++ b/source/app_platform_setup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2018 ARM Limited. All rights reserved. + * Copyright (c) 2015-2019 ARM Limited. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. @@ -44,6 +44,8 @@ int mcc_platform_reset_storage(void) int status = fcc_storage_delete(); if (status != FCC_STATUS_SUCCESS) { printf("Failed to delete storage - %d\n", status); +// Format call is not needed with SST implementation +#ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT // Flagging here because of reformat contains only implementation for mbed-os. #ifdef TARGET_LIKE_MBED status = mcc_platform_reformat_storage(); @@ -56,6 +58,7 @@ int mcc_platform_reset_storage(void) printf("Failed to delete storage - %d\n", status); } } +#endif #endif } return status; diff --git a/source/application_init.cpp b/source/application_init.cpp index c95ec13..114287c 100644 --- a/source/application_init.cpp +++ b/source/application_init.cpp @@ -1,5 +1,5 @@ // ---------------------------------------------------------------------------- -// Copyright 2016-2018 ARM Ltd. +// Copyright 2016-2019 ARM Ltd. // // SPDX-License-Identifier: Apache-2.0 // @@ -145,6 +145,14 @@ void print_fcc_status(int fcc_status) printf("\nFactory Configurator Client [ERROR]: %s\r\n\n", error); } +#if defined(__SXOS__) +extern "C" +void trace_printer(const char* str) +{ + printf("%s\r\n", str); +} +#endif + bool application_init_mbed_trace(void) { // Create mutex for tracing to avoid broken lines in logs @@ -158,6 +166,10 @@ bool application_init_mbed_trace(void) mbed_trace_mutex_wait_function_set(mbed_trace_helper_mutex_wait); mbed_trace_mutex_release_function_set(mbed_trace_helper_mutex_release); +#if defined(__SXOS__) + mbed_trace_print_function_set(trace_printer); +#endif + return 0; } @@ -176,7 +188,7 @@ static bool application_init_verify_cloud_configuration() #endif status = fcc_verify_device_configured_4mbed_cloud(); print_fcc_status(status); - if (status != FCC_STATUS_SUCCESS) { + if (status != FCC_STATUS_SUCCESS && status != FCC_STATUS_EXPIRED_CERTIFICATE) { return 1; } return 0; @@ -212,10 +224,12 @@ static bool application_init_fcc(void) // primary storage if no valid certificates exist. // This should never be used for any kind of production devices. #ifndef MBED_CONF_APP_MCC_NO_AUTO_FORMAT +#ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT printf("Certificate validation failed, trying autorecovery...\n"); if (mcc_platform_reformat_storage() != 0) { return 1; } +#endif status = mcc_platform_reset_storage(); if (status != FCC_STATUS_SUCCESS) { return 1; diff --git a/source/certificate_enrollment_user_cb.h b/source/certificate_enrollment_user_cb.h index 4f5a3d6..f002a07 100644 --- a/source/certificate_enrollment_user_cb.h +++ b/source/certificate_enrollment_user_cb.h @@ -21,6 +21,8 @@ #ifndef CERTIFICATE_ENROLLMENT_USER_CB_H #define CERTIFICATE_ENROLLMENT_USER_CB_H +#include "ce_status.h" +#include "ce_defs.h" #include #ifdef __cplusplus diff --git a/source/platform/.mbedignore b/source/platform/.mbedignore index 71a929d..15cdbee 100644 --- a/source/platform/.mbedignore +++ b/source/platform/.mbedignore @@ -1,3 +1,4 @@ -Linux/* FreeRTOS/* +Linux/* +SXOS/* diff --git a/source/platform/CMakeLists.txt b/source/platform/CMakeLists.txt index 40fccd9..4e12886 100644 --- a/source/platform/CMakeLists.txt +++ b/source/platform/CMakeLists.txt @@ -1,6 +1,6 @@ INCLUDE(CMakeForceCompiler) # CROSS COMPILER SETTING -cmake_minimum_required (VERSION 2.8) +cmake_minimum_required (VERSION 3.5) SET(CMAKE_SYSTEM_NAME Generic) project(platformCommon) diff --git a/source/platform/SXOS/cpp_helpers.cpp b/source/platform/SXOS/cpp_helpers.cpp new file mode 100644 index 0000000..f614afb --- /dev/null +++ b/source/platform/SXOS/cpp_helpers.cpp @@ -0,0 +1,61 @@ +// ---------------------------------------------------------------------------- +// Copyright 2018 ARM Ltd. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------- + +#include "cos.h" + +#include + +void* operator new(size_t count) +{ + return COS_Malloc((UINT32)count, COS_MMI_HEAP); +} + +void* operator new[](size_t count) +{ + return COS_Malloc((UINT32)count, COS_MMI_HEAP); +} + +void operator delete(void* ptr) +{ + // unlike other free() implementations, the COS version does not + // handle NULL + if (ptr) { + COS_Free(ptr); + } +} + +// XXX: m2mfirmware needs this for some reason +void operator delete(void *ptr, size_t sz) +{ + if (ptr) { + COS_Free(ptr); + } +} + +void operator delete[](void* ptr) +{ + if (ptr) { + COS_Free(ptr); + } +} + +extern "C" +void __cxa_pure_virtual() +{ + assert(false); +} diff --git a/source/platform/SXOS/mcc_common_button_and_led.c b/source/platform/SXOS/mcc_common_button_and_led.c new file mode 100644 index 0000000..a78f9c7 --- /dev/null +++ b/source/platform/SXOS/mcc_common_button_and_led.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015-2018 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////// +// INCLUDES +/////////// + +#include "mcc_common_config.h" +#include "mcc_common_button_and_led.h" + +#include +#include +#include + + +uint8_t mcc_platform_button_clicked(void) +{ + return 0; +} + +uint8_t mcc_platform_init_button_and_led(void) +{ + return 0; +} + +void mcc_platform_toggle_led(void) +{ +#if PLATFORM_ENABLE_LED + printf("Virtual LED toggled\n"); +#endif +} + +void mcc_platform_led_off(void) +{ +} diff --git a/source/platform/SXOS/mcc_common_setup.c b/source/platform/SXOS/mcc_common_setup.c new file mode 100644 index 0000000..47b0d00 --- /dev/null +++ b/source/platform/SXOS/mcc_common_setup.c @@ -0,0 +1,437 @@ +/* + * Copyright (c) 2018 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "mcc_common_setup.h" +#include "mcc_common_config.h" + +#include "cos.h" +#include "drv.h" +#include "errorcode.h" +#include "cfw.h" + +#include +#include +#include + +static HANDLE arm_task_handle; + +#define GPRS_DEATT 0 +#define GPRS_ATT 1 +#define GPRS_ACT 2 + +#define DMA_ALIGN_SIZE 16 +#define DMA_ALIGN_MASK (DMA_ALIGN_SIZE-1) + +//////////////////////////////////////// +// PLATFORM SPECIFIC DEFINES & FUNCTIONS +//////////////////////////////////////// +static void *network_interface = NULL; +static DRV_UART_T *uart_drv; + +// counter of RX data overflows, which is useful for tracing data losses +static volatile int rx_overflows; + +// XXX - Todo: need to have configuration for SIM id and APN +static const UINT8 nSim = 0; +static char* nApn = ""; + +static INT32 nCid = 0; +static UINT32 g_InitialState = GPRS_DEATT; + +static bool first_platform_init = true; + +extern struct netif *getGprsNetIf(UINT8 nSim, UINT8 nCid); + +/* UART settings - port and baudrate + * Port depends of AT port defined in target.config + * Baudrate is default 115200 - might be higher, not tested? + */ +#if (AT_DEFAULT_UART == 2) +#define ARM_UART_ID 1 +#elif (AT_DEFAULT_UART == 1) +#define ARM_UART_ID 2 +#else +#error "AT_DEFAULT_UART not set" +#endif + +#define ARM_UART_BAUDRATE 115200 + +#define MCC_CONNECTION_TIMEOUT (10*60) // Seconds +static uint32_t timeout = 0; + +// Semaphore used on communication from rx-callback to the getchar(). +static COS_SEMA serial_rx_semaphore = COS_SEMA_UNINIT; + + +// This function is derived from example code provided by Unisoc +static INT32 startGprsLink1(UINT8 *apn, UINT8 nSIMID) +{ + UINT8 nAttstate = 0xFF; + UINT32 nRet = 0x00; + UINT8 nCID = 0x00, nState = 0x00; + CFW_NW_STATUS_INFO sStatus; + UINT8 nUTI = 0x00; + + nRet = CFW_GetGprsAttState(&nAttstate, nSIMID); + printf("startGprsLink GprsAttState nRet=0x%x,nAttstate=%d\n", nRet, nAttstate); + if (nAttstate != CFW_GPRS_ATTACHED) { + g_InitialState = GPRS_DEATT; + CFW_GetFreeUTI(0, &nUTI); + nRet = CFW_GprsAtt(CFW_GPRS_ATTACHED, nUTI, nSIMID); + printf("startGprsLink nUTI=%d,nRet=0x%x\n", nUTI, nRet); + while (nRet == ERR_SUCCESS && nAttstate != CFW_GPRS_ATTACHED) { + if (timeout > MCC_CONNECTION_TIMEOUT) { + printf("Timeout!\n"); + return -1; + } + + printf("startGprsLink Waiting ATT ... nAttstate=%d,nRet=0x%x\n", nAttstate, nRet); + COS_Sleep(2000); + timeout += 2; + + // There is no worth continue registration if ATT status is UNKNOWN + if (CFW_GprsGetstatus(&sStatus, nSIMID) == ERR_SUCCESS && + sStatus.nStatus == CFW_NW_STATUS_UNKNOW) { + printf("Registration failed! (NW status Unknown)\n"); + return -1; + } + + nRet = CFW_GetGprsAttState(&nAttstate, nSIMID); + } + } + + if (nRet == ERR_SUCCESS && nAttstate == CFW_GPRS_ATTACHED) { + g_InitialState = GPRS_ATT; + } else { + return -1; + } + + nRet = CFW_GprsGetstatus(&sStatus, nSIMID); + while (nRet == ERR_SUCCESS && + sStatus.nStatus != CFW_NW_STATUS_REGISTERED_HOME && + sStatus.nStatus != CFW_NW_STATUS_REGISTERED_ROAMING) { + + if (timeout > MCC_CONNECTION_TIMEOUT) { + printf("Timeout!\n"); + return -1; + } + + printf("startGprsLink Waiting Service ... sStatus.nStatus=%d,nRet=0x%x\n", sStatus.nStatus, nRet); + COS_Sleep(1000); + timeout += 1; + nRet = CFW_GprsGetstatus(&sStatus, nSIMID); + } + if (nRet != ERR_SUCCESS) { + return -1; + } + + nRet = CFW_GetFreeCID(&nCID, nSIMID); + printf("startGprsLink CFW_GetFreeCID nCID=%d,nRet=0x%x\n", nCID, nRet); + + CFW_GPRS_QOS qos; + qos.nDelay = 4; + qos.nMean = 16; + qos.nPeak = 4; + qos.nPrecedence = 3; + qos.nReliability = 3; + nRet = CFW_GprsSetReqQos(nCID, &qos, nSIMID); + printf("startGprsLink CFW_GprsSetReqQos ret nUTI=%d,nRet=0x%x\n", nUTI, nRet); + + CFW_GPRS_PDPCONT_INFO pdp_cont; + pdp_cont.nApnSize = strlen(apn); + pdp_cont.pApn = apn; + + pdp_cont.nPdpAddrSize = 0; + pdp_cont.pPdpAddr = NULL; + pdp_cont.nDComp = 0; + pdp_cont.nHComp = 0; + pdp_cont.nPdpType = CFW_GPRS_PDP_TYPE_IP; + + pdp_cont.nApnUserSize = 0; + pdp_cont.pApnUser = NULL; + pdp_cont.nApnPwdSize = 0; + pdp_cont.pApnPwd = NULL; + + nRet = CFW_GprsSetPdpCxt(nCID, &pdp_cont, nSIMID); + printf("startGprsLink CFW_GprsSetPdpCxt nCID=%d,nRet=0x%x\n", nCID, nRet); + + nRet = CFW_GetGprsActState(nCID, &nState, nSIMID); + if (nState != CFW_GPRS_ACTIVED) { + nRet = CFW_GprsAct(CFW_GPRS_ACTIVED, nCID, nUTI, nSIMID); + printf("startGprsLink CFW_GprsAct nCID=%d,nRet=0x%x\n", nCID, nRet); + while (nRet == ERR_SUCCESS && nState != CFW_GPRS_ACTIVED) { + if (timeout > MCC_CONNECTION_TIMEOUT) { + printf("Timeout!\n"); + return -1; + } + printf("startGprsLink Waiting Act ... nState=%d,nRet=0x%x\n", nState, nRet); + COS_Sleep(1000); + timeout += 1; + nRet = CFW_GetGprsActState(nCID, &nState, nSIMID); + } + } + + if (nRet == ERR_SUCCESS && nState == CFW_GPRS_ACTIVED) { + g_InitialState = GPRS_ACT; + } + + if (nRet != ERR_SUCCESS) { + return -1; + } + + return nCID; +} + +// This function is derived from example code provided by Unisoc +static void restoreGprsLink(UINT8 nSIMID, UINT8 nCID) +{ + UINT8 nAttstate = 0xFF; + UINT32 nRet = 0x00; + UINT8 nState = 0x00; + CFW_NW_STATUS_INFO sStatus; + UINT8 nUTI = 0x00; + + if (g_InitialState == GPRS_ATT) { + nRet = CFW_GetGprsAttState(&nAttstate, nSIMID); + printf("resoreGprsLink GprsAttState nRet=0x%x,nAttstate=%d\n", nRet, nAttstate); + if (nAttstate != CFW_GPRS_DETACHED) { + CFW_GetFreeUTI(0, &nUTI); + nRet = CFW_GprsAtt(CFW_GPRS_DETACHED, nUTI, nSIMID); + printf("resoreGprsLink nUTI=%d,nRet=0x%x\n", nUTI, nRet); + while (nRet == ERR_SUCCESS && nAttstate != CFW_GPRS_DETACHED) { + printf("resoreGprsLink Waiting ATT ... nAttstate=%d,nRet=0x%x\n", nAttstate, nRet); + COS_Sleep(500); + nRet = CFW_GetGprsAttState(&nAttstate, nSIMID); + } + } + } else if (g_InitialState == GPRS_ACT) { + nRet = CFW_GetGprsActState(nCID, &nState, nSIMID); + if (nState != CFW_GPRS_DEACTIVED) { + CFW_GetFreeUTI(0, &nUTI); + nRet = CFW_GprsAct(CFW_GPRS_DEACTIVED, nCID, nUTI, nSIMID); + printf("resoreGprsLink CFW_GprsDEAct nCID=%d,nRet=0x%x,uti=%d\n", nCID, nRet, nUTI); + while (nRet == ERR_SUCCESS && nState != CFW_GPRS_DEACTIVED) { + printf("resoreGprsLink Waiting DEAct ... nState=%d,nRet=0x%x\n", nState, nRet); + COS_Sleep(500); + nRet = CFW_GetGprsActState(nCID, &nState, nSIMID); + } + } + } + + g_InitialState = GPRS_DEATT; +} + +//////////////////////////////// +// SETUP_COMMON.H IMPLEMENTATION +//////////////////////////////// +int mcc_platform_init_connection(void) +{ + timeout = 0; + + if (g_InitialState != GPRS_ACT) { + printf("Waiting for network connection...\n"); + + nCid = startGprsLink1(nApn, nSim); + if (nCid < 0) { + printf("Unable to get context id!\n"); + return -1; + } + + while (timeout < MCC_CONNECTION_TIMEOUT) { + network_interface = getGprsNetIf(nSim, (UINT8)nCid); + if (network_interface != NULL) { + printf("Connected!\n"); + return 0; + } else { + printf("."); + COS_Sleep(2000); + timeout += 2; + } + } + + printf("Unable to connect!\n"); + return -1; + } else { + return 0; + } +} + +int mcc_platform_close_connection(void) +{ + network_interface = NULL; + restoreGprsLink(nSim, (UINT8)nCid); + return 0; +} + +void* mcc_platform_get_network_interface(void) +{ + return network_interface; +} + +int sxos_uart_write(const char *data, int len) +{ + int offset = 0; + + while (offset < len) { + + int written = DRV_UartWrite(uart_drv, data + offset, len - offset, 500); + + offset += written; + } + + return offset; +} + +static void arm_UartCallback(DRV_UART_T *drv, void *param, DRV_UART_EVENT_T evt) +{ + if (evt &= DRV_UART_RX_ARRIVED) { + // ping the receival end + COS_SemaRelease(&serial_rx_semaphore); + } + if (evt &= DRV_UART_RX_OVERFLOW) { + rx_overflows++; + } +} + +static int sxos_uart_init(void) +{ + static bool uart_initted = false; + + // allow calling again, useful for re-using the code from multiple main()'s, + // eg. testapp (which calls mcc_platform_init()) can call PAL's test code which + // also performs its initializations. + if (uart_initted) { + return 0; + } + + COS_SemaInit(&serial_rx_semaphore, 0); + + uart_drv = COS_Malloc((UINT32) DRV_UartStructSize(), COS_MMI_HEAP); + static DRV_UART_CFG_T drvcfg = {0}; + memset(uart_drv, 0, DRV_UartStructSize()); + COS_PRINTFI("[ARM], sxos_uart_init"); + /* Init UART port */ + /* Fill DRV_UART_CFG_T */ + drvcfg.baud = ARM_UART_BAUDRATE; + drvcfg.dataBits = DRV_UART_DATA_BITS_8; + drvcfg.stopBits = DRV_UART_STOP_BITS_1; + drvcfg.parity = DRV_UART_NO_PARITY; + drvcfg.autoFlowCtrlLevel = DRV_UART_DISABLE_AUTO_FLOW_CTRL; + drvcfg.rxDmaBuf = (uint8_t *)COS_Malloc(256 + DMA_ALIGN_MASK, COS_MMI_HEAP); + /* Align address. rxDmaBuf address must be DMA_ALIGN_MASK aligned (currently, 16 bytes) */ + drvcfg.rxDmaBuf = (uint8_t *)((uint32_t)(drvcfg.rxDmaBuf + DMA_ALIGN_MASK) & (~DMA_ALIGN_MASK)); + drvcfg.rxBuf = (uint8_t *)COS_Malloc((4 * 1024), COS_MMI_HEAP); + drvcfg.txBuf = (uint8_t *)COS_Malloc((4 * 1024), COS_MMI_HEAP); + drvcfg.rxDmaSize = 256; + drvcfg.rxBufSize = (4 * 1024); + drvcfg.txBufSize = (4 * 1024); + + // My board works also when RX polling is disabled, but (some?) HW is said to + // have a bug where RX interrupt is not necessarily delivered so polling is needed. + // So let's have the 100 polls per second as it should be enough for 115,2Kbps link. + drvcfg.rxPollPeriod = 10; + + drvcfg.evtMask = DRV_UART_RX_ARRIVED | DRV_UART_RX_OVERFLOW | DRV_UART_WAKE_UP; + drvcfg.callback = arm_UartCallback; + drvcfg.callbackParam = uart_drv; + if (false == DRV_UartInit(uart_drv, ARM_UART_ID, &drvcfg)) { + COS_PRINTFE("[ARM], UART init failed"); + return -1; + } + /* Open UART port */ + if (false == DRV_UartOpen(uart_drv)) { + COS_PRINTFE("[ARM], UART open failed"); + return -1; + } + + uart_initted = true; + + return 0; +} + +// In order for tests to pass for all partition configurations we need to simulate the case of multiple +// partitions using a single path. We do this by creating one or two different sub-paths, depending on +// the configuration. +int mcc_platform_storage_init(void) +{ + return 0; +} + +int mcc_platform_init(void) +{ + int err = 0; + + // TODO: This requires a better solution + // SX OS start up requires a small delay before platform + // functions can be called. + if (first_platform_init) { + COS_Sleep(2000); + } + + arm_task_handle = COS_GetCurrentTaskHandle(); + + first_platform_init = false; + + if (0 != sxos_uart_init()) { + return -1; + } + + return err; +} + +int mcc_platform_reformat_storage(void) +{ +// cleanup folders +// to do: +// PAL_FS_MOUNT_POINT_PRIMARY +// PAL_FS_MOUNT_POINT_SECONDARY + printf("mcc_platform_reformat_storage is not supported\n"); + return 0; +} + +void mcc_platform_do_wait(int timeout_ms) +{ + usleep(timeout_ms * 1000); +} + +int mcc_platform_run_program(main_t mainFunc) +{ + mainFunc(); + return 1; +} + +void mcc_platform_sw_build_info(void) +{ + printf("Application ready. Build at: " __DATE__ " " __TIME__ "\n"); +} + +int getchar(void) +{ + int c = 0; + while (DRV_UartRead(uart_drv, (uint8_t*)&c, 1) == 0) { + // sleep until the arm_UartCallback() wakes us + COS_SemaTake(&serial_rx_semaphore); + } + + // XXX: enable next line to make RX overflows visible. I can't actually make the + // overflow happen on my machine, so perhaps it could even be enabled by default?! +#if 0 + if (rx_overflows > 0) { + assert(false); + } +#endif + + return c; +} diff --git a/source/platform/SXOS/platform_adaptation.c b/source/platform/SXOS/platform_adaptation.c new file mode 100644 index 0000000..37b7d17 --- /dev/null +++ b/source/platform/SXOS/platform_adaptation.c @@ -0,0 +1,120 @@ +// ---------------------------------------------------------------------------- +// Copyright 2018 ARM Ltd. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------- + +#include +#include + + +int sxos_uart_write(const char *data, int len); +extern int mbed_cloud_application_entrypoint(); + +static const char eol[2] = {'\r', '\n'}; + +// default external application entrypoint for SXOS sdk +int external_application_entrypoint() +{ + return mbed_cloud_application_entrypoint(); +} + +// XXX: we need to provide this as it misses from SDK and ns_cmdline +// has the default function which uses this and linker wants it. +int vprintf(const char *fmt, va_list ap) +{ + char buf[512]; + int total; + int charsWritten = 0; + + total = vsnprintf(buf, (sizeof(buf) - 1), fmt, ap); + + const char* outputBuf = buf; + const char* outputBufEnd = buf + total; + + while (outputBuf < outputBufEnd) { + + // search for end of line + const char* nextEol = strchr(outputBuf, '\n'); + + if (nextEol) { + // found LF, count bytes before it + int bytesToEol = nextEol - outputBuf; + + if (bytesToEol == 0) { + // A single LF, so lets print the CR+LF and skip the source char. + // This branch could be combined with next if also, but this looks simpler. + charsWritten += sxos_uart_write(eol, 2); + outputBuf += 1; + } else if ((bytesToEol >= 1) && (outputBuf[bytesToEol - 1] != '\r')) { + // Just LF on end of line, so we need to print chars before it and write extra CR+LF pair. + charsWritten += sxos_uart_write(outputBuf, bytesToEol); + charsWritten += sxos_uart_write(eol, 2); + outputBuf += bytesToEol + 1; + } else { + // String had CR+LF, so no need to add extra, just print until LF. + // Todo: this could just continue too to gang up more chars into write + // if the source already has the CR+LF's in place. + charsWritten += sxos_uart_write(outputBuf, bytesToEol + 1); + outputBuf += bytesToEol + 1; + } + } else { + // no need to convert anymore or at all, just write the rest of string + int bytesLeft = strlen(outputBuf); + charsWritten += sxos_uart_write(outputBuf, bytesLeft); + break; + } + } + return charsWritten; +} + +int putchar(int ch) +{ + char buf = (char)ch; + + if (buf == 0x0a) { + char cr = 0x0d; + sxos_uart_write(&cr, 1); + } + sxos_uart_write(&buf, 1); + return ch; +} + +int puts(const char* str) +{ + size_t len = strlen(str); + sxos_uart_write(str, len); + + // puts() needs to print string and trailing linefeed, which is CR+LF here + sxos_uart_write(eol, 2); + + // return value is non-negative on success + return len; +} + +int fflush(void* stream) +{ + return 0; +} + +int printf(const char *format, ...) +{ + va_list arglist; + va_start(arglist, format); + int length = vprintf(format, arglist); + va_end(arglist); + return length; +} + diff --git a/source/platform/include/mcc_common_setup.h b/source/platform/include/mcc_common_setup.h index 5fad04e..d3885bc 100644 --- a/source/platform/include/mcc_common_setup.h +++ b/source/platform/include/mcc_common_setup.h @@ -41,7 +41,7 @@ int mcc_platform_close_connection(void); // Return network interface. void *mcc_platform_get_network_interface(void); -// Format storage +// Format storage (DEPRECATED) int mcc_platform_reformat_storage(void); // initialize common details for storage for storing KCM data etc. diff --git a/source/platform/mbed-os/mcc_common_setup.cpp b/source/platform/mbed-os/mcc_common_setup.cpp index 4a94828..76011b1 100644 --- a/source/platform/mbed-os/mcc_common_setup.cpp +++ b/source/platform/mbed-os/mcc_common_setup.cpp @@ -27,23 +27,234 @@ #include "mbed.h" #include "mcc_common_setup.h" #include "mcc_common_config.h" +#ifdef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT +#include "kv_config.h" +#endif -#include "mbed-trace/mbed_trace.h" +#include "mbed_trace.h" #define TRACE_GROUP "plat" -// This is for single or dual partition mode. This is supposed to be used with storage for data e.g. SD card. -// Enable by 1/disable by 0. -#ifndef MCC_PLATFORM_PARTITION_MODE -#define MCC_PLATFORM_PARTITION_MODE 0 -#endif - #define SECONDS_TO_MS 1000 // to avoid using floats, wait() uses floats #ifndef MCC_PLATFORM_WAIT_BEFORE_BD_INIT #define MCC_PLATFORM_WAIT_BEFORE_BD_INIT 2 #endif +/* local help functions. */ +const char* network_type(NetworkInterface *iface); + +//////////////////////////////////////// +// PLATFORM SPECIFIC DEFINES & FUNCTIONS +//////////////////////////////////////// + +static NetworkInterface* network_interface=NULL; + +/* Callback function which informs about status of connected NetworkInterface. + * */ +static void network_status_callback(nsapi_event_t status, intptr_t param); + +//////////////////////////////// +// SETUP_COMMON.H IMPLEMENTATION +//////////////////////////////// + +int mcc_platform_init_connection(void) { +// Perform number of retries if network init fails. +#ifndef MCC_PLATFORM_CONNECTION_RETRY_COUNT +#define MCC_PLATFORM_CONNECTION_RETRY_COUNT 5 +#endif +#ifndef MCC_PLATFORM_CONNECTION_RETRY_TIMEOUT +#define MCC_PLATFORM_CONNECTION_RETRY_TIMEOUT 1000 +#endif + printf("mcc_platform_init_connection()\n"); + + network_interface = NetworkInterface::get_default_instance(); + if(network_interface == NULL) { + printf("ERROR: No NetworkInterface found!\n"); + return -1; + } + network_interface->attach(&network_status_callback); + printf("Connecting with interface: %s\n", network_type(NetworkInterface::get_default_instance())); + for (int i=1; i <= MCC_PLATFORM_CONNECTION_RETRY_COUNT; i++) { + nsapi_error_t e; + e = network_interface->connect(); + if (e == NSAPI_ERROR_OK) { + printf("IP: %s\n", network_interface->get_ip_address()); + return 0; + } + printf("Failed to connect! error=%d. Retry %d/%d\n", e, i, MCC_PLATFORM_CONNECTION_RETRY_COUNT); + mcc_platform_do_wait(MCC_PLATFORM_CONNECTION_RETRY_TIMEOUT * i); + } + return -1; +} + +int mcc_platform_close_connection(void) { + + if (network_interface) { + const nsapi_error_t err = network_interface->disconnect(); + if (err == NSAPI_ERROR_OK) { + network_interface->attach(NULL); + network_interface = NULL; + return 0; + } + } + return -1; +} + +void* mcc_platform_get_network_interface(void) { + return network_interface; +} + +void network_status_callback(nsapi_event_t status, intptr_t param) +{ + if (status == NSAPI_EVENT_CONNECTION_STATUS_CHANGE) { + switch(param) { + case NSAPI_STATUS_GLOBAL_UP: +#if MBED_CONF_MBED_TRACE_ENABLE + tr_info("NSAPI_STATUS_GLOBAL_UP"); +#else + printf("NSAPI_STATUS_GLOBAL_UP\n"); +#endif + break; + case NSAPI_STATUS_LOCAL_UP: +#if MBED_CONF_MBED_TRACE_ENABLE + tr_info("NSAPI_STATUS_LOCAL_UP"); +#else + printf("NSAPI_STATUS_LOCAL_UP\n"); +#endif + break; + case NSAPI_STATUS_DISCONNECTED: +#if MBED_CONF_MBED_TRACE_ENABLE + tr_info("NSAPI_STATUS_DISCONNECTED"); +#else + printf("NSAPI_STATUS_DISCONNECTED\n"); +#endif + break; + case NSAPI_STATUS_CONNECTING: +#if MBED_CONF_MBED_TRACE_ENABLE + tr_info("NSAPI_STATUS_CONNECTING"); +#else + printf("NSAPI_STATUS_CONNECTING\n"); +#endif + break; + case NSAPI_STATUS_ERROR_UNSUPPORTED: +#if MBED_CONF_MBED_TRACE_ENABLE + tr_info("NSAPI_STATUS_ERROR_UNSUPPORTED"); +#else + printf("NSAPI_STATUS_ERROR_UNSUPPORTED\n"); +#endif + break; + } + } +} + +const char* network_type(NetworkInterface *iface) +{ + if (iface->ethInterface()) { + return "Ethernet"; + } else if (iface->wifiInterface()) { + return "WiFi"; + } else if (iface->meshInterface()) { + return "Mesh"; + } else if (iface->cellularBase()) { + return "Cellular"; + } else if (iface->emacInterface()) { + return "Emac"; + } else { + return "Unknown"; + } +} + +int mcc_platform_init(void) +{ + // On CortexM (3 and 4) the MCU has a write buffer, which helps in performance front, + // but has a side effect of making data access faults imprecise. + // + // So, if one gets a Mbed OS crash dump with following content, a re-build with + // "PLATFORM_DISABLE_WRITE_BUFFER=1" will help in getting the correct crash location. + // + // --8<--- + // Crash Info: + // <..> + // Target and Fault Info: + // Forced exception, a fault with configurable priority has been escalated to HardFault + // Imprecise data access error has occurred + // --8<--- + // + // This can't be enabled by default as then we would test with different system setup than customer + // and possible OS and driver issues might get pass the tests. + // +#if defined(PLATFORM_DISABLE_WRITE_BUFFER) && (PLATFORM_DISABLE_WRITE_BUFFER==1) + +#if defined(TARGET_CORTEX_M) + + SCnSCB->ACTLR |= SCnSCB_ACTLR_DISDEFWBUF_Msk; + + tr_info("mcc_platform_init: disabled CPU write buffer, expect reduced performance"); +#else + tr_info("mcc_platform_init: disabling CPU write buffer not possible or needed on this MCU"); +#endif + +#endif + + return 0; +} + +void mcc_platform_do_wait(int timeout_ms) +{ + wait_ms(timeout_ms); +} + +int mcc_platform_run_program(main_t mainFunc) +{ + mainFunc(); + return 1; +} + +void mcc_platform_sw_build_info(void) { + printf("Application ready. Build at: " __DATE__ " " __TIME__ "\n"); + + // The Mbed OS' master branch does not define the version numbers at all, so we need + // some ifdeffery to keep compilations running. +#if defined(MBED_MAJOR_VERSION) && defined(MBED_MINOR_VERSION) && defined(MBED_PATCH_VERSION) + printf("Mbed OS version %d.%d.%d\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); +#else + printf("Mbed OS version \n"); +#endif +} + +#ifdef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT +int mcc_platform_storage_init(void) { + // This wait will allow the board more time to initialize + wait_ms(MCC_PLATFORM_WAIT_BEFORE_BD_INIT * SECONDS_TO_MS); + int status = kv_init_storage_config(); + if (status != MBED_SUCCESS) { + printf("kv_init_storage_config() - failed, status %d\n", status); + } + return status; +} +#endif + +/* Rest is legacy storage implementation not needed for SST enabled client. + * This implementation will be removed in future release. + */ +#ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT + +static int mcc_platform_reformat_partition(FileSystem *fs, BlockDevice* part); +static int mcc_platform_test_filesystem(FileSystem *fs, BlockDevice* part); +#if (MCC_PLATFORM_PARTITION_MODE == 1) +static int mcc_platform_init_and_mount_partition(FileSystem **fs, BlockDevice** part, int number_of_partition, const char* mount_point); +#if (MCC_PLATFORM_AUTO_PARTITION == 1) +static int mcc_platform_create_partitions(); +#endif +#endif + +// This is for single or dual partition mode. This is supposed to be used with storage for data e.g. SD card. +// Enable by 1/disable by 0. +#ifndef MCC_PLATFORM_PARTITION_MODE +#define MCC_PLATFORM_PARTITION_MODE 0 +#endif + #include "pal.h" #if (MCC_PLATFORM_PARTITION_MODE == 1) #include "MBRBlockDevice.h" @@ -95,30 +306,8 @@ static bd_size_t mcc_platform_storage_size = 0; #endif // MCC_PLATFORM_PARTITION_MODE - -/* local help functions. */ -static void print_network_information(NetworkInterface *iface); -static int mcc_platform_reformat_partition(FileSystem *fs, BlockDevice* part); -static int mcc_platform_test_filesystem(FileSystem *fs, BlockDevice* part); -#if (MCC_PLATFORM_PARTITION_MODE == 1) -static int mcc_platform_init_and_mount_partition(FileSystem **fs, BlockDevice** part, int number_of_partition, const char* mount_point); -#if (MCC_PLATFORM_AUTO_PARTITION == 1) -static int mcc_platform_create_partitions(); -#endif -#endif - -//////////////////////////////////////// -// PLATFORM SPECIFIC DEFINES & FUNCTIONS -//////////////////////////////////////// -static NetworkInterface* network_interface=NULL; - -static BlockDevice* bd = NULL; -#ifdef ARM_UC_USE_PAL_BLOCKDEVICE -// Can be moved extern reference under update src. No reason keep here because get_default_instance is mbed-os interface. -BlockDevice* arm_uc_blockdevice = BlockDevice::get_default_instance(); -#endif - // blockdevice and filesystem pointers for storage +static BlockDevice* bd = NULL; static BlockDevice *part1 = NULL; static FileSystem *fs1 = NULL; @@ -132,55 +321,6 @@ static FileSystem *fs2 = NULL; #endif #endif // MCC_PLATFORM_PARTITION_MODE -/* Callback function which informs about status of connected NetworkInterface. - * */ -static void network_status_callback(nsapi_event_t status, intptr_t param); - -//////////////////////////////// -// SETUP_COMMON.H IMPLEMENTATION -//////////////////////////////// -int mcc_platform_init_connection(void) { -// Perform number of retries if network init fails. -#ifndef MCC_PLATFORM_CONNECTION_RETRY_COUNT -#define MCC_PLATFORM_CONNECTION_RETRY_COUNT 3 -#endif - printf("mcc_platform_init_connection()\n"); - - network_interface = NetworkInterface::get_default_instance(); - if(network_interface == NULL) { - printf("ERROR: No NetworkInterface found!\n"); - return -1; - } - network_interface->attach(&network_status_callback); - for (int i=0; i < MCC_PLATFORM_CONNECTION_RETRY_COUNT; i++) { - nsapi_error_t e; - e = network_interface->connect(); - if (e == NSAPI_ERROR_OK) { - print_network_information(network_interface); - return 0; - } - printf("Failed to connect! error=%d\n", e); - } - return -1; -} - -int mcc_platform_close_connection(void) { - - if (network_interface) { - const nsapi_error_t err = network_interface->disconnect(); - if (err == NSAPI_ERROR_OK) { - network_interface->attach(NULL); - network_interface = NULL; - return 0; - } - } - return -1; -} - -void* mcc_platform_get_network_interface(void) { - return network_interface; -} - /* help function format partition. */ static int mcc_platform_reformat_partition(FileSystem *fs, BlockDevice* part) { int status; @@ -194,32 +334,6 @@ static int mcc_platform_reformat_partition(FileSystem *fs, BlockDevice* part) { return status; } -int mcc_platform_reformat_storage(void) { - int status = -1; - - printf("Reformat the storage.\n"); - if (bd) { -#if (NUMBER_OF_PARTITIONS > 0) - status = mcc_platform_reformat_partition(fs1, part1); - if (status != 0) { - printf("Formatting primary partition failed with 0x%X !!!\n", status); - return status; - } -#if (NUMBER_OF_PARTITIONS == 2) - status = mcc_platform_reformat_partition(fs2, part2); - if (status != 0) { - printf("Formatting secondary partition failed with 0x%X !!!\n", status); - return status; - } -#endif -#if (NUMBER_OF_PARTITIONS > 2) -#error "Invalid number of partitions!!!" -#endif -#endif - } - return status; -} - /* help function for testing filesystem availbility by umount and * mount filesystem again. * */ @@ -352,10 +466,13 @@ static int mcc_platform_create_partitions(void) { } #endif // ((MCC_PLATFORM_PARTITION_MODE == 1) && (MCC_PLATFORM_AUTO_PARTITION == 1)) + int mcc_platform_storage_init(void) { - static bool init_done=false; + int status=0; + static bool init_done=false; + if(!init_done) { bd = BlockDevice::get_default_instance(); if (bd) { @@ -428,127 +545,31 @@ int mcc_platform_storage_init(void) { else { printf("mcc_platform_storage_init() - init already done.\n"); } - return status; } -int mcc_platform_init(void) -{ - // On CortexM (3 and 4) the MCU has a write buffer, which helps in performance front, - // but has a side effect of making data access faults imprecise. - // - // So, if one gets a Mbed OS crash dump with following content, a re-build with - // "PLATFORM_DISABLE_WRITE_BUFFER=1" will help in getting the correct crash location. - // - // --8<--- - // Crash Info: - // <..> - // Target and Fault Info: - // Forced exception, a fault with configurable priority has been escalated to HardFault - // Imprecise data access error has occurred - // --8<--- - // - // This can't be enabled by default as then we would test with different system setup than customer - // and possible OS and driver issues might get pass the tests. - // -#if defined(PLATFORM_DISABLE_WRITE_BUFFER) && (PLATFORM_DISABLE_WRITE_BUFFER==1) - -#if defined(TARGET_CORTEX_M) - - SCnSCB->ACTLR |= SCnSCB_ACTLR_DISDEFWBUF_Msk; - - tr_info("mcc_platform_init: disabled CPU write buffer, expect reduced performance"); -#else - tr_info("mcc_platform_init: disabling CPU write buffer not possible or needed on this MCU"); -#endif - -#endif - - return 0; -} - -void mcc_platform_do_wait(int timeout_ms) -{ - wait_ms(timeout_ms); -} - -int mcc_platform_run_program(main_t mainFunc) -{ - mainFunc(); - - return 1; -} - -void network_status_callback(nsapi_event_t status, intptr_t param) -{ - if (status == NSAPI_EVENT_CONNECTION_STATUS_CHANGE) { - switch(param) { - case NSAPI_STATUS_GLOBAL_UP: -#if MBED_CONF_MBED_TRACE_ENABLE - tr_info("NSAPI_STATUS_GLOBAL_UP"); -#else - printf("NSAPI_STATUS_GLOBAL_UP\n"); -#endif - break; - case NSAPI_STATUS_LOCAL_UP: -#if MBED_CONF_MBED_TRACE_ENABLE - tr_info("NSAPI_STATUS_LOCAL_UP"); -#else - printf("NSAPI_STATUS_LOCAL_UP\n"); -#endif - break; - case NSAPI_STATUS_DISCONNECTED: -#if MBED_CONF_MBED_TRACE_ENABLE - tr_info("NSAPI_STATUS_DISCONNECTED"); -#else - printf("NSAPI_STATUS_DISCONNECTED\n"); -#endif - break; - case NSAPI_STATUS_CONNECTING: -#if MBED_CONF_MBED_TRACE_ENABLE - tr_info("NSAPI_STATUS_CONNECTING"); -#else - printf("NSAPI_STATUS_CONNECTING\n"); +int mcc_platform_reformat_storage(void) { + int status = -1; + printf("Reformat the storage.\n"); + if (bd) { +#if (NUMBER_OF_PARTITIONS > 0) + status = mcc_platform_reformat_partition(fs1, part1); + if (status != 0) { + printf("Formatting primary partition failed with 0x%X !!!\n", status); + return status; + } +#if (NUMBER_OF_PARTITIONS == 2) + status = mcc_platform_reformat_partition(fs2, part2); + if (status != 0) { + printf("Formatting secondary partition failed with 0x%X !!!\n", status); + return status; + } #endif - break; - case NSAPI_STATUS_ERROR_UNSUPPORTED: -#if MBED_CONF_MBED_TRACE_ENABLE - tr_info("NSAPI_STATUS_ERROR_UNSUPPORTED"); -#else - printf("NSAPI_STATUS_ERROR_UNSUPPORTED\n"); +#if (NUMBER_OF_PARTITIONS > 2) +#error "Invalid number of partitions!!!" #endif - break; - } - } -} - -void mcc_platform_sw_build_info(void) { - printf("Application ready. Build at: " __DATE__ " " __TIME__ "\n"); - - // The Mbed OS' master branch does not define the version numbers at all, so we need - // some ifdeffery to keep compilations running. -#if defined(MBED_MAJOR_VERSION) && defined(MBED_MINOR_VERSION) && defined(MBED_PATCH_VERSION) - printf("Mbed OS version %d.%d.%d\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); -#else - printf("Mbed OS version \n"); #endif -} - -static void print_network_information(NetworkInterface *iface) -{ - if (iface->ethInterface()) { - printf("Connected using Ethernet\n"); - } else if (iface->wifiInterface()) { - printf("Connected using WiFi\n"); - } else if (iface->meshInterface()) { - printf("Connected using Mesh\n"); - } else if (iface->cellularBase()) { - printf("Connected using Cellular\n"); - } else if (iface->emacInterface()) { - printf("Connected using Emac\n"); - } else { - printf("Unknown interface\n"); } - - printf("IP: %s\n", iface->get_ip_address()); + return status; } +#endif // #ifndef MBED_CONF_MBED_CLOUD_CLIENT_EXTERNAL_SST_SUPPORT diff --git a/source/simplem2mclient.h b/source/simplem2mclient.h index f3ac6d4..0a8759d 100644 --- a/source/simplem2mclient.h +++ b/source/simplem2mclient.h @@ -57,16 +57,10 @@ class SimpleM2MClient { _cloud_client.on_unregistered(this, &SimpleM2MClient::client_unregistered); _cloud_client.on_error(this, &SimpleM2MClient::error); - if (!mcc_platform_init_connection()) { - printf("Network initialized, connecting...\n"); - bool setup = _cloud_client.setup(mcc_platform_get_network_interface()); - _register_called = true; - if (!setup) { - printf("Client setup failed\n"); - return false; - } - } else { - printf("Failed to initialize connection\n"); + bool setup = _cloud_client.setup(mcc_platform_get_network_interface()); + _register_called = true; + if (!setup) { + printf("Client setup failed\n"); return false; } diff --git a/tools/mbed-bootloader-k64f-block_device-kvstore-v4.0.0.bin b/tools/mbed-bootloader-k64f-block_device-kvstore-v4.0.0.bin new file mode 100755 index 0000000..a8f61d2 Binary files /dev/null and b/tools/mbed-bootloader-k64f-block_device-kvstore-v4.0.0.bin differ diff --git a/tools/mbed-bootloader-k66f-internal_flash-no_rot-v4.0.0.bin b/tools/mbed-bootloader-k66f-internal_flash-no_rot-v4.0.0.bin new file mode 100755 index 0000000..49b58c9 Binary files /dev/null and b/tools/mbed-bootloader-k66f-internal_flash-no_rot-v4.0.0.bin differ diff --git a/tools/mbed-bootloader-nucleo_f411re-block_device-kvstore-v4.0.0.bin b/tools/mbed-bootloader-nucleo_f411re-block_device-kvstore-v4.0.0.bin new file mode 100755 index 0000000..4de084e Binary files /dev/null and b/tools/mbed-bootloader-nucleo_f411re-block_device-kvstore-v4.0.0.bin differ diff --git a/tools/mbed-bootloader-nucleo_f429zi-block_device-kvstore-v4.0.0.bin b/tools/mbed-bootloader-nucleo_f429zi-block_device-kvstore-v4.0.0.bin new file mode 100755 index 0000000..422473b Binary files /dev/null and b/tools/mbed-bootloader-nucleo_f429zi-block_device-kvstore-v4.0.0.bin differ diff --git a/tools/mbed-bootloader-ublox_evk_odin_w2-block_device-kvstore-v4.0.0.bin b/tools/mbed-bootloader-ublox_evk_odin_w2-block_device-kvstore-v4.0.0.bin new file mode 100755 index 0000000..19fc78c Binary files /dev/null and b/tools/mbed-bootloader-ublox_evk_odin_w2-block_device-kvstore-v4.0.0.bin differ