Filesystem example for LPC55S69 using on-board SD Card (SDIO).

Committer:
maclobdell
Date:
Wed Mar 20 23:20:41 2019 -0400
Revision:
0:ad2237362248
Customized for LPC55S69.

Who changed what in which revision?

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