Generic Pelion Device Management example for various Renesas-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:

https://os.mbed.com/media/cache/platforms/GR-LYCHEE_and_cam.png.250x250_q85.png https://os.mbed.com/media/cache/platforms/GR-PEACH_C_trans.png.250x250_q85.png

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

Example functionality

This example showcases the following device functionality:

  • On user button click, increment Pelion LWM2M button resource.
  • Allow the user to change the state of the board LED from Pelion LWM2M led_state resource and PUT request.

Instructions to use this program with Mbed CLI


1. Import the application into your desktop:

mbed import https://os.mbed.com/teams/Renesas/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)

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 - for more information please contact Renesas (https://en-support.renesas.com/mytickets)

Committer:
MACRUM
Date:
Sat Dec 15 12:47:53 2018 +0900
Revision:
0:6d2053b84a92
initial commit

Who changed what in which revision?

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