Morse Micro IoT SDK  2.10.4
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_PARTITION_CONFIG_DEFAULT   { 0, 0, false }
 Initial values for mmhal_flash_partition_config. More...
 

Functions

const struct mmhal_flash_partition_configmmhal_get_mmconfig_partition (void)
 Get MMCONFIG flash partition configuration. More...
 
int mmhal_flash_erase (uint32_t block_address)
 Erases a block of Flash pointed to by the block_address. More...
 
uint32_t mmhal_flash_getblocksize (uint32_t block_address)
 Returns the size of the Flash block at the specified address. More...
 
int mmhal_flash_read (uint32_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 (uint32_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_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 65 of file mmhal_flash.h.

Function Documentation

◆ mmhal_flash_erase()

int mmhal_flash_erase ( uint32_t  block_address)

Erases a block of Flash pointed to by the block_address.

The block address may be anywhere within the block to erase. The entire block gets erased. Once erased all bytes in the block shall be MMHAL_FLASH_ERASE_VALUE (0xFF).

Parameters
block_addressThe address of the block of Flash to erase.
Returns
0 on success, negative number on failure

◆ mmhal_flash_getblocksize()

uint32_t mmhal_flash_getblocksize ( uint32_t  block_address)

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

Parameters
block_addressThe address of the Flash block.
Returns
The size of the Flash block in bytes. Returns 0 if an invalid address is specified.

◆ mmhal_flash_read()

int mmhal_flash_read ( uint32_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 in Flash to read from.
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 ( uint32_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 in Flash to write to.
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_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.

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