FlashIAPBlockDevice
FlashIAPBlockDevice class hierarchy
The flash IAP block device is a block device driver built on top of the FlashIAP API. This is enabled using the internal flash memory as a block device. The read size, write size and erase size may differ, depending on the flash chip. Use the FlashIAPBlockDevice get
function to discover those sizes.
Additional notes:
- Use this driver on platforms where the FlashIAP implementation uses external flash or in conjunction with a file system with wear leveling, that can operate on a page size granularity.
- The FlashIAP may freeze code execution for a long period of time while writing to flash. Not even high-priority IRQs are allowed to run, which may interrupt background processes.
To configure this class, please see our BlockDevice configuration documentation.
FlashIAPBlockDevice class reference
Public Member Functions | |
FlashIAPBlockDevice (uint32_t address=MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS, uint32_t size=MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE) | |
Creates a FlashIAPBlockDevice. More... | |
virtual int | init () |
Initialize a block device. More... | |
virtual int | deinit () |
Deinitialize a block device. More... | |
virtual int | read (void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size) |
Read blocks from a block device. More... | |
virtual int | program (const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size) |
Program blocks to a block device. More... | |
virtual int | erase (mbed::bd_addr_t addr, mbed::bd_size_t size) |
Erase blocks on a block device. More... | |
virtual mbed::bd_size_t | get_read_size () const |
Get the size of a readable block. More... | |
virtual mbed::bd_size_t | get_program_size () const |
Get the size of a programable block. More... | |
virtual mbed::bd_size_t | get_erase_size () const |
Get the size of a eraseable block. More... | |
virtual mbed::bd_size_t | get_erase_size (mbed::bd_addr_t addr) const |
Get the size of an erasable block given address. More... | |
virtual int | get_erase_value () const |
Get the value of storage when erased. More... | |
virtual mbed::bd_size_t | size () const |
Get the total size of the underlying device. More... | |
virtual const char * | get_type () const |
Get the BlockDevice class type. More... | |
virtual bool | is_valid_erase (bd_addr_t addr, bd_size_t size) const |
Convenience function for checking block erase validity. More... | |
virtual int | sync () |
Ensure data on storage is in sync with the driver. More... | |
virtual int | trim (bd_addr_t addr, bd_size_t size) |
Mark blocks as no longer in use. More... | |
virtual bool | is_valid_read (bd_addr_t addr, bd_size_t size) const |
Convenience function for checking block read validity. More... | |
virtual bool | is_valid_program (bd_addr_t addr, bd_size_t size) const |
Convenience function for checking block program validity. More... | |
virtual bool | is_valid_erase (bd_addr_t addr, bd_size_t size) const |
Convenience function for checking block erase validity. More... |
Static Public Member Functions | |
static BlockDevice * | get_default_instance () |
Return the default block device. More... |
FlashIAPBlockDevice example
#include "mbed.h"
#include "FlashIAPBlockDevice.h"
// Create flash IAP block device
FlashIAPBlockDevice bd;
int main()
{
printf("FlashIAPBlockDevice test\n");
// Initialize the flash IAP block device and print the memory layout
bd.init();
printf("Flash block device size: %llu\n", bd.size());
printf("Flash block device read size: %llu\n", bd.get_read_size());
printf("Flash block device program size: %llu\n", bd.get_program_size());
printf("Flash block device erase size: %llu\n", bd.get_erase_size());
// Write "Hello World!" to the first block
char *buffer = (char *)malloc(bd.get_erase_size());
sprintf(buffer, "Hello World!\n");
bd.erase(0, bd.get_erase_size());
bd.program(buffer, 0, bd.get_erase_size());
// Read back what was stored
bd.read(buffer, 0, bd.get_erase_size());
printf("%s", buffer);
// Deinitialize the device
bd.deinit();
}