Skip to content

Commit 38d4443

Browse files
harrisonmutai-armevedon
authored andcommitted
Update README formatting and content
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
1 parent a1c7e3c commit 38d4443

File tree

1 file changed

+41
-93
lines changed

1 file changed

+41
-93
lines changed

README.md

Lines changed: 41 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,46 @@
11
![](./resources/official_armmbed_example_badge.png)
2-
# Getting started with the Mbed OS block device API
2+
# Block Device API Mbed OS example
33

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/).
55

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).)
78

8-
**Table of contents:**
99

10-
1. [Hardware requirements](#hardware-requirements)
11-
1. [Usage](#usage)
12-
- [Import the example](#import-the-example)
13-
- [Compile the example](#compile-the-example)
14-
- [Run the example](#run-the-example)
15-
- [Troubleshooting](#troubleshooting)
10+
11+
1. [Install Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html).
12+
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`
1614
1. [Changing the block device](#changing-the-block-device)
1715
1. [Tested configurations](#tested-configurations)
1816

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.
3019

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.
3221

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
4223

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:
4426

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+
```
4730

48-
``` commandline
49-
mbed compile -m K64F -t ARM
50-
```
31+
Your PC may take a few minutes to compile your code.
5132

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`.
5434

55-
``` commandline
56-
[snip]
57-
+--------------------------+-------+-------+-------+
58-
| Module | .text | .data | .bss |
59-
+--------------------------+-------+-------+-------+
60-
| Fill | 164 | 0 | 2136 |
61-
| Misc | 54505 | 2556 | 754 |
62-
| drivers | 640 | 0 | 32 |
63-
| features/filesystem | 15793 | 0 | 550 |
64-
| features/storage | 42 | 0 | 184 |
65-
| hal | 418 | 0 | 8 |
66-
| platform | 2355 | 20 | 582 |
67-
| rtos | 135 | 4 | 4 |
68-
| rtos/rtx | 5861 | 20 | 6870 |
69-
| targets/TARGET_Freescale | 8382 | 12 | 384 |
70-
| Subtotals | 88295 | 2612 | 11504 |
71-
+--------------------------+-------+-------+-------+
72-
Allocated Heap: 24576 bytes
73-
Allocated Stack: unknown
74-
Total Static RAM memory (data + bss): 14116 bytes
75-
Total RAM memory (data + bss + heap + stack): 38692 bytes
76-
Total Flash memory (text + data + misc): 91947 bytes
77-
78-
Image: ./BUILD/K64F/ARM/mbed-os-example-blockdevice.bin
35+
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
7938
```
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.
8040
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-
8941
**Note:** The default serial port baud rate is 9600 bit/s.
9042
91-
Expected output:
43+
## Expected output
9244
9345
``` commandline
9446
--- Block device geometry ---
@@ -147,28 +99,27 @@ bd.deinit -> 0
14799
Try changing the string "Hello Storage!" to a message of your choice to see it
148100
stored on the block device.
149101
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.
154105

155106
## 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).
157108

158109
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).
159110

160111
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.
161112
```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);
172123
```
173124
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:
174125
``` json
@@ -191,8 +142,7 @@ You can also modify the pin assignments for your component as follows:
191142
}
192143
```
193144
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
196146
- K64F + Heap
197147
- K64F + SD
198148
- K64F + SPIF (requires shield)
@@ -214,17 +164,15 @@ Alternatively, you may use the system's default block device `BlockDevice *bd =
214164
pins. A different set of serial pins must be selected to use SPI flash with
215165
serial output.
216166
217-
```c++
167+
``` c++
218168
// Connect Tx, Rx, and ground pins to a separte board running the passthrough example:
219169
// https://os.mbed.com/users/sarahmarshy/code/SerialPassthrough/file/2a3a62ee17fa/main.cpp/
220170
Serial pc(TX, RX);
221171
222172
pc.printf("..."); // Replace printf with pc.printf in the example
223173
```
224-
## License and contributions
174+
### License and contributions
225175

226176
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.
227177

228178
This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
229-
230-

0 commit comments

Comments
 (0)