.

Committer:
mbed_official
Date:
Thu May 10 05:16:42 2018 +0100
Revision:
15:9b74f9eb0a51
Parent:
13:8ff2772e836d
Merge pull request #51 from 0xc0170/master

Updating mbed-os to mbed-os-5.8.4
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-fat-filesystem

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 13:8ff2772e836d 1 # Obsolete
mbed_official 13:8ff2772e836d 2
mbed_official 13:8ff2772e836d 3 **The following application has superseded this repository:**
mbed_official 13:8ff2772e836d 4
mbed_official 13:8ff2772e836d 5 * [Mbed OS file system example](https://github.com/ARMmbed/mbed-os-example-filesystem)
mbed_official 0:ab69df6f1c47 6
mbed_official 13:8ff2772e836d 7 # Getting started with the FAT file system on Mbed OS
mbed_official 0:ab69df6f1c47 8
mbed_official 13:8ff2772e836d 9 This guide reviews the steps to get the FAT file system working on an Mbed OS platform.
mbed_official 13:8ff2772e836d 10
mbed_official 13:8ff2772e836d 11 Please install [Mbed CLI](https://os.mbed.com/docs/latest/tools/setup.html).
mbed_official 0:ab69df6f1c47 12
mbed_official 0:ab69df6f1c47 13 ## Hardware requirements
mbed_official 0:ab69df6f1c47 14
mbed_official 13:8ff2772e836d 15 This example uses a RAM-backed FAT file system. The FAT file system requires at least 128 512-byte blocks for a total of 64KB of space. The HeapBlockDevice, which uses a target's heap for storage, backs this space. Therefore, to support this example, a target must have at least 64KB of space usable by as heap. Because there is more than just the heap in a device's RAM, this translates to the requirement that a target's RAM must be at least 96KB large.
mbed_official 0:ab69df6f1c47 16
mbed_official 0:ab69df6f1c47 17 ## Import the example application
mbed_official 0:ab69df6f1c47 18
mbed_official 0:ab69df6f1c47 19 From the command-line, import the example:
mbed_official 0:ab69df6f1c47 20
mbed_official 0:ab69df6f1c47 21 ```
mbed_official 0:ab69df6f1c47 22 mbed import mbed-os-example-fat-filesystem
mbed_official 0:ab69df6f1c47 23 cd mbed-os-example-fat-filesystem
mbed_official 0:ab69df6f1c47 24 ```
mbed_official 0:ab69df6f1c47 25
mbed_official 0:ab69df6f1c47 26 ### Now compile
mbed_official 0:ab69df6f1c47 27
mbed_official 0:ab69df6f1c47 28 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_official 0:ab69df6f1c47 29
mbed_official 0:ab69df6f1c47 30 ```
mbed_official 0:ab69df6f1c47 31 mbed compile -m K64F -t ARM
mbed_official 0:ab69df6f1c47 32 ```
mbed_official 0:ab69df6f1c47 33
mbed_official 0:ab69df6f1c47 34 Your PC may take a few minutes to compile your code. At the end, you see the following result:
mbed_official 0:ab69df6f1c47 35
mbed_official 0:ab69df6f1c47 36 ```
mbed_official 0:ab69df6f1c47 37 [snip]
mbed_official 0:ab69df6f1c47 38 +--------------------------+-------+-------+-------+
mbed_official 0:ab69df6f1c47 39 | Module | .text | .data | .bss |
mbed_official 0:ab69df6f1c47 40 +--------------------------+-------+-------+-------+
mbed_official 0:ab69df6f1c47 41 | Fill | 164 | 0 | 2136 |
mbed_official 0:ab69df6f1c47 42 | Misc | 54505 | 2556 | 754 |
mbed_official 0:ab69df6f1c47 43 | drivers | 640 | 0 | 32 |
mbed_official 0:ab69df6f1c47 44 | features/filesystem | 15793 | 0 | 550 |
mbed_official 0:ab69df6f1c47 45 | features/storage | 42 | 0 | 184 |
mbed_official 0:ab69df6f1c47 46 | hal | 418 | 0 | 8 |
mbed_official 0:ab69df6f1c47 47 | platform | 2355 | 20 | 582 |
mbed_official 0:ab69df6f1c47 48 | rtos | 135 | 4 | 4 |
mbed_official 0:ab69df6f1c47 49 | rtos/rtx | 5861 | 20 | 6870 |
mbed_official 0:ab69df6f1c47 50 | targets/TARGET_Freescale | 8382 | 12 | 384 |
mbed_official 0:ab69df6f1c47 51 | Subtotals | 88295 | 2612 | 11504 |
mbed_official 0:ab69df6f1c47 52 +--------------------------+-------+-------+-------+
mbed_official 0:ab69df6f1c47 53 Allocated Heap: 24576 bytes
mbed_official 0:ab69df6f1c47 54 Allocated Stack: unknown
mbed_official 0:ab69df6f1c47 55 Total Static RAM memory (data + bss): 14116 bytes
mbed_official 0:ab69df6f1c47 56 Total RAM memory (data + bss + heap + stack): 38692 bytes
mbed_official 0:ab69df6f1c47 57 Total Flash memory (text + data + misc): 91947 bytes
mbed_official 0:ab69df6f1c47 58
mbed_official 0:ab69df6f1c47 59 Image: ./BUILD/K64F/gcc_arm/mbed-os-example-fat-filesystem.bin
mbed_official 0:ab69df6f1c47 60 ```
mbed_official 0:ab69df6f1c47 61
mbed_official 0:ab69df6f1c47 62 ### Program your board
mbed_official 0:ab69df6f1c47 63
mbed_official 13:8ff2772e836d 64 1. Connect your Mbed device to the computer over USB.
mbed_official 13:8ff2772e836d 65 1. Copy the binary file to the Mbed device.
mbed_official 0:ab69df6f1c47 66 1. Press the reset button to start the program.
mbed_official 0:ab69df6f1c47 67 1. Open the UART of the board in your favorite UART viewing program. For example, `screen /dev/ttyACM0`.
mbed_official 0:ab69df6f1c47 68
mbed_official 13:8ff2772e836d 69 **Note:** The default serial port baud rate is 9600 bit/s.
mbed_official 13:8ff2772e836d 70
mbed_official 0:ab69df6f1c47 71 You see the following output:
mbed_official 0:ab69df6f1c47 72
mbed_official 0:ab69df6f1c47 73 ```
mbed_official 0:ab69df6f1c47 74 Welcome to the filesystem example.
mbed_official 0:ab69df6f1c47 75 Formatting a FAT, RAM-backed filesystem. done.
mbed_official 0:ab69df6f1c47 76 Mounting the filesystem on "/fs". done.
mbed_official 0:ab69df6f1c47 77 Opening a new file, numbers.txt. done.
mbed_official 0:ab69df6f1c47 78 Writing decimal numbers to a file (20/20) done.
mbed_official 0:ab69df6f1c47 79 Closing file. done.
mbed_official 0:ab69df6f1c47 80 Re-opening file read-only. done.
mbed_official 0:ab69df6f1c47 81 Dumping file to screen.
mbed_official 0:ab69df6f1c47 82 0
mbed_official 0:ab69df6f1c47 83 1
mbed_official 0:ab69df6f1c47 84 2
mbed_official 0:ab69df6f1c47 85 3
mbed_official 0:ab69df6f1c47 86 4
mbed_official 0:ab69df6f1c47 87 5
mbed_official 0:ab69df6f1c47 88 6
mbed_official 0:ab69df6f1c47 89 7
mbed_official 0:ab69df6f1c47 90 8
mbed_official 0:ab69df6f1c47 91 9
mbed_official 0:ab69df6f1c47 92 10
mbed_official 0:ab69df6f1c47 93 11
mbed_official 0:ab69df6f1c47 94 12
mbed_official 0:ab69df6f1c47 95 13
mbed_official 0:ab69df6f1c47 96 14
mbed_official 0:ab69df6f1c47 97 15
mbed_official 0:ab69df6f1c47 98 16
mbed_official 0:ab69df6f1c47 99 17
mbed_official 0:ab69df6f1c47 100 18
mbed_official 0:ab69df6f1c47 101 19
mbed_official 0:ab69df6f1c47 102 EOF.
mbed_official 0:ab69df6f1c47 103 Closing file. done.
mbed_official 0:ab69df6f1c47 104 Opening root directory. done.
mbed_official 0:ab69df6f1c47 105 Printing all filenames:
mbed_official 0:ab69df6f1c47 106 numbers.txt
mbed_official 0:ab69df6f1c47 107 Closeing root directory. done.
mbed_official 0:ab69df6f1c47 108 Filesystem Demo complete.
mbed_official 0:ab69df6f1c47 109
mbed_official 0:ab69df6f1c47 110 ```
mbed_official 0:ab69df6f1c47 111
mbed_official 0:ab69df6f1c47 112 ## Switch from RAM backed block device to an SD card
mbed_official 0:ab69df6f1c47 113
mbed_official 0:ab69df6f1c47 114 From the command-line, run the following command:
mbed_official 0:ab69df6f1c47 115
mbed_official 0:ab69df6f1c47 116 ```bash
mbed_official 0:ab69df6f1c47 117 mbed add sd-driver
mbed_official 0:ab69df6f1c47 118 ```
mbed_official 0:ab69df6f1c47 119
mbed_official 0:ab69df6f1c47 120 Then change the code on line 3 of `main.cpp` to import the SD card header:
mbed_official 0:ab69df6f1c47 121
mbed_official 0:ab69df6f1c47 122 ```C
mbed_official 0:ab69df6f1c47 123 #include "SDBlockDevice.h"
mbed_official 0:ab69df6f1c47 124 ```
mbed_official 0:ab69df6f1c47 125
mbed_official 0:ab69df6f1c47 126 Change the block device declaration on line 7 of `main.cpp` to use the SD card by replacing the `PinName`s with the pins connected to the SD card:
mbed_official 0:ab69df6f1c47 127
mbed_official 0:ab69df6f1c47 128 ```C
mbed_official 0:ab69df6f1c47 129 SDBlockDevice bd(PinName mosi, PinName miso, PinName sclk, PinName cs);
mbed_official 0:ab69df6f1c47 130 ```
mbed_official 0:ab69df6f1c47 131
mbed_official 0:ab69df6f1c47 132 ## Troubleshooting
mbed_official 0:ab69df6f1c47 133
mbed_official 13:8ff2772e836d 134 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.