Morse Micro IoT SDK  2.12.3
Morse Micro Flash Hardware Abstraction Layer (mmhal_flash) API

Detailed Description

This API provides abstraction from the underlying flash hardware.

Note
This API is not used by morselib.

Data Structures

struct  mmhal_flash_partition_config
 Flash partition configuration structure. More...
 

Macros

#define MMHAL_FLASH_ERASE_VALUE   0xFF
 This is the value erased flash bytes are set to. More...
 
#define MMHAL_FLASH_ADDR_T   uint32_t
 Underlying integer type for mmhal_flash_addr_t. More...
 
#define MMHAL_FLASH_PARTITION_CONFIG_DEFAULT   { 0, 0, false }
 Initial values for mmhal_flash_partition_config. More...
 

Typedefs

typedef MMHAL_FLASH_ADDR_T mmhal_flash_addr_t
 Address type used by the mmhal flash API. More...
 

Functions

const struct mmhal_flash_partition_configmmhal_get_mmconfig_partition (void)
 Get MMCONFIG flash partition configuration. More...
 
const struct mmhal_flash_partition_configmmhal_get_factory_mmconfig_partition (void)
 Get optional factory default MMCONFIG flash partition configuration. More...
 
int mmhal_flash_erase (mmhal_flash_addr_t block_address)
 Erases a specified block of flash. More...
 
uint32_t mmhal_flash_getblocksize (mmhal_flash_addr_t block_address)
 Returns the size of the flash block at the specified address. More...
 
int mmhal_flash_read (mmhal_flash_addr_t read_address, uint8_t *buf, size_t size)
 Read a block of data from the specified Flash address into the buffer. More...
 
int mmhal_flash_write (mmhal_flash_addr_t write_address, const uint8_t *data, size_t size)
 Write a block of data to the specified Flash address. More...
 
const struct lfs_config * mmhal_get_littlefs_config (void)
 Get LittleFS configuration. More...
 

Macro Definition Documentation

◆ MMHAL_FLASH_ADDR_T

#define MMHAL_FLASH_ADDR_T   uint32_t

Underlying integer type for mmhal_flash_addr_t.

Defaults to uint32_t. May be overridden by the build system (e.g. by defining MMHAL_FLASH_ADDR_T on the compiler command line) if a platform requires a wider integer type to represent a flash address.

Definition at line 44 of file mmhal_flash.h.

◆ MMHAL_FLASH_ERASE_VALUE

#define MMHAL_FLASH_ERASE_VALUE   0xFF

This is the value erased flash bytes are set to.

This shall be 0xFF as this is the value that hardware flash erases to.

Definition at line 32 of file mmhal_flash.h.

◆ MMHAL_FLASH_PARTITION_CONFIG_DEFAULT

#define MMHAL_FLASH_PARTITION_CONFIG_DEFAULT   { 0, 0, false }

Initial values for mmhal_flash_partition_config.

Definition at line 85 of file mmhal_flash.h.

Typedef Documentation

◆ mmhal_flash_addr_t

Address type used by the mmhal flash API.

Definition at line 48 of file mmhal_flash.h.

Function Documentation

◆ mmhal_flash_erase()

int mmhal_flash_erase ( mmhal_flash_addr_t  block_address)

Erases a specified block of flash.

The given block_address may be anywhere within the block to erase – the entire block will be erased. Once erased all bytes in the block shall be MMHAL_FLASH_ERASE_VALUE.

Parameters
block_addressThe address of the block of flash to erase. Addresses are implementation dependent, but should be within a range defined by a given mmhal_flash_partition_config.
Returns
0 on success, negative number on failure

◆ mmhal_flash_getblocksize()

uint32_t mmhal_flash_getblocksize ( mmhal_flash_addr_t  block_address)

Returns the size of the flash block at the specified address.

Parameters
block_addressThe address of the flash block. Addresses are implementation dependent, but should be within a range defined by a given mmhal_flash_partition_config.
Returns
The size of the Flash block in bytes. Returns 0 if an invalid address is specified.

◆ mmhal_flash_read()

int mmhal_flash_read ( mmhal_flash_addr_t  read_address,
uint8_t *  buf,
size_t  size 
)

Read a block of data from the specified Flash address into the buffer.

Parameters
read_addressThe address to read from. Addresses are implementation dependent, but should be within a range defined by a given mmhal_flash_partition_config.
bufThe buffer to read into.
sizeThe number of bytes to read.
Returns
0 on success, or a negative number on failure.

◆ mmhal_flash_write()

int mmhal_flash_write ( mmhal_flash_addr_t  write_address,
const uint8_t *  data,
size_t  size 
)

Write a block of data to the specified Flash address.

There is no alignment or minimum size requirement. This function will take care of aligning the data and merging with existing Flash contents. The Flash block is not erased, it is up to the application to determine if the block needs to be erased before programming.

Parameters
write_addressThe address to write to. Addresses are implementation dependent, but should be within a range defined by a given mmhal_flash_partition_config.
dataA pointer to the block of data to write.
sizeThe number of bytes to write.
Returns
0 on success, or a negative number on failure.

◆ mmhal_get_factory_mmconfig_partition()

const struct mmhal_flash_partition_config * mmhal_get_factory_mmconfig_partition ( void  )

Get optional factory default MMCONFIG flash partition configuration.

This partition uses the same on-flash format as a single MMCONFIG image, but is treated as read-only by mmconfig. If present and valid, values in this partition are used as fall-backs when a key is absent from the writable MMCONFIG partition. Platforms that do not provide a factory default partition may omit this function; a weak default implementation returns NULL.

Note that unlike mmhal_get_mmconfig_partition(), the size here is used only for a single partition. Therefore it would be normal to define a factory partition that is half the size (or less) of the normal config partition, and it is not necessary to align it to a flash sector as it is not erased.

Returns
A static pointer to the factory MMCONFIG partition config, or NULL if not supported.

◆ mmhal_get_littlefs_config()

const struct lfs_config * mmhal_get_littlefs_config ( void  )

Get LittleFS configuration.

LittleFS initialization is done by littlefs_init() in mmosal_shim_fileio.c. which in turn calls this function to fetch the hardware configuration for LittleFS from the HAL layer. The LittleFS configuration will vary from platform to platform. If LittleFS is not supported by the platform then we just return NULL. This function returns a static pointer to struct lfs_config which is defined in lfs.h.

See mmhal_littlefs.c for the full HAL layer implementation for your platform. See mmosal_shim_fileio.c for the libc shims for LittleFS. See README.md in the src/littlefs folder for detailed information on LittleFS.

Returns
A static pointer to the LittleFS config structure, or NULL if not supported.

◆ mmhal_get_mmconfig_partition()

const struct mmhal_flash_partition_config * mmhal_get_mmconfig_partition ( void  )

Get MMCONFIG flash partition configuration.

MMCONFIG initialization is done by mmconfig_init() in mmconfig.c, which in turn calls this function to fetch the partition configuration for config store from the HAL layer. If config store is not supported by the platform then we just return NULL. This function returns a static pointer to struct mmhal_flash_partition_config.

Because primary/secondary partitions are used in the current implementation, the available config storage is half of the provided size.

Returns
A static pointer to the partition config for MMCONFIG, or NULL if not supported.