Documentation

Mistake on this page? Email us

Mbed OS storage configuration

The example application mbed-cloud-client-example uses Mbed OS for storage configuration and initialization. You can enable the storage driver by using the target.feature flag ["STORAGE"]. The following types of storages are supported:

  • COMPONENT_SD: Uses SPI (defaults to onboard card slot if available).
  • COMPONENT_SPIF: Must be a standard serial NOR flash device (defaults to onboard flash if available).
  • COMPONENT_DATAFLASH: Supports the SPI interface or the AT45DB device family.
  • COMPONENT_FLASHIAP: Uses the internal flash of the device.

An example SD card storage for NUCLEO-F429ZI:

{
    "target_overrides": {
        "NUCLEO_F429ZI": {
            "target.components_add": ["SD"],
            "target.features_add": ["BOOTLOADER", "STORAGE"]
        }
    }
},

Note: The target.features_add configuration is a list, which must contain all features on the same line. You must not have the items on separate lines.

Filesystem

You must define the default type of the filesystem and mount point "default" using FileSystem::get_default_instance(). An SD card uses the FAT filesystem, while other types of storage use LittleFS.

Using the storage

In your application, instantiate the Block Device and filesystem objects:

#include "mbed.h"

BlockDevice* bd = BlockDevice::get_default_instance();
FileSystem *fs = FileSystem::get_default_instance();

You can override get_default_instance() with your own versions, because the default implementation has been compiled with a weak attribute.

Partition mode

Use storage with partitioning, such as an SD card. It is enabled by default. You can disable it in the application's mbed_app.json file:

{
   "target_overrides": {
        "K64F": {
            "client_app.partition_mode": 0
        }
    }
}

In partition mode, the filesystem is initialized by MBRBlockDevice with the partition details for a FAT filesystem. You should not use the partition mode with internal storage, as MBRBlockDevice is not compatible with it.

Dual partition

To enable dual partition, change the value of PAL_NUMBER_OF_PARTITIONS to 2:

{
   "target_overrides": {
        "K64F": {
            "client_app.pal_number_of_partition": 2
        }
    }
}

Auto partition

Auto partitioning is an optional feature that you can define with client_app.auto_partition. If the partition initialization fails (for example, if the SD card only has one partition under the dual partition mode), both partitions will be created. The default partition size is 1GB. To set the partition size, define the value for client_app.primary_partition_size and client_app.secondary_partition_size in bytes.

For example, for SD_CARD storage, dual partition, auto-partition enabled and 2GB partition size:

{
   "target_overrides": {
        "K64F": {
            "target.components_add": ["SD"],
            "target.features_add": ["STORAGE"],
            "client_app.partition_mode": 1,
            "client_app.pal_number_of_partition": 2,
            "client_app.auto_partition": 1,
            "client_app.primary_partition_size": 1982595072,
            "client_app.secondary_partition_size": 1982595072
        }
    }
}