Mbed OS Reference
Loading...
Searching...
No Matches
Flash HAL API

Functions

int32_t flash_init (flash_t *obj)
 Initialize the flash peripheral and the flash_t object. More...
 
int32_t flash_free (flash_t *obj)
 Uninitialize the flash peripheral and the flash_t object. More...
 
int32_t flash_erase_sector (flash_t *obj, uint32_t address)
 Erase one sector starting at defined address. More...
 
int32_t flash_read (flash_t *obj, uint32_t address, uint8_t *data, uint32_t size)
 Read data starting at defined address. More...
 
int32_t flash_program_page (flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size)
 Program pages starting at defined address. More...
 
uint32_t flash_get_sector_size (const flash_t *obj, uint32_t address)
 Get sector size. More...
 
uint32_t flash_get_page_size (const flash_t *obj)
 Get page size. More...
 
uint32_t flash_get_start_address (const flash_t *obj)
 Get start address for the flash region (as in, where the flash is mapped in main memory). More...
 
uint32_t flash_get_size (const flash_t *obj)
 Get the flash region size. More...
 
uint8_t flash_get_erase_value (const flash_t *obj)
 Get the flash erase value. More...
 

Detailed Description

Function Documentation

◆ flash_init()

int32_t flash_init ( flash_t obj)

Initialize the flash peripheral and the flash_t object.

Parameters
objThe flash object
Returns
0 for success, -1 for error

◆ flash_free()

int32_t flash_free ( flash_t obj)

Uninitialize the flash peripheral and the flash_t object.

Parameters
objThe flash object
Returns
0 for success, -1 for error

◆ flash_erase_sector()

int32_t flash_erase_sector ( flash_t obj,
uint32_t  address 
)

Erase one sector starting at defined address.

The address should be at sector boundary. This function does not do any check for address alignments

Parameters
objThe flash object
addressThe sector starting address
Returns
0 for success, -1 for error

◆ flash_read()

int32_t flash_read ( flash_t obj,
uint32_t  address,
uint8_t *  data,
uint32_t  size 
)

Read data starting at defined address.

This function has a WEAK implementation using memcpy for backwards compatibility.

Parameters
objThe flash object
addressAddress to begin reading from
dataThe buffer to read data into
sizeThe number of bytes to read
Returns
0 for success, -1 for error

◆ flash_program_page()

int32_t flash_program_page ( flash_t obj,
uint32_t  address,
const uint8_t *  data,
uint32_t  size 
)

Program pages starting at defined address.

The pages should not cross multiple sectors.

Note
The upper level FlashIAP.cpp code guarantees:
  • data is 32-bit aligned
  • size is a multiple of the page size
  • address is inside a flash sector
  • address is aligned to the page size (but not the sector size)
So, implementations of this function do not need to check these things.
Parameters
objThe flash object
addressThe sector starting address
dataThe data buffer to be programmed
sizeThe number of bytes to program
Returns
0 for success, -1 for error

◆ flash_get_sector_size()

uint32_t flash_get_sector_size ( const flash_t obj,
uint32_t  address 
)

Get sector size.

Parameters
objThe flash object
addressThe sector starting address
Returns
The size of a sector

◆ flash_get_page_size()

uint32_t flash_get_page_size ( const flash_t obj)

Get page size.

The page size defines the writable page size

Parameters
objThe flash object
Returns
The size of a page

◆ flash_get_start_address()

uint32_t flash_get_start_address ( const flash_t obj)

Get start address for the flash region (as in, where the flash is mapped in main memory).

Note
This should return the start address of the entire flash region, not the first address after the end of the program in flash.
Parameters
objThe flash object
Returns
The start address for the flash region

◆ flash_get_size()

uint32_t flash_get_size ( const flash_t obj)

Get the flash region size.

Parameters
objThe flash object
Returns
The flash region size

◆ flash_get_erase_value()

uint8_t flash_get_erase_value ( const flash_t obj)

Get the flash erase value.

Parameters
objThe flash object
Returns
The flash erase value