Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
This example is known to work great on the following platforms:
- WISE-1530 WiFi Module using DB-1505 carrier board and external SD card reader.
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/Advantech/code/pelion-example-common cd pelion-example-common
2. Download your developer certificate from pelion portal
3. Compile the program
mbed compile -t <toolchain> -m <TARGET_BOARD>
(supported toolchains : GCC_ARM / ARM / IAR)
4. Copy the binary file pelion-example-common.bin to your mbed device.
drivers/storage/MySystemStorage.cpp@0:43ff9e3bc244, 2019-03-12 (annotated)
- Committer:
- chuanga
- Date:
- Tue Mar 12 13:48:39 2019 +0800
- Revision:
- 0:43ff9e3bc244
copying sources from github repository
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| chuanga | 0:43ff9e3bc244 | 1 | /* |
| chuanga | 0:43ff9e3bc244 | 2 | * Copyright (c) 2018 ARM Limited. All rights reserved. |
| chuanga | 0:43ff9e3bc244 | 3 | * SPDX-License-Identifier: Apache-2.0 |
| chuanga | 0:43ff9e3bc244 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| chuanga | 0:43ff9e3bc244 | 5 | * not use this file except in compliance with the License. |
| chuanga | 0:43ff9e3bc244 | 6 | * You may obtain a copy of the License at |
| chuanga | 0:43ff9e3bc244 | 7 | * |
| chuanga | 0:43ff9e3bc244 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| chuanga | 0:43ff9e3bc244 | 9 | * |
| chuanga | 0:43ff9e3bc244 | 10 | * Unless required by applicable law or agreed to in writing, software |
| chuanga | 0:43ff9e3bc244 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| chuanga | 0:43ff9e3bc244 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| chuanga | 0:43ff9e3bc244 | 13 | * See the License for the specific language governing permissions and |
| chuanga | 0:43ff9e3bc244 | 14 | * limitations under the License. |
| chuanga | 0:43ff9e3bc244 | 15 | */ |
| chuanga | 0:43ff9e3bc244 | 16 | #include "BlockDevice.h" |
| chuanga | 0:43ff9e3bc244 | 17 | #include "FileSystem.h" |
| chuanga | 0:43ff9e3bc244 | 18 | #include "FATFileSystem.h" |
| chuanga | 0:43ff9e3bc244 | 19 | #include "LittleFileSystem.h" |
| chuanga | 0:43ff9e3bc244 | 20 | |
| chuanga | 0:43ff9e3bc244 | 21 | #if COMPONENT_SPIF |
| chuanga | 0:43ff9e3bc244 | 22 | #include "SPIFBlockDevice.h" |
| chuanga | 0:43ff9e3bc244 | 23 | #endif |
| chuanga | 0:43ff9e3bc244 | 24 | |
| chuanga | 0:43ff9e3bc244 | 25 | #if COMPONENT_QSPIF |
| chuanga | 0:43ff9e3bc244 | 26 | #include "QSPIFBlockDevice.h" |
| chuanga | 0:43ff9e3bc244 | 27 | #endif |
| chuanga | 0:43ff9e3bc244 | 28 | |
| chuanga | 0:43ff9e3bc244 | 29 | #if COMPONENT_DATAFLASH |
| chuanga | 0:43ff9e3bc244 | 30 | #include "DataFlashBlockDevice.h" |
| chuanga | 0:43ff9e3bc244 | 31 | #endif |
| chuanga | 0:43ff9e3bc244 | 32 | |
| chuanga | 0:43ff9e3bc244 | 33 | #if COMPONENT_SD |
| chuanga | 0:43ff9e3bc244 | 34 | #include "SDBlockDevice.h" |
| chuanga | 0:43ff9e3bc244 | 35 | #endif |
| chuanga | 0:43ff9e3bc244 | 36 | |
| chuanga | 0:43ff9e3bc244 | 37 | #if COMPONENT_FLASHIAP |
| chuanga | 0:43ff9e3bc244 | 38 | #include "FlashIAPBlockDevice.h" |
| chuanga | 0:43ff9e3bc244 | 39 | #endif |
| chuanga | 0:43ff9e3bc244 | 40 | |
| chuanga | 0:43ff9e3bc244 | 41 | #if COMPONENT_NUSD |
| chuanga | 0:43ff9e3bc244 | 42 | #include "NuSDBlockDevice.h" |
| chuanga | 0:43ff9e3bc244 | 43 | #endif |
| chuanga | 0:43ff9e3bc244 | 44 | |
| chuanga | 0:43ff9e3bc244 | 45 | using namespace mbed; |
| chuanga | 0:43ff9e3bc244 | 46 | |
| chuanga | 0:43ff9e3bc244 | 47 | // Align a value to a specified size. |
| chuanga | 0:43ff9e3bc244 | 48 | // Parameters : |
| chuanga | 0:43ff9e3bc244 | 49 | // val - [IN] Value. |
| chuanga | 0:43ff9e3bc244 | 50 | // size - [IN] Size. |
| chuanga | 0:43ff9e3bc244 | 51 | // Return : Aligned value. |
| chuanga | 0:43ff9e3bc244 | 52 | static inline uint32_t align_up(uint32_t val, uint32_t size) |
| chuanga | 0:43ff9e3bc244 | 53 | { |
| chuanga | 0:43ff9e3bc244 | 54 | return (((val - 1) / size) + 1) * size; |
| chuanga | 0:43ff9e3bc244 | 55 | } |
| chuanga | 0:43ff9e3bc244 | 56 | |
| chuanga | 0:43ff9e3bc244 | 57 | BlockDevice *BlockDevice::get_default_instance() |
| chuanga | 0:43ff9e3bc244 | 58 | { |
| chuanga | 0:43ff9e3bc244 | 59 | #if COMPONENT_SPIF |
| chuanga | 0:43ff9e3bc244 | 60 | |
| chuanga | 0:43ff9e3bc244 | 61 | static SPIFBlockDevice default_bd( |
| chuanga | 0:43ff9e3bc244 | 62 | MBED_CONF_SPIF_DRIVER_SPI_MOSI, |
| chuanga | 0:43ff9e3bc244 | 63 | MBED_CONF_SPIF_DRIVER_SPI_MISO, |
| chuanga | 0:43ff9e3bc244 | 64 | MBED_CONF_SPIF_DRIVER_SPI_CLK, |
| chuanga | 0:43ff9e3bc244 | 65 | MBED_CONF_SPIF_DRIVER_SPI_CS, |
| chuanga | 0:43ff9e3bc244 | 66 | MBED_CONF_SPIF_DRIVER_SPI_FREQ |
| chuanga | 0:43ff9e3bc244 | 67 | ); |
| chuanga | 0:43ff9e3bc244 | 68 | |
| chuanga | 0:43ff9e3bc244 | 69 | return &default_bd; |
| chuanga | 0:43ff9e3bc244 | 70 | |
| chuanga | 0:43ff9e3bc244 | 71 | #elif COMPONENT_QSPIF |
| chuanga | 0:43ff9e3bc244 | 72 | |
| chuanga | 0:43ff9e3bc244 | 73 | static QSPIFBlockDevice default_bd( |
| chuanga | 0:43ff9e3bc244 | 74 | MBED_CONF_QSPIF_QSPI_IO0, |
| chuanga | 0:43ff9e3bc244 | 75 | MBED_CONF_QSPIF_QSPI_IO1, |
| chuanga | 0:43ff9e3bc244 | 76 | MBED_CONF_QSPIF_QSPI_IO2, |
| chuanga | 0:43ff9e3bc244 | 77 | MBED_CONF_QSPIF_QSPI_IO3, |
| chuanga | 0:43ff9e3bc244 | 78 | MBED_CONF_QSPIF_QSPI_SCK, |
| chuanga | 0:43ff9e3bc244 | 79 | MBED_CONF_QSPIF_QSPI_CSN, |
| chuanga | 0:43ff9e3bc244 | 80 | MBED_CONF_QSPIF_QSPI_POLARITY_MODE, |
| chuanga | 0:43ff9e3bc244 | 81 | MBED_CONF_QSPIF_QSPI_FREQ |
| chuanga | 0:43ff9e3bc244 | 82 | ); |
| chuanga | 0:43ff9e3bc244 | 83 | |
| chuanga | 0:43ff9e3bc244 | 84 | return &default_bd; |
| chuanga | 0:43ff9e3bc244 | 85 | |
| chuanga | 0:43ff9e3bc244 | 86 | #elif COMPONENT_DATAFLASH |
| chuanga | 0:43ff9e3bc244 | 87 | |
| chuanga | 0:43ff9e3bc244 | 88 | static DataFlashBlockDevice default_bd( |
| chuanga | 0:43ff9e3bc244 | 89 | MBED_CONF_DATAFLASH_SPI_MOSI, |
| chuanga | 0:43ff9e3bc244 | 90 | MBED_CONF_DATAFLASH_SPI_MISO, |
| chuanga | 0:43ff9e3bc244 | 91 | MBED_CONF_DATAFLASH_SPI_CLK, |
| chuanga | 0:43ff9e3bc244 | 92 | MBED_CONF_DATAFLASH_SPI_CS |
| chuanga | 0:43ff9e3bc244 | 93 | ); |
| chuanga | 0:43ff9e3bc244 | 94 | |
| chuanga | 0:43ff9e3bc244 | 95 | return &default_bd; |
| chuanga | 0:43ff9e3bc244 | 96 | |
| chuanga | 0:43ff9e3bc244 | 97 | #elif COMPONENT_SD |
| chuanga | 0:43ff9e3bc244 | 98 | |
| chuanga | 0:43ff9e3bc244 | 99 | static SDBlockDevice default_bd( |
| chuanga | 0:43ff9e3bc244 | 100 | MBED_CONF_SD_SPI_MOSI, |
| chuanga | 0:43ff9e3bc244 | 101 | MBED_CONF_SD_SPI_MISO, |
| chuanga | 0:43ff9e3bc244 | 102 | MBED_CONF_SD_SPI_CLK, |
| chuanga | 0:43ff9e3bc244 | 103 | MBED_CONF_SD_SPI_CS |
| chuanga | 0:43ff9e3bc244 | 104 | ); |
| chuanga | 0:43ff9e3bc244 | 105 | |
| chuanga | 0:43ff9e3bc244 | 106 | return &default_bd; |
| chuanga | 0:43ff9e3bc244 | 107 | |
| chuanga | 0:43ff9e3bc244 | 108 | #elif COMPONENT_NUSD |
| chuanga | 0:43ff9e3bc244 | 109 | |
| chuanga | 0:43ff9e3bc244 | 110 | static NuSDBlockDevice default_bd; |
| chuanga | 0:43ff9e3bc244 | 111 | |
| chuanga | 0:43ff9e3bc244 | 112 | return &default_bd; |
| chuanga | 0:43ff9e3bc244 | 113 | |
| chuanga | 0:43ff9e3bc244 | 114 | #elif COMPONENT_FLASHIAP |
| chuanga | 0:43ff9e3bc244 | 115 | |
| chuanga | 0:43ff9e3bc244 | 116 | #if (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE == 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS == 0xFFFFFFFF) |
| chuanga | 0:43ff9e3bc244 | 117 | |
| chuanga | 0:43ff9e3bc244 | 118 | size_t flash_size; |
| chuanga | 0:43ff9e3bc244 | 119 | uint32_t start_address; |
| chuanga | 0:43ff9e3bc244 | 120 | uint32_t bottom_address; |
| chuanga | 0:43ff9e3bc244 | 121 | FlashIAP flash; |
| chuanga | 0:43ff9e3bc244 | 122 | |
| chuanga | 0:43ff9e3bc244 | 123 | int ret = flash.init(); |
| chuanga | 0:43ff9e3bc244 | 124 | if (ret != 0) { |
| chuanga | 0:43ff9e3bc244 | 125 | return 0; |
| chuanga | 0:43ff9e3bc244 | 126 | } |
| chuanga | 0:43ff9e3bc244 | 127 | |
| chuanga | 0:43ff9e3bc244 | 128 | //Find the start of first sector after text area |
| chuanga | 0:43ff9e3bc244 | 129 | bottom_address = align_up(FLASHIAP_ROM_END, flash.get_sector_size(FLASHIAP_ROM_END)); |
| chuanga | 0:43ff9e3bc244 | 130 | start_address = flash.get_flash_start(); |
| chuanga | 0:43ff9e3bc244 | 131 | flash_size = flash.get_flash_size(); |
| chuanga | 0:43ff9e3bc244 | 132 | |
| chuanga | 0:43ff9e3bc244 | 133 | ret = flash.deinit(); |
| chuanga | 0:43ff9e3bc244 | 134 | |
| chuanga | 0:43ff9e3bc244 | 135 | static FlashIAPBlockDevice default_bd(bottom_address, start_address + flash_size - bottom_address); |
| chuanga | 0:43ff9e3bc244 | 136 | |
| chuanga | 0:43ff9e3bc244 | 137 | #else |
| chuanga | 0:43ff9e3bc244 | 138 | |
| chuanga | 0:43ff9e3bc244 | 139 | static FlashIAPBlockDevice default_bd; |
| chuanga | 0:43ff9e3bc244 | 140 | |
| chuanga | 0:43ff9e3bc244 | 141 | #endif |
| chuanga | 0:43ff9e3bc244 | 142 | |
| chuanga | 0:43ff9e3bc244 | 143 | return &default_bd; |
| chuanga | 0:43ff9e3bc244 | 144 | |
| chuanga | 0:43ff9e3bc244 | 145 | #else |
| chuanga | 0:43ff9e3bc244 | 146 | |
| chuanga | 0:43ff9e3bc244 | 147 | return NULL; |
| chuanga | 0:43ff9e3bc244 | 148 | |
| chuanga | 0:43ff9e3bc244 | 149 | #endif |
| chuanga | 0:43ff9e3bc244 | 150 | |
| chuanga | 0:43ff9e3bc244 | 151 | } |
| chuanga | 0:43ff9e3bc244 | 152 | |
| chuanga | 0:43ff9e3bc244 | 153 | FileSystem *FileSystem::get_default_instance() |
| chuanga | 0:43ff9e3bc244 | 154 | { |
| chuanga | 0:43ff9e3bc244 | 155 | #if COMPONENT_SPIF || COMPONENT_QSPIF || COMPONENT_DATAFLASH || COMPONENT_NUSD |
| chuanga | 0:43ff9e3bc244 | 156 | |
| chuanga | 0:43ff9e3bc244 | 157 | static LittleFileSystem flash("flash", BlockDevice::get_default_instance()); |
| chuanga | 0:43ff9e3bc244 | 158 | flash.set_as_default(); |
| chuanga | 0:43ff9e3bc244 | 159 | |
| chuanga | 0:43ff9e3bc244 | 160 | return &flash; |
| chuanga | 0:43ff9e3bc244 | 161 | |
| chuanga | 0:43ff9e3bc244 | 162 | #elif COMPONENT_SD |
| chuanga | 0:43ff9e3bc244 | 163 | |
| chuanga | 0:43ff9e3bc244 | 164 | static FATFileSystem sdcard("sd", BlockDevice::get_default_instance()); |
| chuanga | 0:43ff9e3bc244 | 165 | sdcard.set_as_default(); |
| chuanga | 0:43ff9e3bc244 | 166 | |
| chuanga | 0:43ff9e3bc244 | 167 | return &sdcard; |
| chuanga | 0:43ff9e3bc244 | 168 | |
| chuanga | 0:43ff9e3bc244 | 169 | #elif COMPONENT_FLASHIAP |
| chuanga | 0:43ff9e3bc244 | 170 | |
| chuanga | 0:43ff9e3bc244 | 171 | static LittleFileSystem flash("flash", BlockDevice::get_default_instance()); |
| chuanga | 0:43ff9e3bc244 | 172 | flash.set_as_default(); |
| chuanga | 0:43ff9e3bc244 | 173 | |
| chuanga | 0:43ff9e3bc244 | 174 | return &flash; |
| chuanga | 0:43ff9e3bc244 | 175 | |
| chuanga | 0:43ff9e3bc244 | 176 | #else |
| chuanga | 0:43ff9e3bc244 | 177 | |
| chuanga | 0:43ff9e3bc244 | 178 | return NULL; |
| chuanga | 0:43ff9e3bc244 | 179 | |
| chuanga | 0:43ff9e3bc244 | 180 | #endif |
| chuanga | 0:43ff9e3bc244 | 181 | |
| chuanga | 0:43ff9e3bc244 | 182 | } |