ARMmbed / mbed-os-example-pelion

Mbed OS example for Pelion Device Management
Apache License 2.0
14 stars 34 forks source link
lwm2m lwm2m-client mbed-os pelion

Pelion Device Management Client example for Mbed OS

This is a basic Device Management Client example for Mbed OS that supports:

There is a more advanced example of the client with support for multiple operating systems in mbed-cloud-client-example repository. The underlying client library is the same for both. This Mbed OS only example is simpler as it only supports one OS with a limited set of demonstrated features. If you want to do development in Linux and Mbed OS at the same time - you should use the mbed-cloud-client-example.

Note: If you want to use production provisioning modes, or use more advanced client features, those are demonstrated via mbed-cloud-client-example.

Supported boards

This table shows a list of boards that are supported.

Board Connectivity Storage for credentials and FW candidate Notes
Cypress CYTFM_064B0S2_4343W Wi-Fi Internal flash for credentials + external flash for FW candidate To use mbed-os-example-pelion with the CYTFM_064B0S2_4343W board, check out the cytfm-064b0s2-4343w branch and see Running PDMC example on the CYTFM_064B0S2_4343W.
Cypress CY8CPROTO-062-4343W Wi-Fi QSPIF Build-only
Embedded Planet EP_AGORA Cellular SPIF Build-only
Nuvoton NUMAKER_IOT_M263A Wi-Fi ESP8266 SD card (NUSD) Build-only
Nuvoton NUMAKER_IOT_M487 Wi-Fi ESP8266 SD card (NUSD) Build-only
Nuvoton NUMAKER_PFM_M487 Ethernet SD card (NUSD) Build-only
Nuvoton NUMAKER_PFM_NUC472 Ethernet SD card (NUSD) Build-only
NXP K64F Ethernet Internal Flash
NXP K66F Ethernet Internal Flash
Renesas GR_LYCHEE Wi-Fi ESP32 External Flash (See security limitation of this board) Build-only
Renesas RZ_A1H Ethernet External Flash (See security limitation of this board) Build-only
Seeed ARCH_MAX Ethernet SD card Build-only
Seeed WIO_3G Cellular Internal Flash Build-only
Seeed WIO_BG96 Cellular Internal Flash Build-only
ST DISCO_L475VG_IOT01A Wi-Fi QSPIF Build-only
ST DISCO_L496AG Cellular QSPIF Build-only
ST NUCLEO_F411RE Wi-Fi ESP8266 SD card Build-only
ST NUCLEO_F429ZI Ethernet Internal Flash Build-only
ST NUCLEO_F767ZI Ethernet Internal Flash Build-only
ST NUCLEO_H743ZI2 Ethernet Internal Flash Build-only
ST NUCLEO_L4R5ZI Wi-Fi ESP8266 Internal Flash Build-only
ST DISCO_F746NG Ethernet QSPIF Build-only
Uhuru UHURU_RAVEN Wi-Fi ESP32 Internal Flash Build-only

Build-only = This target is currently verified only via compilation, and is not verified at runtime.

Developer guide

This section is intended for developers to get started, import the example application, compile and get it running on their device.

Requirements

Deploying

This repository is in the process of being updated and depends on few enhancements being deployed in mbed-cloud-client. In the meantime, follow these steps to import and apply the patches before compiling.

```
mbed import mbed-os-example-pelion
cd mbed-os-example-pelion
```

Preparing for build

  1. Configure Mbed CLI defaults:

    mbed target K64F
    mbed toolchain GCC_ARM
  2. Download the developer certificates from the Device Management Portal:

    1. Log in to the portal with your credentials.
    2. Navigate to Device identity > Certificates.
    3. Click New certificate.
    4. Add a name and an optional description for the certificate, and click Create certificate.
    5. Go to Device identity > Certificates again.
    6. Click on your new certificate.
    7. Click Download developer C file to download the file mbed_cloud_dev_credentials.c.
  3. Copy the mbed_cloud_dev_credentials.c file to the root folder of the example.

  4. Use manifest-tool python package to create an update-related configuration for your device:

    1. Install the requirements.txt from the application to get the supported version of manifest-tool:
      pip install -r requirements.txt
    2. Initialize the developer environment:
      manifest-dev-tool init --access-key <Device Management access key>

Compiling

mbed compile

Program Flow

  1. Initialize, connect and register to Pelion DM
  2. Interact with the user through the serial port (115200 bauds)
    • Press enter through putty/minicom to simulate button
    • Press i to print endpoint name
    • Press Ctrl-C to to unregister
    • Press r to reset storage and reboot (warning: it generates a new device ID!)

Further information and requirements

Check the public tutorial for further information:

https://www.pelion.com/docs/device-management/current/connecting/mbed-os.html

Enabling logs

Logging (or tracing) can be enabled by modifying the mbed_app.json file.

```
        "mbed-trace.enable"                         : null,
```

By modifying that null to 1 and recompiling the application.

Log level can be modified compile-time by defining MBED_TRACE_MAX_LEVEL -macro to mbed_app.json:

    "target.macros_add": [
         "MBED_TRACE_MAX_LEVEL=TRACE_LEVEL_INFO",

Default level is TRACE_LEVEL_DEBUG, possible values are:

Component level run-time control is also possible by setting log levels (by calling mbed_trace_config_set()) and inclusions/exclusions (by calling mbed_trace_include_filters_set() or mbed_trace_exclude_filters_set()`).

For more details, see the mbed-trace library.

Troubleshooting

Porting process to add support for an Mbed Enabled board

There are many steps involved in this process. We generally recomend the following steps:

  1. Configure the application using mbed_app.json
    • Configure the default connectivity
    • Configure the KVSTORE area to store credentials (internal or external memory)
    • Build the application, program the board and observe whether the application can connect to Pelion DM by using a serial terminal.
  2. Configure the bootloader using bootloader_app.json
    • Configure the KVSTORE area
    • Configure the FW Candidate Storage
    • Build bootloader application, program the board and observe whether this is able to boot.
  3. Enable application with bootloader using mbed_app.json
    • Enable the usage of the bootloader
    • Ensure the KVSTORE addresses and FW Candidate storage addresses match with the bootloader configuration
    • Build the application again (this time combined with bootloader) and check whether it can boot and connect to Pelion DM.
    • Perform a FW Update and check whether the process can be completed succesfully.

1. Application configuration

Note: consider allocating the credentials on internal flash to simplify the application setup process. In addition, consider the use of internal flash to store the firmware candidate image for the FW update process as this would remove the need to use external components. If there isn't enough space, you may need to enable external storage (SD Card, SPI, etc).

Mbed OS boards should have a default configuration for connectivity and storage in Mbed OS (targets.json). You can extend or override the default configuration using mbed_app.json in this application. Create a new entry under the target name for your device.

a. Connectivity

Specify the default IP connectivity type for your target. It's essential with targets that lack default connectivity set in targets.json or for targets that support multiple connectivity options. For example:

  "target.network-default-interface-type" : "ETHERNET",

The possible options are ETHERNET, WIFI and CELLULAR.

Depending on connectivity type, you might have to specify more configuration options. Review the documentation for further information.

b. Storage for credentials

Start by getting familiar with the multiple storage options and configurations supported in Mbed OS.

Then start designing the system memory map, the location of components (whether they are on internal or external memory), and the corresponding base addresses and sizes. You may want to create a diagram similar to the one below to help you to make design decisions:

+--------------------------+
|                          |
|                          |
|                          |
|Firmware Candidate Storage|
|                          |
|                          |
|                          |
+--------------------------+ <-+ update-client.storage-address
|                          |
|         KVSTORE          |
|                          |
+--------------------------+ <-+ storage_tdb_internal.internal_base_address
|                          |
|        Free space        |
|                          |
+--------------------------+
|                          |
|                          |
|        Active App        |
|                          |
|                          |
|                          |
+--------------------------+ <-+ mbed-bootloader.application-start-address
|Active App Metadata Header|
+--------------------------+ <-+ update-client.application-details
|                          |
|        Bootloader        |
|                          |
+--------------------------+ <-+ 0

In cases where the MCU has two separate memory banks, it's appropiate to allocate the bootloader and base application in one bank, and KVSTORE storage at the begining of the second bank followed by a firmware candidate storage.

c. Storage for firmware updates

Before enabling FW updates, it's recomended that the application is able to initialize the network and connect to Pelion DM.

Once the connection is successfull, you can follow the steps below to enable the board to receive FW updates. Note the configuration for the application in this section should match with the one on the bootloader - see section below.

2. Bootloader configuration

The bootloader is required to perform FW Updates. The steps below explain how to create a new configuration and binary for the bootloader.

  1. Import as a new application the mbed-bootloader repository.

  2. Edit the bootloader application configuration in this example (bootloader/bootloader_app.json) and add a new target entry. An example of this configuration can be seen for the NUCLEO_F429ZI board:

    "update-client.firmware-header-version" : "2", "mbed-bootloader.use-kvstore-rot" : 0, "mbed-bootloader.bootloader-size" : "APPLICATION_SIZE", "update-client.application-details" : "(MBED_ROM_START + MBED_BOOTLOADER_SIZE)", "mbed-bootloader.application-start-address": "(MBED_CONF_UPDATE_CLIENT_APPLICATION_DETAILS + MBED_BOOTLOADER_ACTIVE_HEADER_REGION_SIZE)", "mbed-bootloader.max-application-size" : "(MBED_ROM_START + MBED_BOOTLOADER_FLASH_BANK_SIZE - MBED_CONF_MBED_BOOTLOADER_APPLICATION_START_ADDRESS)", "update-client.storage-address" : "(MBED_ROM_START + MBED_BOOTLOADER_FLASH_BANK_SIZE + KVSTORE_SIZE)", "update-client.storage-size" : "(MBED_BOOTLOADER_FLASH_BANK_SIZE - KVSTORE_SIZE)", "update-client.storage-locations" : 1, "kvstore-size" : "2641024", "update-client.storage-page" : 1

  3. Compile the bootloader using the bootloader_app.json configuration you've just edited:

    mbed compile -t <TOOLCHAIN> -m <TARGET> --profile=tiny.json --app-config=.../mbed-os-pelion-example/bootloader/bootloader_app.json>

Note: mbed-bootloader is primarily optimized for GCC_ARM, so you may want to compile it with that toolchain. Before jumping to the next step, you should compile and flash the bootloader and then connect over the virtual serial port to ensure the bootloader is running correctly. You can ignore errors related to checksum verification or failure to jump to application - these are expected at this stage.

Validation and testing for the board configuration

The board needs to pass the underlying Mbed OS tests and be supported by official Mbed OS release.

  cd mbed-os
  mbed test -m <target> -t <toolchain>
  cd mbed-os
  mbed test -t <toolchain> -m <board> -n *integration-* -DINTEGRATION_TESTS -v

Validation and testing for the client configuration

Basic pelion features are required to work:

This should be verified by executing the Pelion E2E python test library tests.

Contributing platform support

The contribution of platform support to this repository is restricted to Arm Mbed Partners and Arm Engineering teams. If you’d like to add a custom or community-based platform, please fork this repository and add it into your own account. Expectations on contributions:

Note platforms will be tested regularly in the Arm CI system. Please discuss with your Arm contact and make hardware available as indicated in the Mbed Enabled requirements.

Known-issues

Please review existing issues on GitHub and report any problem you may see.