Example of Mbed filesystem using HeapBlockDevice

Dependents:   TemperatureButtonFile AccelleratorRead

Committer:
mbed_official
Date:
Fri Dec 15 20:45:15 2017 +0000
Revision:
2:6a0c72c9d3fb
Parent:
1:2bfc377bcc2a
Child:
6:5be6b5fd262f
Merge pull request #12 from ARMmbed/dhwalters423-bd-change

Clarify BlockDevice pin out with example
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-filesystem

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:8e251d9511b8 1 # Getting started with the Mbed OS file system
mbed_official 0:8e251d9511b8 2
mbed_official 0:8e251d9511b8 3 This example demonstrates how to use the Mbed OS file system.
mbed_official 0:8e251d9511b8 4
mbed_official 1:2bfc377bcc2a 5 You can find more information about the Mbed OS file system and other related pieces of the Mbed OS storage stack [in the storage overview](https://os.mbed.com/docs/latest/reference/storage.html).
mbed_official 1:2bfc377bcc2a 6
mbed_official 1:2bfc377bcc2a 7 **Table of contents:**
mbed_official 1:2bfc377bcc2a 8
mbed_official 1:2bfc377bcc2a 9 1. [Hardware requirements](#hardware-requirements)
mbed_official 1:2bfc377bcc2a 10 1. [Usage](#usage)
mbed_official 1:2bfc377bcc2a 11 - [Import the example](#import-the-example)
mbed_official 1:2bfc377bcc2a 12 - [Compile the example](#compile-the-example)
mbed_official 1:2bfc377bcc2a 13 - [Run the example](#run-the-example)
mbed_official 1:2bfc377bcc2a 14 - [Troubleshooting](#troubleshooting)
mbed_official 1:2bfc377bcc2a 15 1. [Changing the file system](#changing-the-file-system)
mbed_official 1:2bfc377bcc2a 16 1. [Changing the block device](#changing-the-block-device)
mbed_official 1:2bfc377bcc2a 17 1. [Tested configurations](#tested-configurations)
mbed_official 0:8e251d9511b8 18
mbed_official 0:8e251d9511b8 19 ## Hardware requirements
mbed_official 0:8e251d9511b8 20
mbed_official 0:8e251d9511b8 21 This example uses a block device as storage. This can be either an external
mbed_official 1:2bfc377bcc2a 22 block device (one of SPI flash, DataFlash or an SD card) or simulated on a
mbed_official 1:2bfc377bcc2a 23 heap block device on boards with enough RAM.
mbed_official 1:2bfc377bcc2a 24
mbed_official 1:2bfc377bcc2a 25 This example uses an instance of the LittleFileSystem API (LittleFS) on external SPI flash.
mbed_official 1:2bfc377bcc2a 26 The [changing the block device](#changing-the-block-device) section describes
mbed_official 1:2bfc377bcc2a 27 how to change the file system or block device in the example.
mbed_official 0:8e251d9511b8 28
mbed_official 0:8e251d9511b8 29 ## Usage
mbed_official 0:8e251d9511b8 30
mbed_official 0:8e251d9511b8 31 #### Import the example
mbed_official 0:8e251d9511b8 32
mbed_official 1:2bfc377bcc2a 33 Make sure you have an Mbed development environment set up. [Get started with Mbed OS](https://os.mbed.com/docs/latest/tutorials/your-first-program.html)
mbed_official 0:8e251d9511b8 34 to set everything up.
mbed_official 0:8e251d9511b8 35
mbed_official 0:8e251d9511b8 36 From the command-line, import the example:
mbed_official 0:8e251d9511b8 37
mbed_official 0:8e251d9511b8 38 ```
mbed_official 0:8e251d9511b8 39 mbed import mbed-os-example-filesystem
mbed_official 0:8e251d9511b8 40 cd mbed-os-example-filesystem
mbed_official 0:8e251d9511b8 41 ```
mbed_official 0:8e251d9511b8 42
mbed_official 0:8e251d9511b8 43 #### Compile the example
mbed_official 0:8e251d9511b8 44
mbed_official 0:8e251d9511b8 45 Invoke `mbed compile`, and specify the name of your platform and your favorite
mbed_official 0:8e251d9511b8 46 toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
mbed_official 0:8e251d9511b8 47
mbed_official 0:8e251d9511b8 48 ```
mbed_official 0:8e251d9511b8 49 mbed compile -m K64F -t ARM
mbed_official 0:8e251d9511b8 50 ```
mbed_official 0:8e251d9511b8 51
mbed_official 0:8e251d9511b8 52 Your PC may take a few minutes to compile your code. At the end, you see the
mbed_official 0:8e251d9511b8 53 following result:
mbed_official 0:8e251d9511b8 54
mbed_official 0:8e251d9511b8 55 ```
mbed_official 0:8e251d9511b8 56 [snip]
mbed_official 0:8e251d9511b8 57 +--------------------------+-------+-------+-------+
mbed_official 0:8e251d9511b8 58 | Module | .text | .data | .bss |
mbed_official 0:8e251d9511b8 59 +--------------------------+-------+-------+-------+
mbed_official 0:8e251d9511b8 60 | Fill | 164 | 0 | 2136 |
mbed_official 0:8e251d9511b8 61 | Misc | 54505 | 2556 | 754 |
mbed_official 0:8e251d9511b8 62 | drivers | 640 | 0 | 32 |
mbed_official 0:8e251d9511b8 63 | features/filesystem | 15793 | 0 | 550 |
mbed_official 0:8e251d9511b8 64 | features/storage | 42 | 0 | 184 |
mbed_official 0:8e251d9511b8 65 | hal | 418 | 0 | 8 |
mbed_official 0:8e251d9511b8 66 | platform | 2355 | 20 | 582 |
mbed_official 0:8e251d9511b8 67 | rtos | 135 | 4 | 4 |
mbed_official 0:8e251d9511b8 68 | rtos/rtx | 5861 | 20 | 6870 |
mbed_official 0:8e251d9511b8 69 | targets/TARGET_Freescale | 8382 | 12 | 384 |
mbed_official 0:8e251d9511b8 70 | Subtotals | 88295 | 2612 | 11504 |
mbed_official 0:8e251d9511b8 71 +--------------------------+-------+-------+-------+
mbed_official 0:8e251d9511b8 72 Allocated Heap: 24576 bytes
mbed_official 0:8e251d9511b8 73 Allocated Stack: unknown
mbed_official 0:8e251d9511b8 74 Total Static RAM memory (data + bss): 14116 bytes
mbed_official 0:8e251d9511b8 75 Total RAM memory (data + bss + heap + stack): 38692 bytes
mbed_official 0:8e251d9511b8 76 Total Flash memory (text + data + misc): 91947 bytes
mbed_official 0:8e251d9511b8 77
mbed_official 0:8e251d9511b8 78 Image: ./BUILD/K64F/ARM/mbed-os-example-filesystem.bin
mbed_official 0:8e251d9511b8 79 ```
mbed_official 0:8e251d9511b8 80
mbed_official 0:8e251d9511b8 81 #### Run the example
mbed_official 0:8e251d9511b8 82
mbed_official 0:8e251d9511b8 83 1. Connect your Mbed Enabled device to the computer over USB.
mbed_official 0:8e251d9511b8 84 1. Copy the binary file to the Mbed Enabled device.
mbed_official 0:8e251d9511b8 85 1. Press the reset button to start the program.
mbed_official 0:8e251d9511b8 86 1. Open the UART of the board in your favorite UART viewing program. For
mbed_official 0:8e251d9511b8 87 example, `screen /dev/ttyACM0`.
mbed_official 0:8e251d9511b8 88
mbed_official 0:8e251d9511b8 89 **Note:** The default serial port baud rate is 9600 bit/s.
mbed_official 0:8e251d9511b8 90
mbed_official 0:8e251d9511b8 91 Expected output:
mbed_official 0:8e251d9511b8 92
mbed_official 0:8e251d9511b8 93 ```
mbed_official 0:8e251d9511b8 94 --- Mbed OS filesystem example ---
mbed_official 0:8e251d9511b8 95 Mounting the filesystem... Fail :(
mbed_official 0:8e251d9511b8 96 No filesystem found, formatting... OK
mbed_official 0:8e251d9511b8 97 Opening "/fs/numbers.txt"... Fail :(
mbed_official 0:8e251d9511b8 98 No file found, creating a new file... OK
mbed_official 0:8e251d9511b8 99 Writing numbers (10/10)... OK
mbed_official 0:8e251d9511b8 100 Seeking file... OK
mbed_official 0:8e251d9511b8 101 Incrementing numbers (10/10)... OK
mbed_official 0:8e251d9511b8 102 Closing "/fs/numbers.txt"... OK
mbed_official 0:8e251d9511b8 103 Opening the root directory... OK
mbed_official 0:8e251d9511b8 104 root directory:
mbed_official 0:8e251d9511b8 105 .
mbed_official 0:8e251d9511b8 106 ..
mbed_official 0:8e251d9511b8 107 numbers.txt
mbed_official 0:8e251d9511b8 108 Closing the root directory... OK
mbed_official 0:8e251d9511b8 109 Opening "/fs/numbers.txt"...OK
mbed_official 0:8e251d9511b8 110 numbers:
mbed_official 0:8e251d9511b8 111 1
mbed_official 0:8e251d9511b8 112 2
mbed_official 0:8e251d9511b8 113 3
mbed_official 0:8e251d9511b8 114 4
mbed_official 0:8e251d9511b8 115 5
mbed_official 0:8e251d9511b8 116 6
mbed_official 0:8e251d9511b8 117 7
mbed_official 0:8e251d9511b8 118 8
mbed_official 0:8e251d9511b8 119 9
mbed_official 0:8e251d9511b8 120 10
mbed_official 0:8e251d9511b8 121 Closing "/fs/numbers.txt"... OK
mbed_official 0:8e251d9511b8 122 Unmounting... OK
mbed_official 0:8e251d9511b8 123 Mbed OS filesystem example done!
mbed_official 0:8e251d9511b8 124 ```
mbed_official 0:8e251d9511b8 125
mbed_official 0:8e251d9511b8 126 You can also reset the board to see the data persist across boots. Each boot
mbed_official 0:8e251d9511b8 127 increments the numbers stored on disk:
mbed_official 0:8e251d9511b8 128
mbed_official 0:8e251d9511b8 129 ```
mbed_official 0:8e251d9511b8 130 --- Mbed OS filesystem example ---
mbed_official 0:8e251d9511b8 131 Mounting the filesystem... OK
mbed_official 0:8e251d9511b8 132 Opening "/fs/numbers.txt"... OK
mbed_official 0:8e251d9511b8 133 Incrementing numbers (10/10)... OK
mbed_official 0:8e251d9511b8 134 Closing "/fs/numbers.txt"... OK
mbed_official 0:8e251d9511b8 135 Opening the root directory... OK
mbed_official 0:8e251d9511b8 136 root directory:
mbed_official 0:8e251d9511b8 137 .
mbed_official 0:8e251d9511b8 138 ..
mbed_official 0:8e251d9511b8 139 numbers.txt
mbed_official 0:8e251d9511b8 140 Closing the root directory... OK
mbed_official 0:8e251d9511b8 141 Opening "/fs/numbers.txt"...OK
mbed_official 0:8e251d9511b8 142 numbers:
mbed_official 0:8e251d9511b8 143 2
mbed_official 0:8e251d9511b8 144 3
mbed_official 0:8e251d9511b8 145 4
mbed_official 0:8e251d9511b8 146 5
mbed_official 0:8e251d9511b8 147 6
mbed_official 0:8e251d9511b8 148 7
mbed_official 0:8e251d9511b8 149 8
mbed_official 0:8e251d9511b8 150 9
mbed_official 0:8e251d9511b8 151 10
mbed_official 0:8e251d9511b8 152 11
mbed_official 0:8e251d9511b8 153 Closing "/fs/numbers.txt"... OK
mbed_official 0:8e251d9511b8 154 Unmounting... OK
mbed_official 0:8e251d9511b8 155 Mbed OS filesystem example done!
mbed_official 0:8e251d9511b8 156 ```
mbed_official 0:8e251d9511b8 157
mbed_official 0:8e251d9511b8 158 If you find yourself with a corrupted file system, you can reset the storage
mbed_official 0:8e251d9511b8 159 by pressing BUTTON1:
mbed_official 0:8e251d9511b8 160
mbed_official 0:8e251d9511b8 161 ```
mbed_official 0:8e251d9511b8 162 Initializing the block device... OK
mbed_official 0:8e251d9511b8 163 Erasing the block device... OK
mbed_official 0:8e251d9511b8 164 Deinitializing the block device... OK
mbed_official 0:8e251d9511b8 165 ```
mbed_official 0:8e251d9511b8 166
mbed_official 0:8e251d9511b8 167 Note that if you press the reset button at the wrong time, you may corrupt
mbed_official 0:8e251d9511b8 168 a file system that is not power resilient!
mbed_official 0:8e251d9511b8 169
mbed_official 0:8e251d9511b8 170 #### Troubleshooting
mbed_official 0:8e251d9511b8 171
mbed_official 0:8e251d9511b8 172 If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html)
mbed_official 0:8e251d9511b8 173 for suggestions on what could be wrong and how to fix it.
mbed_official 0:8e251d9511b8 174
mbed_official 0:8e251d9511b8 175 ## Changing the file system
mbed_official 0:8e251d9511b8 176
mbed_official 1:2bfc377bcc2a 177 In Mbed OS, a C++ classes that inherits from the [FileSystem](https://os.mbed.com/docs/latest/reference/storage.html#declaring-a-file-system)
mbed_official 0:8e251d9511b8 178 interface represents each file system. You can change the file system in the
mbed_official 0:8e251d9511b8 179 example by changing the class declared in main.cpp.
mbed_official 0:8e251d9511b8 180
mbed_official 0:8e251d9511b8 181 ``` diff
mbed_official 0:8e251d9511b8 182 - LittleFileSystem fs("fs");
mbed_official 0:8e251d9511b8 183 + FATFileSysten fs("fs");
mbed_official 0:8e251d9511b8 184 ```
mbed_official 0:8e251d9511b8 185
mbed_official 0:8e251d9511b8 186 Mbed OS has two options for the file system:
mbed_official 0:8e251d9511b8 187
mbed_official 1:2bfc377bcc2a 188 - [**LittleFileSystem**](https://os.mbed.com/docs/latest/reference/littlefilesystem.html) -
mbed_official 1:2bfc377bcc2a 189 The little file system is a fail-safe file system we designed
mbed_official 0:8e251d9511b8 190 for embedded systems, specifically for microcontrollers that use flash
mbed_official 0:8e251d9511b8 191 storage.
mbed_official 1:2bfc377bcc2a 192
mbed_official 1:2bfc377bcc2a 193 ``` cpp
mbed_official 1:2bfc377bcc2a 194 LittleFileSystem fs("fs");
mbed_official 1:2bfc377bcc2a 195 ```
mbed_official 0:8e251d9511b8 196
mbed_official 0:8e251d9511b8 197 - **Bounded RAM/ROM** - This file system works with a limited amount of memory.
mbed_official 0:8e251d9511b8 198 It avoids recursion and limits dynamic memory to configurable
mbed_official 0:8e251d9511b8 199 buffers.
mbed_official 0:8e251d9511b8 200
mbed_official 0:8e251d9511b8 201 - **Power-loss resilient** - We designed this for operating systems
mbed_official 0:8e251d9511b8 202 that may have random power failures. It has strong copy-on-write
mbed_official 0:8e251d9511b8 203 guarantees and keeps storage on disk in a valid state.
mbed_official 0:8e251d9511b8 204
mbed_official 0:8e251d9511b8 205 - **Wear leveling** - Because the most common form of embedded storage is
mbed_official 0:8e251d9511b8 206 erodible flash memories, this file system provides a form of dynamic wear
mbed_official 0:8e251d9511b8 207 leveling for systems that cannot fit a full flash translation layer.
mbed_official 0:8e251d9511b8 208
mbed_official 0:8e251d9511b8 209 - **FATFileSystem** - The FAT file system is a well-known file system that you
mbed_official 0:8e251d9511b8 210 can find on almost every system, including PCs. The Mbed OS implementation of
mbed_official 0:8e251d9511b8 211 the FAT file system is based on ChanFS and is optimized for small embedded systems.
mbed_official 1:2bfc377bcc2a 212
mbed_official 1:2bfc377bcc2a 213 ``` cpp
mbed_official 1:2bfc377bcc2a 214 FATFileSystem fs("fs");
mbed_official 1:2bfc377bcc2a 215 ```
mbed_official 0:8e251d9511b8 216
mbed_official 0:8e251d9511b8 217 - **Portable** - Almost every operating system supports the FAT file system,
mbed_official 0:8e251d9511b8 218 which is the most common file system found on portable storage, such as SD
mbed_official 0:8e251d9511b8 219 cards and flash drives. The FAT file system is the easiest way to support
mbed_official 0:8e251d9511b8 220 access from a PC.
mbed_official 0:8e251d9511b8 221
mbed_official 0:8e251d9511b8 222 ## Changing the block device
mbed_official 0:8e251d9511b8 223
mbed_official 1:2bfc377bcc2a 224 In Mbed OS, a C++ classes that inherits from the [BlockDevice](https://os.mbed.com/docs/latest/reference/storage.html#block-devices)
mbed_official 0:8e251d9511b8 225 interface represents each block device. You can change the filesystem in the
mbed_official 0:8e251d9511b8 226 example by changing the class declared in main.cpp.
mbed_official 0:8e251d9511b8 227
mbed_official 0:8e251d9511b8 228 ``` diff
mbed_official 0:8e251d9511b8 229 -SPIFBlockDevice bd(
mbed_official 0:8e251d9511b8 230 - MBED_CONF_SPIF_DRIVER_SPI_MOSI,
mbed_official 0:8e251d9511b8 231 - MBED_CONF_SPIF_DRIVER_SPI_MISO,
mbed_official 0:8e251d9511b8 232 - MBED_CONF_SPIF_DRIVER_SPI_CLK,
mbed_official 0:8e251d9511b8 233 - MBED_CONF_SPIF_DRIVER_SPI_CS);
mbed_official 0:8e251d9511b8 234 +SDBlockDevice bd(
mbed_official 0:8e251d9511b8 235 + MBED_CONF_SD_SPI_MOSI,
mbed_official 0:8e251d9511b8 236 + MBED_CONF_SD_SPI_MISO,
mbed_official 0:8e251d9511b8 237 + MBED_CONF_SD_SPI_CLK,
mbed_official 0:8e251d9511b8 238 + MBED_CONF_SD_SPI_CS);
mbed_official 0:8e251d9511b8 239 ```
mbed_official 0:8e251d9511b8 240
mbed_official 2:6a0c72c9d3fb 241 **Note:** Most block devices require pin assignments. Double check that the
mbed_official 2:6a0c72c9d3fb 242 pins in `<driver>/mbed_lib.json` are correct. For example, to change the pins for the SD driver, open `sd-driver/config/mbed_lib.json`, and change your target platform to the correct pin-out in the `target_overrides` configuration:
mbed_official 2:6a0c72c9d3fb 243
mbed_official 2:6a0c72c9d3fb 244 ```
mbed_official 2:6a0c72c9d3fb 245 "target_overrides": {
mbed_official 2:6a0c72c9d3fb 246 ...
mbed_official 2:6a0c72c9d3fb 247 "NUCLEO_F429ZI": {
mbed_official 2:6a0c72c9d3fb 248 "SPI_MOSI": "PC_12",
mbed_official 2:6a0c72c9d3fb 249 "SPI_MISO": "PC_11",
mbed_official 2:6a0c72c9d3fb 250 "SPI_CLK": "PC_10",
mbed_official 2:6a0c72c9d3fb 251 "SPI_CS": "PA_15"
mbed_official 2:6a0c72c9d3fb 252 },
mbed_official 2:6a0c72c9d3fb 253 ...
mbed_official 2:6a0c72c9d3fb 254 }
mbed_official 2:6a0c72c9d3fb 255 ```
mbed_official 2:6a0c72c9d3fb 256
mbed_official 0:8e251d9511b8 257 Mbed OS has several options for the block device:
mbed_official 0:8e251d9511b8 258
mbed_official 0:8e251d9511b8 259 - **SPIFBlockDevice** - Block device driver for NOR-based SPI flash devices that
mbed_official 1:2bfc377bcc2a 260 support SFDP. NOR-based SPI flash supports byte-sized read and writes, with an
mbed_official 1:2bfc377bcc2a 261 erase size of about 4kbytes. An erase sets a block to all 1s, with successive
mbed_official 1:2bfc377bcc2a 262 writes clearing set bits.
mbed_official 1:2bfc377bcc2a 263
mbed_official 1:2bfc377bcc2a 264 ``` cpp
mbed_official 1:2bfc377bcc2a 265 SPIFBlockDevice bd(
mbed_official 1:2bfc377bcc2a 266 MBED_CONF_SPIF_DRIVER_SPI_MOSI,
mbed_official 1:2bfc377bcc2a 267 MBED_CONF_SPIF_DRIVER_SPI_MISO,
mbed_official 1:2bfc377bcc2a 268 MBED_CONF_SPIF_DRIVER_SPI_CLK,
mbed_official 1:2bfc377bcc2a 269 MBED_CONF_SPIF_DRIVER_SPI_CS);
mbed_official 1:2bfc377bcc2a 270 ```
mbed_official 0:8e251d9511b8 271
mbed_official 0:8e251d9511b8 272 - **DataFlashBlockDevice** - Block device driver for NOR-based SPI flash devices
mbed_official 1:2bfc377bcc2a 273 that support the DataFlash protocol, such as the Adesto AT45DB series of
mbed_official 1:2bfc377bcc2a 274 devices. DataFlash is a memory protocol that combines flash with SRAM buffers
mbed_official 1:2bfc377bcc2a 275 for a programming interface. DataFlash supports byte-sized read and writes, with
mbed_official 1:2bfc377bcc2a 276 an erase size of about 528 bytes or sometimes 1056 bytes. DataFlash provides
mbed_official 1:2bfc377bcc2a 277 erase sizes with an extra 16 bytes for error correction codes (ECC), so a flash
mbed_official 1:2bfc377bcc2a 278 translation layer (FTL) may still present 512 byte erase sizes.
mbed_official 1:2bfc377bcc2a 279
mbed_official 1:2bfc377bcc2a 280 ``` cpp
mbed_official 1:2bfc377bcc2a 281 DataFlashBlockDevice bd(
mbed_official 1:2bfc377bcc2a 282 MBED_CONF_DATAFLASH_SPI_MOSI,
mbed_official 1:2bfc377bcc2a 283 MBED_CONF_DATAFLASH_SPI_MISO,
mbed_official 1:2bfc377bcc2a 284 MBED_CONF_DATAFLASH_SPI_CLK,
mbed_official 1:2bfc377bcc2a 285 MBED_CONF_DATAFLASH_SPI_CS);
mbed_official 1:2bfc377bcc2a 286 ```
mbed_official 0:8e251d9511b8 287
mbed_official 0:8e251d9511b8 288 - **SDBlockDevice** - Block device driver for SD cards and eMMC memory chips. SD
mbed_official 1:2bfc377bcc2a 289 cards or eMMC chips offer a full FTL layer on top of NAND flash. This makes the
mbed_official 1:2bfc377bcc2a 290 storage well-suited for systems that require a about 1GB of memory.
mbed_official 1:2bfc377bcc2a 291 Additionally, SD cards are a popular form of portable storage. They are useful
mbed_official 1:2bfc377bcc2a 292 if you want to store data that you can access from a PC.
mbed_official 1:2bfc377bcc2a 293
mbed_official 1:2bfc377bcc2a 294 ``` cpp
mbed_official 1:2bfc377bcc2a 295 SDBlockDevice bd(
mbed_official 1:2bfc377bcc2a 296 MBED_CONF_SD_SPI_MOSI,
mbed_official 1:2bfc377bcc2a 297 MBED_CONF_SD_SPI_MISO,
mbed_official 1:2bfc377bcc2a 298 MBED_CONF_SD_SPI_CLK,
mbed_official 1:2bfc377bcc2a 299 MBED_CONF_SD_SPI_CS);
mbed_official 1:2bfc377bcc2a 300 ```
mbed_official 0:8e251d9511b8 301
mbed_official 0:8e251d9511b8 302 - [**HeapBlockDevice**](https://os.mbed.com/docs/v5.6/reference/heapblockdevice.html) -
mbed_official 0:8e251d9511b8 303 Block device that simulates storage in RAM using the heap. Do not use the heap
mbed_official 0:8e251d9511b8 304 block device for storing data persistently because a power loss causes
mbed_official 0:8e251d9511b8 305 complete loss of data. Instead, use it fortesting applications when a storage
mbed_official 0:8e251d9511b8 306 device is not available.
mbed_official 1:2bfc377bcc2a 307
mbed_official 1:2bfc377bcc2a 308 ``` cpp
mbed_official 1:2bfc377bcc2a 309 HeapBlockDevice bd(1024*512, 512);
mbed_official 1:2bfc377bcc2a 310 ```
mbed_official 0:8e251d9511b8 311
mbed_official 0:8e251d9511b8 312 Additionally, Mbed OS contains several utility block devices to give you better
mbed_official 0:8e251d9511b8 313 control over the allocation of storage.
mbed_official 0:8e251d9511b8 314
mbed_official 1:2bfc377bcc2a 315 - [**SlicingBlockDevice**](https://os.mbed.com/docs/latest/reference/slicingblockdevice.html) -
mbed_official 0:8e251d9511b8 316 With the slicing block device, you can partition storage into smaller block
mbed_official 0:8e251d9511b8 317 devices that you can use independently.
mbed_official 0:8e251d9511b8 318
mbed_official 1:2bfc377bcc2a 319 - [**ChainingBlockDevice**](https://os.mbed.com/docs/latest/reference/chainingblockdevice.html) -
mbed_official 0:8e251d9511b8 320 With the chaining block device, you can chain multiple block devices together
mbed_official 0:8e251d9511b8 321 and extend the usable amount of storage.
mbed_official 0:8e251d9511b8 322
mbed_official 1:2bfc377bcc2a 323 - [**MBRBlockDevice**](https://os.mbed.com/docs/latest/reference/mbrblockdevice.html) -
mbed_official 0:8e251d9511b8 324 Mbed OS comes with support for storing partitions on disk with a Master Boot
mbed_official 0:8e251d9511b8 325 Record (MBR). The MBRBlockDevice provides this functionality and supports
mbed_official 0:8e251d9511b8 326 creating partitions at runtime or using preformatted partitions configured
mbed_official 0:8e251d9511b8 327 separately from outside the application.
mbed_official 0:8e251d9511b8 328
mbed_official 0:8e251d9511b8 329 - **ReadOnlyBlockDevice** - With the read-only block device, you can wrap a
mbed_official 0:8e251d9511b8 330 block device in a read-only layer, ensuring that user of the block device does
mbed_official 0:8e251d9511b8 331 not modify the storage.
mbed_official 0:8e251d9511b8 332
mbed_official 0:8e251d9511b8 333 - **ProfilingBlockDevice** - With the profiling block device, you can profile
mbed_official 0:8e251d9511b8 334 the quantity of erase, program and read operations that are incurred on a
mbed_official 0:8e251d9511b8 335 block device.
mbed_official 0:8e251d9511b8 336
mbed_official 0:8e251d9511b8 337 - **ObservingBlockDevice** - The observing block device grants the user the
mbed_official 0:8e251d9511b8 338 ability to register a callback on block device operations. You can use this to
mbed_official 0:8e251d9511b8 339 inspect the state of the block device, log different metrics or perform some
mbed_official 0:8e251d9511b8 340 other operation.
mbed_official 0:8e251d9511b8 341
mbed_official 0:8e251d9511b8 342 - **ExhaustibleBlockDevice** - Useful for evaluating how file systems respond to
mbed_official 0:8e251d9511b8 343 wear, the exhaustible block device simulates wear on another form of storage.
mbed_official 0:8e251d9511b8 344 You can configure it to expire blocks as necessary.
mbed_official 0:8e251d9511b8 345
mbed_official 1:2bfc377bcc2a 346 ## Tested configurations
mbed_official 1:2bfc377bcc2a 347
mbed_official 1:2bfc377bcc2a 348 - K64F + Heap + LittleFS
mbed_official 1:2bfc377bcc2a 349 - K64F + Heap + FATFS
mbed_official 1:2bfc377bcc2a 350 - K64F + SD + LittleFS
mbed_official 1:2bfc377bcc2a 351 - K64F + SD + FATFS
mbed_official 1:2bfc377bcc2a 352 - K64F + SPIF (requires shield) + LittleFS
mbed_official 1:2bfc377bcc2a 353 - K64F + SPIF (requires shield) + FATFS
mbed_official 1:2bfc377bcc2a 354 - K64F + DataFlash (requires shield) + LittleFS
mbed_official 1:2bfc377bcc2a 355 - K64F + DataFlash (requires shield) + FATFS
mbed_official 1:2bfc377bcc2a 356 - UBLOX_EVK_ODIN_W2 + Heap + LittleFS
mbed_official 1:2bfc377bcc2a 357 - UBLOX_EVK_ODIN_W2 + Heap + FATFS
mbed_official 1:2bfc377bcc2a 358 - UBLOX_EVK_ODIN_W2 + SD + LittleFS
mbed_official 1:2bfc377bcc2a 359 - UBLOX_EVK_ODIN_W2 + SD + FATFS
mbed_official 1:2bfc377bcc2a 360 - UBLOX_EVK_ODIN_W2 + SPIF (requires shield) + LittleFS
mbed_official 1:2bfc377bcc2a 361 - UBLOX_EVK_ODIN_W2 + SPIF (requires shield) + FATFS
mbed_official 1:2bfc377bcc2a 362 - UBLOX_EVK_ODIN_W2 + DataFlash (requires shield) + LittleFS
mbed_official 1:2bfc377bcc2a 363 - UBLOX_EVK_ODIN_W2 + DataFlash (requires shield) + FATFS
mbed_official 1:2bfc377bcc2a 364 - NUCLEO_F429ZI + Heap + LittleFS
mbed_official 1:2bfc377bcc2a 365 - NUCLEO_F429ZI + Heap + FATFS
mbed_official 1:2bfc377bcc2a 366 - NUCLEO_F429ZI + SD (requires shield) + LittleFS
mbed_official 1:2bfc377bcc2a 367 - NUCLEO_F429ZI + SD (requires shield) + FATFS
mbed_official 1:2bfc377bcc2a 368 - NUCLEO_F429ZI + SPIF (requires shield) + LittleFS
mbed_official 1:2bfc377bcc2a 369 - NUCLEO_F429ZI + SPIF (requires shield) + FATFS
mbed_official 1:2bfc377bcc2a 370 - NUCLEO_F429ZI + DataFlash (requires shield) + LittleFS
mbed_official 1:2bfc377bcc2a 371 - NUCLEO_F429ZI + DataFlash (requires shield) + FATFS