Generic Pelion Device Management example for various Nuvoton-based boards.

DEPRECATED

This example application is not maintained and not recommended. It uses an old version of Mbed OS, Pelion DM, and Arm toolchain. It doesn't work with Mbed Studio.

Please use: https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-pelion/

This example is known to work great on the following platforms:

Follow the Quick-Start instructions: https://cloud.mbed.com/quick-start

https://os.mbed.com/media/cache/platforms/NuMaker-IoT-M487_board_front_small.jpg.250x250_q85.jpghttps://os.mbed.com/media/cache/platforms/NuMaker-PFM-M487.png.170x170_q85.png https://os.mbed.com/media/cache/platforms/NuMaker-PFM-NUC472Small.png.170x170_q85.png

Example functionality

This example showcases the following device functionality:

  • On timer button increment, simulate Pelion LWM2M button resource change

Use this example with Mbed CLI


1. Import the application into your desktop:

mbed import https://os.mbed.com/teams/Nuvoton/code/pelion-example-common
cd pelion-example-common


2. Install the CLOUD_SDK_API_KEY

mbed config -G CLOUD_SDK_API_KEY <PELION_DM_API_KEY>

For instructions on how to generate your API key, please see the documentation.

3. Initialize firmware credentials (done once per repository). You can use the following command:

mbed dm init -d "<your company name in Pelion DM>" --model-name "<product model identifier>" -q --force

If above command do not work for your Mbed CLI, please consider upgrading Mbed CLI to version 1.8.x or above.

4. Compile and program:

mbed compile -t <toolchain> -m <TARGET_BOARD>

(supported toolchains : GCC_ARM / ARM / IAR)

5. Copy the binary file pelion-example-common.bin to your mbed device.

Note

This platform and application is suitable for evaluation and initial development. For production purposes, we recommend to use a different variant with built-in security features

Committer:
Sam Chu
Date:
Tue Dec 18 00:07:56 2018 +0800
Revision:
0:e0138281f21d
Child:
2:f07ccb7164d3
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sam Chu 0:e0138281f21d 1 /*
Sam Chu 0:e0138281f21d 2 * Copyright (c) 2018 ARM Limited. All rights reserved.
Sam Chu 0:e0138281f21d 3 * SPDX-License-Identifier: Apache-2.0
Sam Chu 0:e0138281f21d 4 * Licensed under the Apache License, Version 2.0 (the License); you may
Sam Chu 0:e0138281f21d 5 * not use this file except in compliance with the License.
Sam Chu 0:e0138281f21d 6 * You may obtain a copy of the License at
Sam Chu 0:e0138281f21d 7 *
Sam Chu 0:e0138281f21d 8 * http://www.apache.org/licenses/LICENSE-2.0
Sam Chu 0:e0138281f21d 9 *
Sam Chu 0:e0138281f21d 10 * Unless required by applicable law or agreed to in writing, software
Sam Chu 0:e0138281f21d 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
Sam Chu 0:e0138281f21d 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Sam Chu 0:e0138281f21d 13 * See the License for the specific language governing permissions and
Sam Chu 0:e0138281f21d 14 * limitations under the License.
Sam Chu 0:e0138281f21d 15 */
Sam Chu 0:e0138281f21d 16 #include "BlockDevice.h"
Sam Chu 0:e0138281f21d 17 #include "FileSystem.h"
Sam Chu 0:e0138281f21d 18 #include "FATFileSystem.h"
Sam Chu 0:e0138281f21d 19 #include "LittleFileSystem.h"
Sam Chu 0:e0138281f21d 20
Sam Chu 0:e0138281f21d 21 #if COMPONENT_SPIF
Sam Chu 0:e0138281f21d 22 #include "SPIFBlockDevice.h"
Sam Chu 0:e0138281f21d 23 #endif
Sam Chu 0:e0138281f21d 24
Sam Chu 0:e0138281f21d 25 #if COMPONENT_QSPIF
Sam Chu 0:e0138281f21d 26 #include "QSPIFBlockDevice.h"
Sam Chu 0:e0138281f21d 27 #endif
Sam Chu 0:e0138281f21d 28
Sam Chu 0:e0138281f21d 29 #if COMPONENT_DATAFLASH
Sam Chu 0:e0138281f21d 30 #include "DataFlashBlockDevice.h"
Sam Chu 0:e0138281f21d 31 #endif
Sam Chu 0:e0138281f21d 32
Sam Chu 0:e0138281f21d 33 #if COMPONENT_SD
Sam Chu 0:e0138281f21d 34 #include "SDBlockDevice.h"
Sam Chu 0:e0138281f21d 35 #endif
Sam Chu 0:e0138281f21d 36
Sam Chu 0:e0138281f21d 37 #if COMPONENT_FLASHIAP
Sam Chu 0:e0138281f21d 38 #include "FlashIAPBlockDevice.h"
Sam Chu 0:e0138281f21d 39 #endif
Sam Chu 0:e0138281f21d 40
Sam Chu 0:e0138281f21d 41 #if COMPONENT_NUSD
Sam Chu 0:e0138281f21d 42 #include "NuSDBlockDevice.h"
Sam Chu 0:e0138281f21d 43 #endif
Sam Chu 0:e0138281f21d 44
Sam Chu 0:e0138281f21d 45 using namespace mbed;
Sam Chu 0:e0138281f21d 46
Sam Chu 0:e0138281f21d 47 // Align a value to a specified size.
Sam Chu 0:e0138281f21d 48 // Parameters :
Sam Chu 0:e0138281f21d 49 // val - [IN] Value.
Sam Chu 0:e0138281f21d 50 // size - [IN] Size.
Sam Chu 0:e0138281f21d 51 // Return : Aligned value.
Sam Chu 0:e0138281f21d 52 static inline uint32_t align_up(uint32_t val, uint32_t size)
Sam Chu 0:e0138281f21d 53 {
Sam Chu 0:e0138281f21d 54 return (((val - 1) / size) + 1) * size;
Sam Chu 0:e0138281f21d 55 }
Sam Chu 0:e0138281f21d 56
Sam Chu 0:e0138281f21d 57 BlockDevice *BlockDevice::get_default_instance()
Sam Chu 0:e0138281f21d 58 {
Sam Chu 0:e0138281f21d 59 #if COMPONENT_SPIF
Sam Chu 0:e0138281f21d 60
Sam Chu 0:e0138281f21d 61 static SPIFBlockDevice default_bd(
Sam Chu 0:e0138281f21d 62 MBED_CONF_SPIF_DRIVER_SPI_MOSI,
Sam Chu 0:e0138281f21d 63 MBED_CONF_SPIF_DRIVER_SPI_MISO,
Sam Chu 0:e0138281f21d 64 MBED_CONF_SPIF_DRIVER_SPI_CLK,
Sam Chu 0:e0138281f21d 65 MBED_CONF_SPIF_DRIVER_SPI_CS,
Sam Chu 0:e0138281f21d 66 MBED_CONF_SPIF_DRIVER_SPI_FREQ
Sam Chu 0:e0138281f21d 67 );
Sam Chu 0:e0138281f21d 68
Sam Chu 0:e0138281f21d 69 return &default_bd;
Sam Chu 0:e0138281f21d 70
Sam Chu 0:e0138281f21d 71 #elif COMPONENT_QSPIF
Sam Chu 0:e0138281f21d 72
Sam Chu 0:e0138281f21d 73 static QSPIFBlockDevice default_bd(
Sam Chu 0:e0138281f21d 74 MBED_CONF_QSPIF_QSPI_IO0,
Sam Chu 0:e0138281f21d 75 MBED_CONF_QSPIF_QSPI_IO1,
Sam Chu 0:e0138281f21d 76 MBED_CONF_QSPIF_QSPI_IO2,
Sam Chu 0:e0138281f21d 77 MBED_CONF_QSPIF_QSPI_IO3,
Sam Chu 0:e0138281f21d 78 MBED_CONF_QSPIF_QSPI_SCK,
Sam Chu 0:e0138281f21d 79 MBED_CONF_QSPIF_QSPI_CSN,
Sam Chu 0:e0138281f21d 80 MBED_CONF_QSPIF_QSPI_POLARITY_MODE,
Sam Chu 0:e0138281f21d 81 MBED_CONF_QSPIF_QSPI_FREQ
Sam Chu 0:e0138281f21d 82 );
Sam Chu 0:e0138281f21d 83
Sam Chu 0:e0138281f21d 84 return &default_bd;
Sam Chu 0:e0138281f21d 85
Sam Chu 0:e0138281f21d 86 #elif COMPONENT_DATAFLASH
Sam Chu 0:e0138281f21d 87
Sam Chu 0:e0138281f21d 88 static DataFlashBlockDevice default_bd(
Sam Chu 0:e0138281f21d 89 MBED_CONF_DATAFLASH_SPI_MOSI,
Sam Chu 0:e0138281f21d 90 MBED_CONF_DATAFLASH_SPI_MISO,
Sam Chu 0:e0138281f21d 91 MBED_CONF_DATAFLASH_SPI_CLK,
Sam Chu 0:e0138281f21d 92 MBED_CONF_DATAFLASH_SPI_CS
Sam Chu 0:e0138281f21d 93 );
Sam Chu 0:e0138281f21d 94
Sam Chu 0:e0138281f21d 95 return &default_bd;
Sam Chu 0:e0138281f21d 96
Sam Chu 0:e0138281f21d 97 #elif COMPONENT_SD
Sam Chu 0:e0138281f21d 98
Sam Chu 0:e0138281f21d 99 static SDBlockDevice default_bd(
Sam Chu 0:e0138281f21d 100 MBED_CONF_SD_SPI_MOSI,
Sam Chu 0:e0138281f21d 101 MBED_CONF_SD_SPI_MISO,
Sam Chu 0:e0138281f21d 102 MBED_CONF_SD_SPI_CLK,
Sam Chu 0:e0138281f21d 103 MBED_CONF_SD_SPI_CS
Sam Chu 0:e0138281f21d 104 );
Sam Chu 0:e0138281f21d 105
Sam Chu 0:e0138281f21d 106 return &default_bd;
Sam Chu 0:e0138281f21d 107
Sam Chu 0:e0138281f21d 108 #elif COMPONENT_NUSD
Sam Chu 0:e0138281f21d 109
Sam Chu 0:e0138281f21d 110 static NuSDBlockDevice default_bd;
Sam Chu 0:e0138281f21d 111
Sam Chu 0:e0138281f21d 112 return &default_bd;
Sam Chu 0:e0138281f21d 113
Sam Chu 0:e0138281f21d 114 #elif COMPONENT_FLASHIAP
Sam Chu 0:e0138281f21d 115
Sam Chu 0:e0138281f21d 116 #if (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE == 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS == 0xFFFFFFFF)
Sam Chu 0:e0138281f21d 117
Sam Chu 0:e0138281f21d 118 size_t flash_size;
Sam Chu 0:e0138281f21d 119 uint32_t start_address;
Sam Chu 0:e0138281f21d 120 uint32_t bottom_address;
Sam Chu 0:e0138281f21d 121 FlashIAP flash;
Sam Chu 0:e0138281f21d 122
Sam Chu 0:e0138281f21d 123 int ret = flash.init();
Sam Chu 0:e0138281f21d 124 if (ret != 0) {
Sam Chu 0:e0138281f21d 125 return 0;
Sam Chu 0:e0138281f21d 126 }
Sam Chu 0:e0138281f21d 127
Sam Chu 0:e0138281f21d 128 //Find the start of first sector after text area
Sam Chu 0:e0138281f21d 129 bottom_address = align_up(FLASHIAP_ROM_END, flash.get_sector_size(FLASHIAP_ROM_END));
Sam Chu 0:e0138281f21d 130 start_address = flash.get_flash_start();
Sam Chu 0:e0138281f21d 131 flash_size = flash.get_flash_size();
Sam Chu 0:e0138281f21d 132
Sam Chu 0:e0138281f21d 133 ret = flash.deinit();
Sam Chu 0:e0138281f21d 134
Sam Chu 0:e0138281f21d 135 static FlashIAPBlockDevice default_bd(bottom_address, start_address + flash_size - bottom_address);
Sam Chu 0:e0138281f21d 136
Sam Chu 0:e0138281f21d 137 #else
Sam Chu 0:e0138281f21d 138
Sam Chu 0:e0138281f21d 139 static FlashIAPBlockDevice default_bd;
Sam Chu 0:e0138281f21d 140
Sam Chu 0:e0138281f21d 141 #endif
Sam Chu 0:e0138281f21d 142
Sam Chu 0:e0138281f21d 143 return &default_bd;
Sam Chu 0:e0138281f21d 144
Sam Chu 0:e0138281f21d 145 #else
Sam Chu 0:e0138281f21d 146
Sam Chu 0:e0138281f21d 147 return NULL;
Sam Chu 0:e0138281f21d 148
Sam Chu 0:e0138281f21d 149 #endif
Sam Chu 0:e0138281f21d 150
Sam Chu 0:e0138281f21d 151 }
Sam Chu 0:e0138281f21d 152
Sam Chu 0:e0138281f21d 153 FileSystem *FileSystem::get_default_instance()
Sam Chu 0:e0138281f21d 154 {
Sam Chu 0:e0138281f21d 155 #if COMPONENT_SPIF || COMPONENT_QSPIF || COMPONENT_DATAFLASH || COMPONENT_NUSD
Sam Chu 0:e0138281f21d 156
Sam Chu 0:e0138281f21d 157 static LittleFileSystem flash("flash", BlockDevice::get_default_instance());
Sam Chu 0:e0138281f21d 158 flash.set_as_default();
Sam Chu 0:e0138281f21d 159
Sam Chu 0:e0138281f21d 160 return &flash;
Sam Chu 0:e0138281f21d 161
Sam Chu 0:e0138281f21d 162 #elif COMPONENT_SD
Sam Chu 0:e0138281f21d 163
Sam Chu 0:e0138281f21d 164 static FATFileSystem sdcard("sd", BlockDevice::get_default_instance());
Sam Chu 0:e0138281f21d 165 sdcard.set_as_default();
Sam Chu 0:e0138281f21d 166
Sam Chu 0:e0138281f21d 167 return &sdcard;
Sam Chu 0:e0138281f21d 168
Sam Chu 0:e0138281f21d 169 #elif COMPONENT_FLASHIAP
Sam Chu 0:e0138281f21d 170
Sam Chu 0:e0138281f21d 171 static LittleFileSystem flash("flash", BlockDevice::get_default_instance());
Sam Chu 0:e0138281f21d 172 flash.set_as_default();
Sam Chu 0:e0138281f21d 173
Sam Chu 0:e0138281f21d 174 return &flash;
Sam Chu 0:e0138281f21d 175
Sam Chu 0:e0138281f21d 176 #else
Sam Chu 0:e0138281f21d 177
Sam Chu 0:e0138281f21d 178 return NULL;
Sam Chu 0:e0138281f21d 179
Sam Chu 0:e0138281f21d 180 #endif
Sam Chu 0:e0138281f21d 181
Sam Chu 0:e0138281f21d 182 }