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

Files at this revision

API Documentation at this revision

Comitter:
maclobdell
Date:
Wed Mar 20 23:20:41 2019 -0400
Commit message:
Customized for LPC55S69.

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
.travis.yml Show annotated file Show diff for this revision Revisions of this file
LICENSE.md Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
sdio-driver.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Wed Mar 20 23:20:41 2019 -0400
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.travis.yml	Wed Mar 20 23:20:41 2019 -0400
@@ -0,0 +1,64 @@
+language: python
+python: 2.7
+dist: trusty
+
+env:
+  global:
+    - >
+      STATUS=$'curl -so/dev/null --user $MBED_BOT --request POST
+      https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT}
+      --data @- << DATA\n{
+      "state": "$0",
+      "description": "$1",
+      "context": "travis-ci/$TARGET",
+      "target_url": "https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID"
+      }\nDATA'
+
+
+cache:
+  pip: true
+  directories:
+    - $HOME/.cache/apt
+
+after_success:
+  - bash -c "$STATUS" success "Build $TARGET has passed"
+
+after_failure:
+  - bash -c "$STATUS" failure "Build $TARGET has failed"
+
+before_install:
+  - bash -c "$STATUS" pending "Build $TARGET in progress"
+  # Make sure pipefail
+  - set -o pipefail
+  # Setup apt to cache
+  - mkdir -p $HOME/.cache/apt/partial
+  - sudo rm -rf /var/cache/apt/archives
+  - sudo ln -s $HOME/.cache/apt /var/cache/apt/archives
+  # Setup ppa to make sure arm-none-eabi-gcc is correct version
+  - sudo add-apt-repository -y ppa:team-gcc-arm-embedded/ppa
+  - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 762E3157
+  - travis_retry $(! sudo apt-get update 2>&1 | grep FAILED )
+
+install:
+  # Print versions we use
+  - gcc --version
+  - python --version
+  # Install dependencies
+  - sudo apt-get install gcc-arm-embedded
+  - arm-none-eabi-gcc --version
+  # Deploy mbed and pip dependencies
+  - pip install mbed-cli
+  - mbed deploy --verbose
+  - pip install -r mbed-os/requirements.txt
+
+script:
+  # Check that example compiles with littlefs + spif
+  - mbed compile -t GCC_ARM -m K82F -j0
+
+  # Check that example compiles with fatfs + HeapBlockDevice
+  - sed -i 's/BlockDevice.h/HeapBlockDevice.h/g' main.cpp
+  - sed -i 's/BlockDevice::get_default_instance()/new HeapBlockDevice(2048, 1, 1, 512)/g' main.cpp
+  - sed -i 's/LittleFileSystem/FATFileSystem/g' main.cpp
+  - mbed compile -t GCC_ARM -m K64F -j0
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LICENSE.md	Wed Mar 20 23:20:41 2019 -0400
@@ -0,0 +1,165 @@
+Apache License
+Version 2.0, January 2004
+http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and
+distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright
+owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities
+that control, are controlled by, or are under common control with that entity.
+For the purposes of this definition, "control" means (i) the power, direct or
+indirect, to cause the direction or management of such entity, whether by
+contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
+outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising
+permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including
+but not limited to software source code, documentation source, and configuration
+files.
+
+"Object" form shall mean any form resulting from mechanical transformation or
+translation of a Source form, including but not limited to compiled object code,
+generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made
+available under the License, as indicated by a copyright notice that is included
+in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that
+is based on (or derived from) the Work and for which the editorial revisions,
+annotations, elaborations, or other modifications represent, as a whole, an
+original work of authorship. For the purposes of this License, Derivative Works
+shall not include works that remain separable from, or merely link (or bind by
+name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version
+of the Work and any modifications or additions to that Work or Derivative Works
+thereof, that is intentionally submitted to Licensor for inclusion in the Work
+by the copyright owner or by an individual or Legal Entity authorized to submit
+on behalf of the copyright owner. For the purposes of this definition,
+"submitted" means any form of electronic, verbal, or written communication sent
+to the Licensor or its representatives, including but not limited to
+communication on electronic mailing lists, source code control systems, and
+issue tracking systems that are managed by, or on behalf of, the Licensor for
+the purpose of discussing and improving the Work, but excluding communication
+that is conspicuously marked or otherwise designated in writing by the copyright
+owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
+of whom a Contribution has been received by Licensor and subsequently
+incorporated within the Work.
+
+2. Grant of Copyright License.
+
+Subject to the terms and conditions of this License, each Contributor hereby
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
+irrevocable copyright license to reproduce, prepare Derivative Works of,
+publicly display, publicly perform, sublicense, and distribute the Work and such
+Derivative Works in Source or Object form.
+
+3. Grant of Patent License.
+
+Subject to the terms and conditions of this License, each Contributor hereby
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
+irrevocable (except as stated in this section) patent license to make, have
+made, use, offer to sell, sell, import, and otherwise transfer the Work, where
+such license applies only to those patent claims licensable by such Contributor
+that are necessarily infringed by their Contribution(s) alone or by combination
+of their Contribution(s) with the Work to which such Contribution(s) was
+submitted. If You institute patent litigation against any entity (including a
+cross-claim or counterclaim in a lawsuit) alleging that the Work or a
+Contribution incorporated within the Work constitutes direct or contributory
+patent infringement, then any patent licenses granted to You under this License
+for that Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution.
+
+You may reproduce and distribute copies of the Work or Derivative Works thereof
+in any medium, with or without modifications, and in Source or Object form,
+provided that You meet the following conditions:
+
+You must give any other recipients of the Work or Derivative Works a copy of
+this License; and
+You must cause any modified files to carry prominent notices stating that You
+changed the files; and
+You must retain, in the Source form of any Derivative Works that You distribute,
+all copyright, patent, trademark, and attribution notices from the Source form
+of the Work, excluding those notices that do not pertain to any part of the
+Derivative Works; and
+If the Work includes a "NOTICE" text file as part of its distribution, then any
+Derivative Works that You distribute must include a readable copy of the
+attribution notices contained within such NOTICE file, excluding those notices
+that do not pertain to any part of the Derivative Works, in at least one of the
+following places: within a NOTICE text file distributed as part of the
+Derivative Works; within the Source form or documentation, if provided along
+with the Derivative Works; or, within a display generated by the Derivative
+Works, if and wherever such third-party notices normally appear. The contents of
+the NOTICE file are for informational purposes only and do not modify the
+License. You may add Your own attribution notices within Derivative Works that
+You distribute, alongside or as an addendum to the NOTICE text from the Work,
+provided that such additional attribution notices cannot be construed as
+modifying the License.
+You may add Your own copyright statement to Your modifications and may provide
+additional or different license terms and conditions for use, reproduction, or
+distribution of Your modifications, or for any such Derivative Works as a whole,
+provided Your use, reproduction, and distribution of the Work otherwise complies
+with the conditions stated in this License.
+
+5. Submission of Contributions.
+
+Unless You explicitly state otherwise, any Contribution intentionally submitted
+for inclusion in the Work by You to the Licensor shall be under the terms and
+conditions of this License, without any additional terms or conditions.
+Notwithstanding the above, nothing herein shall supersede or modify the terms of
+any separate license agreement you may have executed with Licensor regarding
+such Contributions.
+
+6. Trademarks.
+
+This License does not grant permission to use the trade names, trademarks,
+service marks, or product names of the Licensor, except as required for
+reasonable and customary use in describing the origin of the Work and
+reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty.
+
+Unless required by applicable law or agreed to in writing, Licensor provides the
+Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+including, without limitation, any warranties or conditions of TITLE,
+NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
+solely responsible for determining the appropriateness of using or
+redistributing the Work and assume any risks associated with Your exercise of
+permissions under this License.
+
+8. Limitation of Liability.
+
+In no event and under no legal theory, whether in tort (including negligence),
+contract, or otherwise, unless required by applicable law (such as deliberate
+and grossly negligent acts) or agreed to in writing, shall any Contributor be
+liable to You for damages, including any direct, indirect, special, incidental,
+or consequential damages of any character arising as a result of this License or
+out of the use or inability to use the Work (including but not limited to
+damages for loss of goodwill, work stoppage, computer failure or malfunction, or
+any and all other commercial damages or losses), even if such Contributor has
+been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability.
+
+While redistributing the Work or Derivative Works thereof, You may choose to
+offer, and charge a fee for, acceptance of support, warranty, indemnity, or
+other liability obligations and/or rights consistent with this License. However,
+in accepting such obligations, You may act only on Your own behalf and on Your
+sole responsibility, not on behalf of any other Contributor, and only if You
+agree to indemnify, defend, and hold each Contributor harmless for any liability
+incurred by, or claims asserted against, such Contributor by reason of your
+accepting any such warranty or additional liability.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Wed Mar 20 23:20:41 2019 -0400
@@ -0,0 +1,454 @@
+# Getting started with the Mbed OS file system
+
+This example demonstrates how to use the Mbed OS file system.
+
+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).
+
+**Table of contents:**
+
+1. [Hardware requirements](#hardware-requirements)
+1. [Usage](#usage)
+   - [Import the example](#import-the-example)
+   - [Compile the example](#compile-the-example)
+   - [Run the example](#run-the-example)
+   - [Troubleshooting](#troubleshooting)
+1. [Changing the file system](#changing-the-file-system)
+1. [Changing the block device](#changing-the-block-device)
+1. [Tested configurations](#tested-configurations)
+
+## Hardware requirements
+
+This example uses a block device as storage. This can be one of:
+
+* A built-in SPI flash, such as on the [FRDM-K82F](https://os.mbed.com/platforms/FRDM-K82F/).
+* An external block device (one of SPI flash, DataFlash or an SD card). 
+* Simulated on a heap block device on boards with enough RAM.
+
+This example uses an instance of the LittleFileSystem API (LittleFS) on external SPI flash.
+The [changing the block device](#changing-the-block-device) section describes
+how to change the file system or block device in the example.
+
+## Usage
+
+#### Import the example
+
+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)
+to set everything up.
+
+From the command-line, import the example:
+
+```
+mbed import mbed-os-example-filesystem
+cd mbed-os-example-filesystem
+```
+
+#### Compile the example
+
+Invoke `mbed compile`, and specify the name of your platform and your favorite
+toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
+
+```
+mbed compile -m K64F -t ARM
+```
+
+Your PC may take a few minutes to compile your code. At the end, you see the
+following result:
+
+```
+[snip]
++--------------------------+-------+-------+-------+
+| Module                   | .text | .data |  .bss |
++--------------------------+-------+-------+-------+
+| Fill                     |   164 |     0 |  2136 |
+| Misc                     | 54505 |  2556 |   754 |
+| drivers                  |   640 |     0 |    32 |
+| features/filesystem      | 15793 |     0 |   550 |
+| features/storage         |    42 |     0 |   184 |
+| hal                      |   418 |     0 |     8 |
+| platform                 |  2355 |    20 |   582 |
+| rtos                     |   135 |     4 |     4 |
+| rtos/rtx                 |  5861 |    20 |  6870 |
+| targets/TARGET_Freescale |  8382 |    12 |   384 |
+| Subtotals                | 88295 |  2612 | 11504 |
++--------------------------+-------+-------+-------+
+Allocated Heap: 24576 bytes
+Allocated Stack: unknown
+Total Static RAM memory (data + bss): 14116 bytes
+Total RAM memory (data + bss + heap + stack): 38692 bytes
+Total Flash memory (text + data + misc): 91947 bytes
+
+Image: ./BUILD/K64F/ARM/mbed-os-example-filesystem.bin
+```
+
+#### Run the example
+
+1. Connect your Mbed Enabled device to the computer over USB.
+1. Copy the binary file to the Mbed Enabled device.
+1. Press the reset button to start the program.
+1. Open the UART of the board in your favorite UART viewing program. For
+   example, `screen /dev/ttyACM0`.
+   
+**Note:** The default serial port baud rate is 9600 bit/s.
+
+Expected output:
+
+```
+--- Mbed OS filesystem example ---
+Mounting the filesystem... Fail :(
+No filesystem found, formatting... OK
+Opening "/fs/numbers.txt"... Fail :(
+No file found, creating a new file... OK
+Writing numbers (10/10)... OK
+Seeking file... OK
+Incrementing numbers (10/10)... OK
+Closing "/fs/numbers.txt"... OK
+Opening the root directory... OK
+root directory:
+    .
+    ..
+    numbers.txt
+Closing the root directory... OK
+Opening "/fs/numbers.txt"...OK
+numbers:
+    1
+    2
+    3
+    4
+    5
+    6
+    7
+    8
+    9
+    10
+Closing "/fs/numbers.txt"... OK
+Unmounting... OK
+Mbed OS filesystem example done!
+```
+
+You can also reset the board to see the data persist across boots. Each boot
+increments the numbers stored on disk:
+
+```
+--- Mbed OS filesystem example ---
+Mounting the filesystem... OK
+Opening "/fs/numbers.txt"... OK
+Incrementing numbers (10/10)... OK
+Closing "/fs/numbers.txt"... OK
+Opening the root directory... OK
+root directory:
+    .
+    ..
+    numbers.txt
+Closing the root directory... OK
+Opening "/fs/numbers.txt"...OK
+numbers:
+    2
+    3
+    4
+    5
+    6
+    7
+    8
+    9
+    10
+    11
+Closing "/fs/numbers.txt"... OK
+Unmounting... OK
+Mbed OS filesystem example done!
+```
+
+If you find yourself with a corrupted file system, you can reset the storage
+by pressing BUTTON1:
+
+```
+Initializing the block device... OK
+Erasing the block device... OK
+Deinitializing the block device... OK
+```
+
+Note that if you press the reset button at the wrong time, you may corrupt
+a file system that is not power resilient!
+
+#### Troubleshooting
+
+If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html)
+for suggestions on what could be wrong and how to fix it.
+
+## Changing the file system
+
+In Mbed OS, a C++ classes that inherits from the [FileSystem](https://os.mbed.com/docs/latest/reference/storage.html#declaring-a-file-system)
+interface represents each file system. You can change the file system in the
+example by changing the class declared in main.cpp.
+
+``` diff
+- LittleFileSystem fs("fs");
++ FATFileSystem fs("fs");
+```
+
+**Note:** Different file systems require different minimum numbers of storage
+blocks to function. For the `FATFileSystem`, this example requires a minimum of
+256 blocks, and for the `LittleFileSystem`, this example requires a minimum of 6
+blocks. You can find the number of blocks on a block device by dividing the
+block device's size by its erase size.
+
+Mbed OS has two options for the file system:
+
+- [**LittleFileSystem**](https://os.mbed.com/docs/latest/reference/littlefilesystem.html) -
+  The little file system is a fail-safe file system we designed
+  for embedded systems, specifically for microcontrollers that use flash
+  storage.
+  
+  ``` cpp
+  LittleFileSystem fs("fs");
+  ```
+
+  - **Bounded RAM/ROM** - This file system works with a limited amount of memory.
+    It avoids recursion and limits dynamic memory to configurable
+    buffers.
+  
+  - **Power-loss resilient** - We designed this for operating systems
+    that may have random power failures. It has strong copy-on-write
+    guarantees and keeps storage on disk in a valid state.
+  
+  - **Wear leveling** - Because the most common form of embedded storage is
+    erodible flash memories, this file system provides a form of dynamic wear
+    leveling for systems that cannot fit a full flash translation layer.
+
+- **FATFileSystem** - The FAT file system is a well-known file system that you
+  can find on almost every system, including PCs. The Mbed OS implementation of
+  the FAT file system is based on ChanFS and is optimized for small embedded systems.
+  
+  ``` cpp
+  FATFileSystem fs("fs");
+  ```
+
+  - **Portable** - Almost every operating system supports the FAT file system,
+    which is the most common file system found on portable storage, such as SD
+    cards and flash drives. The FAT file system is the easiest way to support
+    access from a PC.
+
+## Changing the block device
+
+In Mbed OS, a C++ classes that inherits from the [BlockDevice](https://os.mbed.com/docs/latest/reference/storage.html#block-devices)
+interface represents each block device. You can change the filesystem in the
+example by changing the class declared in main.cpp.
+
+``` diff
+-SPIFBlockDevice bd(
+-        MBED_CONF_SPIF_DRIVER_SPI_MOSI,
+-        MBED_CONF_SPIF_DRIVER_SPI_MISO,
+-        MBED_CONF_SPIF_DRIVER_SPI_CLK,
+-        MBED_CONF_SPIF_DRIVER_SPI_CS);
++SDBlockDevice bd(
++        MBED_CONF_SD_SPI_MOSI,
++        MBED_CONF_SD_SPI_MISO,
++        MBED_CONF_SD_SPI_CLK,
++        MBED_CONF_SD_SPI_CS);
+```
+
+**Note:** Most block devices require pin assignments. Double check that the
+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:
+
+```
+   "target_overrides": {
+         ...
+         "NUCLEO_F429ZI": {
+             "SPI_MOSI": "PC_12",
+             "SPI_MISO": "PC_11",
+             "SPI_CLK":  "PC_10",
+             "SPI_CS":   "PA_15"
+         },
+         ...
+     }
+```
+The pins macros define above can be override at the application configuration file using the driver prefix before the parameter name.
+```
+   "target_overrides": {
+         ...
+         "NUCLEO_F429ZI": {
+             "spif-driver.SPI_MOSI": "PC_12",
+             "spif-driver.SPI_MISO": "PC_11",
+             "spif-driver.SPI_CLK":  "PC_10",
+             "spif-driver.SPI_CS":   "PA_15"
+         },
+         ...
+     }
+```
+or 
+```
+   "target_overrides": {
+         ...
+         "NUCLEO_F429ZI": {
+             "sd.SPI_MOSI": "PC_12",
+             "sd.SPI_MISO": "PC_11",
+             "sd.SPI_CLK":  "PC_10",
+             "sd.SPI_CS":   "PA_15"
+         },
+         ...
+     }
+```
+
+Mbed OS has several options for the block device:
+
+- **SPIFBlockDevice** - Block device driver for NOR-based SPI flash devices that
+  support SFDP. NOR-based SPI flash supports byte-sized read and writes, with an
+  erase size of about 4kbytes. An erase sets a block to all 1s, with successive
+  writes clearing set bits.
+
+  ``` cpp
+  SPIFBlockDevice bd(
+          MBED_CONF_SPIF_DRIVER_SPI_MOSI,
+          MBED_CONF_SPIF_DRIVER_SPI_MISO,
+          MBED_CONF_SPIF_DRIVER_SPI_CLK,
+          MBED_CONF_SPIF_DRIVER_SPI_CS);
+  ```
+
+  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:
+```
+  "target_overrides": {
+         ...
+         "NUCLEO_F429ZI": {
+             "target.components_add": ["SPIF"],
+             ...
+         },
+         ...
+  }
+```
+
+- **DataFlashBlockDevice** - Block device driver for NOR-based SPI flash devices
+  that support the DataFlash protocol, such as the Adesto AT45DB series of
+  devices. DataFlash is a memory protocol that combines flash with SRAM buffers
+  for a programming interface. DataFlash supports byte-sized read and writes, with
+  an erase size of about 528 bytes or sometimes 1056 bytes. DataFlash provides
+  erase sizes with an extra 16 bytes for error correction codes (ECC), so a flash
+  translation layer (FTL) may still present 512 byte erase sizes.
+  
+  ``` cpp
+  DataFlashBlockDevice bd(
+          MBED_CONF_DATAFLASH_SPI_MOSI,
+          MBED_CONF_DATAFLASH_SPI_MISO,
+          MBED_CONF_DATAFLASH_SPI_CLK,
+          MBED_CONF_DATAFLASH_SPI_CS);
+  ```
+
+  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:
+```
+  "target_overrides": {
+         ...
+         "NUCLEO_F429ZI": {
+             "target.components_add": ["DATAFLASH"],
+             ...
+         },
+         ...
+  }
+```
+
+- **SDBlockDevice** - Block device driver for SD cards and eMMC memory chips. SD
+  cards or eMMC chips offer a full FTL layer on top of NAND flash. This makes the
+  storage well-suited for systems that require a about 1GB of memory.
+  Additionally, SD cards are a popular form of portable storage. They are useful
+  if you want to store data that you can access from a PC.
+  
+  ``` cpp
+  SDBlockDevice bd(
+          MBED_CONF_SD_SPI_MOSI,
+          MBED_CONF_SD_SPI_MISO,
+          MBED_CONF_SD_SPI_CLK,
+          MBED_CONF_SD_SPI_CS);
+  ```
+
+  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:
+```
+  "target_overrides": {
+         ...
+         "NUCLEO_F429ZI": {
+             "target.components_add": ["SD"],
+             ...
+         },
+         ...
+  }
+```
+
+- [**HeapBlockDevice**](https://os.mbed.com/docs/v5.6/reference/heapblockdevice.html) -
+  Block device that simulates storage in RAM using the heap. Do not use the heap
+  block device for storing data persistently because a power loss causes
+  complete loss of data. Instead, use it fortesting applications when a storage
+  device is not available.
+  
+  ``` cpp
+  HeapBlockDevice bd(1024*512, 512);
+  ```
+
+Additionally, Mbed OS contains several utility block devices to give you better
+control over the allocation of storage.
+
+- [**SlicingBlockDevice**](https://os.mbed.com/docs/latest/reference/slicingblockdevice.html) -
+  With the slicing block device, you can partition storage into smaller block
+  devices that you can use independently.
+
+- [**ChainingBlockDevice**](https://os.mbed.com/docs/latest/reference/chainingblockdevice.html) -
+  With the chaining block device, you can chain multiple block devices together
+  and extend the usable amount of storage.
+
+- [**MBRBlockDevice**](https://os.mbed.com/docs/latest/reference/mbrblockdevice.html) -
+  Mbed OS comes with support for storing partitions on disk with a Master Boot
+  Record (MBR). The MBRBlockDevice provides this functionality and supports
+  creating partitions at runtime or using preformatted partitions configured
+  separately from outside the application.
+
+- **ReadOnlyBlockDevice** - With the read-only block device, you can wrap a
+  block device in a read-only layer, ensuring that user of the block device does
+  not modify the storage.
+
+- **ProfilingBlockDevice** - With the profiling block device, you can profile
+  the quantity of erase, program and read operations that are incurred on a
+  block device.
+
+- **ObservingBlockDevice** - The observing block device grants the user the
+  ability to register a callback on block device operations. You can use this to
+  inspect the state of the block device, log different metrics or perform some
+  other operation.
+
+- **ExhaustibleBlockDevice** - Useful for evaluating how file systems respond to
+  wear, the exhaustible block device simulates wear on another form of storage.
+  You can configure it to expire blocks as necessary.
+
+## Tested configurations
+
+- K64F + Heap + LittleFS
+- K64F + Heap + FATFS
+- K64F + SD + LittleFS
+- K64F + SD + FATFS
+- K64F + SPIF (requires shield) + LittleFS
+- K64F + SPIF (requires shield) + FATFS
+- K64F + DataFlash (requires shield) + LittleFS
+- K64F + DataFlash (requires shield) + FATFS
+- UBLOX_EVK_ODIN_W2 \[1\] + Heap + LittleFS
+- UBLOX_EVK_ODIN_W2 \[1\] + Heap + FATFS
+- UBLOX_EVK_ODIN_W2 \[1\] + SD + LittleFS
+- UBLOX_EVK_ODIN_W2 \[1\] + SD + FATFS
+- UBLOX_EVK_ODIN_W2 \[1\] + SPIF (requires shield) + LittleFS
+- UBLOX_EVK_ODIN_W2 \[1\] + SPIF (requires shield) + FATFS
+- UBLOX_EVK_ODIN_W2 \[1\] + DataFlash (requires shield) + LittleFS
+- UBLOX_EVK_ODIN_W2 \[1\] + DataFlash (requires shield) + FATFS
+- NUCLEO_F429ZI + Heap + LittleFS
+- NUCLEO_F429ZI + Heap + FATFS
+- NUCLEO_F429ZI + SD (requires shield) + LittleFS
+- NUCLEO_F429ZI + SD (requires shield) + FATFS
+- NUCLEO_F429ZI + SPIF (requires shield) + LittleFS
+- NUCLEO_F429ZI + SPIF (requires shield) + FATFS
+- NUCLEO_F429ZI + DataFlash (requires shield) + LittleFS
+- NUCLEO_F429ZI + DataFlash (requires shield) + FATFS
+
+\[1\]: Note: The UBLOX_EVK_ODIN_W2 SPI pins conflict with the default serial
+pins. A different set of serial pins must be selected to use SPI flash with
+serial output.
+
+```c++
+// Connect Tx, Rx, and ground pins to a separte board running the passthrough example:
+// https://os.mbed.com/users/sarahmarshy/code/SerialPassthrough/file/2a3a62ee17fa/main.cpp/
+Serial pc(TX, RX);   
+
+pc.printf("...");    // Replace printf with pc.printf in the example
+```
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Mar 20 23:20:41 2019 -0400
@@ -0,0 +1,226 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2019 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "mbed.h"
+#include <stdio.h>
+#include <errno.h>
+
+#include "BlockDevice.h"
+#include "SDIOBlockDevice.h"
+
+// This will take the system's default block device
+//BlockDevice *bd = BlockDevice::get_default_instance();
+BlockDevice *bd = new SDIOBlockDevice();
+
+// Instead of the default block device, you can define your own block device.
+// For example: HeapBlockDevice with size of 2048 bytes, read size 1, write size 1 and erase size 512.
+// #include "HeapBlockDevice.h"
+// BlockDevice *bd = new HeapBlockDevice(2048, 1, 1, 512);
+
+
+// This example uses LittleFileSystem as the default file system
+#include "LittleFileSystem.h"
+LittleFileSystem fs("fs");
+
+// Uncomment the following two lines and comment the previous two to use FAT file system.
+// #include "FATFileSystem.h"
+// FATFileSystem fs("fs");
+
+
+// Set up the button to trigger an erase
+//InterruptIn irq(BUTTON1);
+InterruptIn irq(SW2);
+
+void erase() {
+    printf("Initializing the block device... ");
+    fflush(stdout);
+    int err = bd->init();
+    printf("%s\n", (err ? "Fail :(" : "OK"));
+    if (err) {
+        error("error: %s (%d)\n", strerror(-err), err);
+    }
+
+    printf("Erasing the block device... ");
+    fflush(stdout);
+    err = bd->erase(0, bd->size());
+    printf("%s\n", (err ? "Fail :(" : "OK"));
+    if (err) {
+        error("error: %s (%d)\n", strerror(-err), err);
+    }
+
+    printf("Deinitializing the block device... ");
+    fflush(stdout);
+    err = bd->deinit();
+    printf("%s\n", (err ? "Fail :(" : "OK"));
+    if (err) {
+        error("error: %s (%d)\n", strerror(-err), err);
+    }
+}
+
+
+// Entry point for the example
+int main() {
+    printf("--- Mbed OS filesystem example ---\n");
+
+    // Setup the erase event on button press, use the event queue
+    // to avoid running in interrupt context
+    irq.fall(mbed_event_queue()->event(erase));
+
+    // Try to mount the filesystem
+    printf("Mounting the filesystem... ");
+    fflush(stdout);
+    int err = fs.mount(bd);
+    printf("%s\n", (err ? "Fail :(" : "OK"));
+    if (err) {
+        // Reformat if we can't mount the filesystem
+        // this should only happen on the first boot
+        printf("No filesystem found, formatting... ");
+        fflush(stdout);
+        err = fs.reformat(bd);
+        printf("%s\n", (err ? "Fail :(" : "OK"));
+        if (err) {
+            error("error: %s (%d)\n", strerror(-err), err);
+        }
+    }
+
+    // Open the numbers file
+    printf("Opening \"/fs/numbers.txt\"... ");
+    fflush(stdout);
+    FILE *f = fopen("/fs/numbers.txt", "r+");
+    printf("%s\n", (!f ? "Fail :(" : "OK"));
+    if (!f) {
+        // Create the numbers file if it doesn't exist
+        printf("No file found, creating a new file... ");
+        fflush(stdout);
+        f = fopen("/fs/numbers.txt", "w+");
+        printf("%s\n", (!f ? "Fail :(" : "OK"));
+        if (!f) {
+            error("error: %s (%d)\n", strerror(errno), -errno);
+        }
+
+        for (int i = 0; i < 10; i++) {
+            printf("\rWriting numbers (%d/%d)... ", i, 10);
+            fflush(stdout);
+            err = fprintf(f, "    %d\n", i);
+            if (err < 0) {
+                printf("Fail :(\n");
+                error("error: %s (%d)\n", strerror(errno), -errno);
+            }
+        }
+        printf("\rWriting numbers (%d/%d)... OK\n", 10, 10);
+
+        printf("Seeking file... ");
+        fflush(stdout);
+        err = fseek(f, 0, SEEK_SET);
+        printf("%s\n", (err < 0 ? "Fail :(" : "OK"));
+        if (err < 0) {
+            error("error: %s (%d)\n", strerror(errno), -errno);
+        }
+    }
+
+    // Go through and increment the numbers
+    for (int i = 0; i < 10; i++) {
+        printf("\rIncrementing numbers (%d/%d)... ", i, 10);
+        fflush(stdout);
+
+        // Get current stream position
+        long pos = ftell(f);
+
+        // Parse out the number and increment
+        int32_t number;
+        fscanf(f, "%d", &number);
+        number += 1;
+
+        // Seek to beginning of number
+        fseek(f, pos, SEEK_SET);
+    
+        // Store number
+        fprintf(f, "    %d\n", number);
+
+        // Flush between write and read on same file
+        fflush(f);
+    }
+    printf("\rIncrementing numbers (%d/%d)... OK\n", 10, 10);
+
+    // Close the file which also flushes any cached writes
+    printf("Closing \"/fs/numbers.txt\"... ");
+    fflush(stdout);
+    err = fclose(f);
+    printf("%s\n", (err < 0 ? "Fail :(" : "OK"));
+    if (err < 0) {
+        error("error: %s (%d)\n", strerror(errno), -errno);
+    }
+    
+    // Display the root directory
+    printf("Opening the root directory... ");
+    fflush(stdout);
+    DIR *d = opendir("/fs/");
+    printf("%s\n", (!d ? "Fail :(" : "OK"));
+    if (!d) {
+        error("error: %s (%d)\n", strerror(errno), -errno);
+    }
+
+    printf("root directory:\n");
+    while (true) {
+        struct dirent *e = readdir(d);
+        if (!e) {
+            break;
+        }
+
+        printf("    %s\n", e->d_name);
+    }
+
+    printf("Closing the root directory... ");
+    fflush(stdout);
+    err = closedir(d);
+    printf("%s\n", (err < 0 ? "Fail :(" : "OK"));
+    if (err < 0) {
+        error("error: %s (%d)\n", strerror(errno), -errno);
+    }
+
+    // Display the numbers file
+    printf("Opening \"/fs/numbers.txt\"... ");
+    fflush(stdout);
+    f = fopen("/fs/numbers.txt", "r");
+    printf("%s\n", (!f ? "Fail :(" : "OK"));
+    if (!f) {
+        error("error: %s (%d)\n", strerror(errno), -errno);
+    }
+
+    printf("numbers:\n");
+    while (!feof(f)) {
+        int c = fgetc(f);
+        printf("%c", c);
+    }
+
+    printf("\rClosing \"/fs/numbers.txt\"... ");
+    fflush(stdout);
+    err = fclose(f);
+    printf("%s\n", (err < 0 ? "Fail :(" : "OK"));
+    if (err < 0) {
+        error("error: %s (%d)\n", strerror(errno), -errno);
+    }
+
+    // Tidy up
+    printf("Unmounting... ");
+    fflush(stdout);
+    err = fs.unmount();
+    printf("%s\n", (err < 0 ? "Fail :(" : "OK"));
+    if (err < 0) {
+        error("error: %s (%d)\n", strerror(-err), err);
+    }
+        
+    printf("Mbed OS filesystem example done!\n");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Mar 20 23:20:41 2019 -0400
@@ -0,0 +1,2 @@
+https://github.com/ARMmbed/mbed-os/#c0939781ea1fa50657e055867193b62b1c9a6035
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Wed Mar 20 23:20:41 2019 -0400
@@ -0,0 +1,7 @@
+{
+    "target_overrides": {
+        "*": {
+            "platform.stdio-convert-newlines": true
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sdio-driver.lib	Wed Mar 20 23:20:41 2019 -0400
@@ -0,0 +1,1 @@
+https://github.com/NXPmicro/sdio-driver/#370c51a39582a5318e412095fc16f5ed3891ccb4