You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace reference to SPIFBlockDevice as default, this example uses an
instance of the SDBlockDevice. Add note to explain what happens in the
scenario that a SD card is not found on the board. Update template to
follow format used in mbed-os-example-blinky. Remove linker table and
depracated compilers. Output in README matches output from source
# Getting started with the Mbed OS block device API
2
+
# Block Device API Mbed OS example
3
3
4
-
This example demonstrates how to use the Mbed OS block device API.
4
+
The example project is part of the [Arm Mbed OS Official Examples](https://os.mbed.com/code/). It contains an application that demonstrates how to use a block device as storage on supported [Mbed boards](https://os.mbed.com/platforms/).
5
5
6
-
You can find more information about the Mbed OS block device and other related pieces of the Mbed OS storage stack [in the storage overview](https://os.mbed.com/docs/latest/reference/storage.html).
6
+
You can build the project with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/latest/tools/index.html). However, this example project specifically refers to the command-line interface tool [Arm Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
7
+
(Note: To see a rendered example you can import into the Arm Online Compiler, please see our [import quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).)
1. From the command-line, import the example: `mbed import mbed-os-example-blockdevice`
13
+
1. Change the current directory to where the project was imported: `cd mbed-os-example-blockdevice`
16
14
1.[Changing the block device](#changing-the-block-device)
17
15
1.[Tested configurations](#tested-configurations)
18
16
19
-
## Hardware requirements
20
-
21
-
This example uses a block device as storage. This can be either an external
22
-
block device (one of SPI flash, DataFlash or an SD card) or simulated on a
23
-
heap block device on boards with enough RAM.
24
-
25
-
By default, this example uses an instance of the SPIFBlockDevice, which requires
26
-
external SPI flash. The [changing the block device](#changing-the-block-device)
27
-
section describes how to change the file system or block device in the example.
28
-
29
-
## Usage
17
+
## Application functionality
18
+
This example demonstrates how to read and write data into a storage device. This can be either an external block device (one of SPI flash, DataFlash or an SD card) or simulated on a heap block device on boards with enough RAM.
30
19
31
-
#### Import the example
20
+
By default, an instance of the SDBlockDevice is used, this requires an external SD card. The [changing the block device](#changing-the-block-device) section describes how to change this.
32
21
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)
34
-
to set everything up.
35
-
36
-
From the command-line, import the example:
37
-
38
-
```commandline
39
-
mbed import mbed-os-example-blockdevice
40
-
cd mbed-os-example-blockdevice
41
-
```
22
+
#### Building and running
42
23
43
-
#### Compile the example
24
+
1. Connect a USB cable between the USB port on the board and the host computer.
25
+
1. Run the following command to build the example project and program the microcontroller flash memory:
44
26
45
-
Invoke `mbed compile`, and specify the name of your platform and your favorite
46
-
toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
27
+
```bash
28
+
mbed compile -m <TARGET> -t <TOOLCHAIN> --flash
29
+
```
47
30
48
-
```commandline
49
-
mbed compile -m K64F -t ARM
50
-
```
31
+
Your PC may take a few minutes to compile your code.
51
32
52
-
Your PC may take a few minutes to compile your code. At the end, you see the
53
-
following result:
33
+
Alternatively, you can manually copy the binary to the board, which you mount on the host computer over USB. The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blockdevice.bin`.
Depending on the target, you can build the example project with the `GCC_ARM`, or `ARM` toolchain. Run the command below to determine which toolchain supports your target:
36
+
```bash
37
+
mbed compile -S
79
38
```
39
+
Once you have programmed your board, open the UART of the board in your preferred UART viewing program. To launch the serial console provided by Mbed, run the command`mbedtools sterm`. If you don't see any output in the console press the reset button to restart the program.
80
40
81
-
#### Run the example
82
-
83
-
1. Connect your Mbed Enabled device to the computer over USB.
84
-
1. Copy the binary file to the Mbed Enabled device.
85
-
1. Press the reset button to start the program.
86
-
1. Open the UART of the board in your favorite UART viewing program. For
87
-
example, `screen /dev/ttyACM0`.
88
-
89
41
**Note:** The default serial port baud rate is 9600 bit/s.
90
42
91
-
Expected output:
43
+
## Expected output
92
44
93
45
``` commandline
94
46
--- Block device geometry ---
@@ -147,28 +99,27 @@ bd.deinit -> 0
147
99
Try changing the string "Hello Storage!" to a message of your choice to see it
148
100
stored on the block device.
149
101
150
-
#### Troubleshooting
151
-
152
-
If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html)
153
-
for suggestions on what could be wrong and how to fix it.
102
+
If you see garbled text from the read operations check that your SD card is securely fixed in the port. If there's no SD card mounted the application returns garbage characters.
103
+
## Troubleshooting
104
+
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.
154
105
155
106
## Changing the block device
156
-
Mbed-OS supports a variety of block device types, more information on supported devices can be found [here](https://os.mbed.com/docs/mbed-os/latest/apis/data-storage.html#Default-BlockDevice-configuration).
107
+
Mbed-OS supports a variety of block device types, more information on supported devices can be found [here](https://os.mbed.com/docs/mbed-os/latest/apis/data-storage-concepts.html).
157
108
158
109
Each device is represented by a C++ class that inherits from the interface class [BlockDevice](https://os.mbed.com/docs/mbed-os/latest/apis/blockdevice-apis.html). These classes take their default configuration from the component configuration file. This may be found in`/mbed-os/storage/blockdevice/` under the path corresponding to the block device type—for example [mbed_lib.json](https://github.com/ARMmbed/mbed-os/blob/master/storage/blockdevice/COMPONENT_SPIF/mbed_lib.json).
159
110
160
111
In this example, you can determine which block device is used by modifying the type of `bd`in main.cpp. For instance, if instead you wanted to use a SPIF block device you would declare`bd` as an SPIFBlockDevice instance.
161
112
```diff
162
-
-SPIFBlockDevice bd(
163
-
-MBED_CONF_SPIF_DRIVER_SPI_MOSI,
164
-
-MBED_CONF_SPIF_DRIVER_SPI_MISO,
165
-
-MBED_CONF_SPIF_DRIVER_SPI_CLK,
166
-
-MBED_CONF_SPIF_DRIVER_SPI_CS);
167
-
+SDBlockDevice bd(
168
-
+MBED_CONF_SD_SPI_MOSI,
169
-
+MBED_CONF_SD_SPI_MISO,
170
-
+MBED_CONF_SD_SPI_CLK,
171
-
+MBED_CONF_SD_SPI_CS);
113
+
-SDBlockDevice bd(
114
+
- MBED_CONF_SD_SPI_MOSI,
115
+
- MBED_CONF_SD_SPI_MISO,
116
+
- MBED_CONF_SD_SPI_CLK,
117
+
- MBED_CONF_SD_SPI_CS);
118
+
+SPIFBlockDevice bd(
119
+
+ MBED_CONF_SPIF_DRIVER_SPI_MOSI,
120
+
+ MBED_CONF_SPIF_DRIVER_SPI_MISO,
121
+
+ MBED_CONF_SPIF_DRIVER_SPI_CLK,
122
+
+ MBED_CONF_SPIF_DRIVER_SPI_CS);
172
123
```
173
124
You may need to make modifications to the application configuration file if you're using a physical storage device that isn't included in your target's default configuration (check in `targets.json` for this). To do this, add your physical storage device as a component in `mbed_app.json` as follows:
174
125
``` json
@@ -191,8 +142,7 @@ You can also modify the pin assignments for your component as follows:
191
142
}
192
143
```
193
144
Alternatively, you may use the system's default block device `BlockDevice *bd = BlockDevice::get_default_instance()` but this will require more code changes to the example.
194
-
# Tested configurations
195
-
145
+
## Tested configurations
196
146
- K64F + Heap
197
147
- K64F + SD
198
148
- K64F + SPIF (requires shield)
@@ -214,17 +164,15 @@ Alternatively, you may use the system's default block device `BlockDevice *bd =
214
164
pins. A different set of serial pins must be selected to use SPI flash with
215
165
serial output.
216
166
217
-
```c++
167
+
```c++
218
168
// Connect Tx, Rx, and ground pins to a separte board running the passthrough example:
pc.printf("..."); // Replace printf with pc.printf in the example
223
173
```
224
-
## License and contributions
174
+
### License and contributions
225
175
226
176
The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see [contributing.md](CONTRIBUTING.md) for more info.
227
177
228
178
This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
0 commit comments