Mbed OS Reference
Loading...
Searching...
No Matches
FlashIAP Class Reference

Flash IAP driver. More...

#include <FlashIAP.h>

Inheritance diagram for FlashIAP:
NonCopyable< FlashIAP >

Public Member Functions

int init ()
 Initialize a flash IAP device. More...
 
int deinit ()
 Deinitialize a flash IAP device. More...
 
int read (void *buffer, uint32_t addr, uint32_t size)
 Read data from a flash device. More...
 
int program (const void *buffer, uint32_t addr, uint32_t size)
 Program data to pages. More...
 
int erase (uint32_t addr, uint32_t size)
 Erase sectors. More...
 
uint32_t get_sector_size (uint32_t addr) const
 Get the sector size at the defined address. More...
 
uint32_t get_flash_start () const
 Get the flash start address. More...
 
uint32_t get_flash_size () const
 Get the flash size. More...
 
uint32_t get_page_size () const
 Get the program page size. More...
 
uint8_t get_erase_value () const
 Get the flash erase value. More...
 

Detailed Description

Flash IAP driver.

It invokes flash HAL functions.

Note
Synchronization level: Thread safe

Definition at line 68 of file FlashIAP.h.

Member Function Documentation

◆ init()

int init ( )

Initialize a flash IAP device.

Should be called once per lifetime of the object.

Returns
0 on success or a negative error code on failure

◆ deinit()

int deinit ( )

Deinitialize a flash IAP device.

Returns
0 on success or a negative error code on failure

◆ read()

int read ( void *  buffer,
uint32_t  addr,
uint32_t  size 
)

Read data from a flash device.

This method invokes memcpy - reads number of bytes from the address

Parameters
bufferBuffer to write to
addrFlash address to begin reading from
sizeSize to read in bytes
Returns
0 on success, negative error code on failure

◆ program()

int program ( const void *  buffer,
uint32_t  addr,
uint32_t  size 
)

Program data to pages.

The sectors must have been erased prior to being programmed

Parameters
bufferBuffer of data to be written
addrAddress of a page to begin writing to
sizeSize to write in bytes, must be a multiple of program size
Returns
0 on success, negative error code on failure

◆ erase()

int erase ( uint32_t  addr,
uint32_t  size 
)

Erase sectors.

The state of an erased sector is undefined until it has been programmed

Parameters
addrAddress of a sector to begin erasing, must be a multiple of the sector size
sizeSize to erase in bytes, must be a multiple of the sector size
Returns
0 on success, negative error code on failure

◆ get_sector_size()

uint32_t get_sector_size ( uint32_t  addr) const

Get the sector size at the defined address.

Sector size might differ at address ranges. An example <0-0x1000, sector size=1024; 0x10000-0x20000, size=2048>

Parameters
addrAddress of or inside the sector to query
Returns
Size of a sector in bytes or MBED_FLASH_INVALID_SIZE if not mapped

◆ get_flash_start()

uint32_t get_flash_start ( ) const

Get the flash start address.

Note
This is the start address of the entire flash region, not the first address after the end of the program in flash.
Returns
Flash start address

◆ get_flash_size()

uint32_t get_flash_size ( ) const

Get the flash size.

Returns
Flash size

◆ get_page_size()

uint32_t get_page_size ( ) const

Get the program page size.

The page size defines the writable page size

Returns
Size of a program page in bytes

◆ get_erase_value()

uint8_t get_erase_value ( ) const

Get the flash erase value.

Get the value we read after erase operation

Returns
flash erase value