Skip to content

Commit a1c7e3c

Browse files
harrisonmutai-armevedon
authored andcommitted
Improve explanation for adding a new block device
1 parent daedf99 commit a1c7e3c

File tree

1 file changed

+27
-132
lines changed

1 file changed

+27
-132
lines changed

README.md

Lines changed: 27 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ to set everything up.
3535

3636
From the command-line, import the example:
3737

38-
```
38+
``` commandline
3939
mbed import mbed-os-example-blockdevice
4040
cd mbed-os-example-blockdevice
4141
```
@@ -45,14 +45,14 @@ cd mbed-os-example-blockdevice
4545
Invoke `mbed compile`, and specify the name of your platform and your favorite
4646
toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
4747

48-
```
48+
``` commandline
4949
mbed compile -m K64F -t ARM
5050
```
5151

5252
Your PC may take a few minutes to compile your code. At the end, you see the
5353
following result:
5454

55-
```
55+
``` commandline
5656
[snip]
5757
+--------------------------+-------+-------+-------+
5858
| Module | .text | .data | .bss |
@@ -90,7 +90,7 @@ Image: ./BUILD/K64F/ARM/mbed-os-example-blockdevice.bin
9090

9191
Expected output:
9292

93-
```
93+
``` commandline
9494
--- Block device geometry ---
9595
read_size: 1 B
9696
program_size: 1 B
@@ -118,7 +118,7 @@ bd.deinit -> 0
118118

119119
You can also reset the board to see the data persist across boots:
120120

121-
```
121+
``` commandline
122122
--- Block device geometry ---
123123
read_size: 1 B
124124
program_size: 1 B
@@ -153,12 +153,12 @@ If you have problems, you can review the [documentation](https://os.mbed.com/doc
153153
for suggestions on what could be wrong and how to fix it.
154154

155155
## 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).
156157

157-
In Mbed OS, a C++ classes that inherits from the [BlockDevice](https://os.mbed.com/docs/latest/reference/storage.html#block-devices)
158-
interface represents each block device. You can change the filesystem in the
159-
example by changing the class declared in main.cpp.
158+
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).
160159

161-
``` diff
160+
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+
```diff
162162
-SPIFBlockDevice bd(
163163
- MBED_CONF_SPIF_DRIVER_SPI_MOSI,
164164
- MBED_CONF_SPIF_DRIVER_SPI_MISO,
@@ -170,133 +170,28 @@ example by changing the class declared in main.cpp.
170170
+ MBED_CONF_SD_SPI_CLK,
171171
+ MBED_CONF_SD_SPI_CS);
172172
```
173-
174-
**Note:** Most block devices require pin assignments. Double check that the
175-
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.
176-
177-
Starting mbed-os 5.10 the SD, SPIF, DATAFLASH and QSPIF block devices are components under mbed-os. In order to add a component to the application use the "components_add" `target_overrides` configuration:
178-
173+
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+
``` json
175+
"target_overrides": {
176+
"K64F": {
177+
"target.components_add": ["SPIF"],
178+
}
179+
}
179180
```
181+
You can also modify the pin assignments for your component as follows:
182+
``` json
180183
"target_overrides": {
181-
...
182-
"NUCLEO_F429ZI": {
183-
"components_add": ["SPIF"],
184-
"SPI_MOSI": "PC_12",
185-
"SPI_MISO": "PC_11",
186-
"SPI_CLK": "PC_10",
187-
"SPI_CS": "PA_15"
188-
},
189-
...
184+
"K64F": {
185+
"target.components_add": ["SPIF"],
186+
"spif-driver.SPI_MOSI": "PC_12",
187+
"spif-driver.SPI_MISO": "PC_11",
188+
"spif-driver.SPI_CLK": "PC_10",
189+
"spif-driver.SPI_CS": "PA_15"
190+
}
190191
}
191192
```
192-
193-
The components_add param can be "SPIF", "SD" , "DATAFLASH" or "QSPIF" depends on the block devices you need.
194-
195-
Mbed OS has several options for the block device:
196-
197-
- **SPIFBlockDevice** - Block device driver for NOR-based SPI flash devices that
198-
support SFDP. NOR-based SPI flash supports byte-sized read and writes, with an
199-
erase size of about 4kbytes. An erase sets a block to all 1s, with successive
200-
writes clearing set bits.
201-
202-
``` cpp
203-
SPIFBlockDevice bd(
204-
MBED_CONF_SPIF_DRIVER_SPI_MOSI,
205-
MBED_CONF_SPIF_DRIVER_SPI_MISO,
206-
MBED_CONF_SPIF_DRIVER_SPI_CLK,
207-
MBED_CONF_SPIF_DRIVER_SPI_CS);
208-
```
209-
210-
- **QSPIFBlockDevice** - Block device driver for NOR-based Quad SPI flash devices that
211-
support SFDP, with QUAD SPI bus support for 4 bits per cycle (4 times the speed of standard SPI)
212-
213-
``` cpp
214-
QSPIFBlockDevice bd(
215-
QSPI_FLASH1_IO0,
216-
QSPI_FLASH1_IO1,
217-
QSPI_FLASH1_IO2,
218-
QSPI_FLASH1_IO3,
219-
QSPI_FLASH1_SCK,
220-
QSPI_FLASH1_CSN,
221-
QSPIF_POLARITY_MODE_0,
222-
MBED_CONF_QSPIF_QSPI_FREQ);
223-
```
224-
225-
- **DataFlashBlockDevice** - Block device driver for NOR-based SPI flash devices
226-
that support the DataFlash protocol, such as the Adesto AT45DB series of
227-
devices. DataFlash is a memory protocol that combines flash with SRAM buffers
228-
for a programming interface. DataFlash supports byte-sized read and writes, with
229-
an erase size of about 528 bytes or sometimes 1056 bytes. DataFlash provides
230-
erase sizes with an extra 16 bytes for error correction codes (ECC), so a flash
231-
translation layer (FTL) may still present 512 byte erase sizes.
232-
233-
``` cpp
234-
DataFlashBlockDevice bd(
235-
MBED_CONF_DATAFLASH_SPI_MOSI,
236-
MBED_CONF_DATAFLASH_SPI_MISO,
237-
MBED_CONF_DATAFLASH_SPI_CLK,
238-
MBED_CONF_DATAFLASH_SPI_CS);
239-
```
240-
241-
- **SDBlockDevice** - Block device driver for SD cards and eMMC memory chips. SD
242-
cards or eMMC chips offer a full FTL layer on top of NAND flash. This makes the
243-
storage well-suited for systems that require a about 1GB of memory.
244-
Additionally, SD cards are a popular form of portable storage. They are useful
245-
if you want to store data that you can access from a PC.
246-
247-
``` cpp
248-
SDBlockDevice bd(
249-
MBED_CONF_SD_SPI_MOSI,
250-
MBED_CONF_SD_SPI_MISO,
251-
MBED_CONF_SD_SPI_CLK,
252-
MBED_CONF_SD_SPI_CS);
253-
```
254-
255-
- [**HeapBlockDevice**](https://os.mbed.com/docs/v5.6/reference/heapblockdevice.html) -
256-
Block device that simulates storage in RAM using the heap. Do not use the heap
257-
block device for storing data persistently because a power loss causes
258-
complete loss of data. Instead, use it fortesting applications when a storage
259-
device is not available.
260-
261-
``` cpp
262-
HeapBlockDevice bd(1024*512, 512);
263-
```
264-
265-
Additionally, Mbed OS contains several utility block devices to give you better
266-
control over the allocation of storage.
267-
268-
- [**SlicingBlockDevice**](https://os.mbed.com/docs/latest/reference/slicingblockdevice.html) -
269-
With the slicing block device, you can partition storage into smaller block
270-
devices that you can use independently.
271-
272-
- [**ChainingBlockDevice**](https://os.mbed.com/docs/latest/reference/chainingblockdevice.html) -
273-
With the chaining block device, you can chain multiple block devices together
274-
and extend the usable amount of storage.
275-
276-
- [**MBRBlockDevice**](https://os.mbed.com/docs/latest/reference/mbrblockdevice.html) -
277-
Mbed OS comes with support for storing partitions on disk with a Master Boot
278-
Record (MBR). The MBRBlockDevice provides this functionality and supports
279-
creating partitions at runtime or using preformatted partitions configured
280-
separately from outside the application.
281-
282-
- **ReadOnlyBlockDevice** - With the read-only block device, you can wrap a
283-
block device in a read-only layer, ensuring that user of the block device does
284-
not modify the storage.
285-
286-
- **ProfilingBlockDevice** - With the profiling block device, you can profile
287-
the quantity of erase, program and read operations that are incurred on a
288-
block device.
289-
290-
- **ObservingBlockDevice** - The observing block device grants the user the
291-
ability to register a callback on block device operations. You can use this to
292-
inspect the state of the block device, log different metrics or perform some
293-
other operation.
294-
295-
- **ExhaustibleBlockDevice** - Useful for evaluating how file systems respond to
296-
wear, the exhaustible block device simulates wear on another form of storage.
297-
You can configure it to expire blocks as necessary.
298-
299-
## Tested configurations
193+
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
300195

301196
- K64F + Heap
302197
- K64F + SD

0 commit comments

Comments
 (0)