Low-level flash page interface. More...
Low-level flash page interface.
This interface provides a very simple and straight forward way for writing a MCU's internal flash. This interface is only capable of reading, verifying, and writing complete flash pages, it has no support for partial flash access. This enables for very slim and efficient implementations.
A module for more fine-grained access of memory locations can easily be programmed on top of this interface.
The flashpage driver implementation should make sure, that the CPU uses no additional energy while the flashpage driver is inactive. This means, that any particular CPU peripherals used for reading and writing flash pages should be disabled before the read and write functions return.
If an implementation puts the calling thread to sleep for a duration of time, the implementation might need to take care of blocking certain power modes.
Files | |
file | flashpage.h |
Low-level flash page peripheral driver interface. | |
Macros | |
#define | CPU_FLASH_BASE (0) |
Per default, we expect the internal flash to start at address 0. | |
#define | FLASHPAGE_WRITE_BLOCK_SIZE |
For raw writings to the flash, this constant must define the minimum write length allowed by the MCU. | |
#define | FLASHPAGE_WRITE_BLOCK_ALIGNMENT |
The buffers to be written to the flash MUST be aligned, as well as the address on which the buffer is written to the flash. | |
#define | FLASHPAGE_ERASE_STATE (0xFFU) |
State of an erased byte in memory. | |
#define | PERIPH_FLASHPAGE_CUSTOM_PAGESIZES |
Defined to signal that the peripheral has non-uniform flash page sizes. | |
#define | PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR |
If non-uniform flash page sizes are required, defined to signal that the peripheral does not implement a custom flashpage_addr function and instead relies on the generic helper function that relies on flashpage_size. | |
#define | PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE |
If non-uniform flash page sizes are required, defined to signal that the peripheral does not implement a custom flashpage_page function and instead relies on the generic helper function that relies on flashpage_size. | |
#define | FLASH_WRITABLE_INIT(name, size) |
Define an array in flash memory. | |
Enumerations | |
enum | { FLASHPAGE_OK = 0 , FLASHPAGE_NOMATCH = -1 } |
Return values used in this interface. More... | |
Functions | |
static size_t | flashpage_size (unsigned page) |
Get the page size of the given page number. | |
static void * | flashpage_addr (unsigned page) |
Translate the given page number into the page's starting address. | |
static unsigned | flashpage_page (const void *addr) |
Translate the given address into the corresponding page number. | |
void | flashpage_erase (unsigned page) |
Erase the given page. | |
void | flashpage_write_page (unsigned page, const void *data) |
Write the given page with the given data. | |
void | flashpage_write (void *target_addr, const void *data, size_t len) |
Write any number of data bytes to a given location in the flash memory. | |
void | flashpage_read (unsigned page, void *data) |
Read the given page into the given memory location. | |
int | flashpage_verify (unsigned page, const void *data) |
Verify the given page against the given data. | |
int | flashpage_write_and_verify (unsigned page, const void *data) |
Write the given page and verify the results. | |
#define CPU_FLASH_BASE (0) |
Per default, we expect the internal flash to start at address 0.
Definition at line 65 of file flashpage.h.
#define FLASH_WRITABLE_INIT | ( | name, | |
size | |||
) |
Define an array in flash memory.
This macro defines an array stored in the ".flash_writable" section which is part of flash memory. With this macro it is possible to reserve flash memory at build time.
E.g. FLASH_WRITABLE_INIT(a, 2); will create a array with name 'a' of size 2 * FLASHPAGE_SIZE which is stored in flash memory and takes up 2 flash pages.
Symbols created by using this macro are sorted in ascending order by name. Therefore, &a < &b where a and b are arrays created using this macro.
[in] | name | name of the array |
[in] | size | size of the array in unit of FLASHPAGE_SIZE |
Definition at line 173 of file flashpage.h.
#define FLASHPAGE_ERASE_STATE (0xFFU) |
State of an erased byte in memory.
Definition at line 95 of file flashpage.h.
#define FLASHPAGE_WRITE_BLOCK_ALIGNMENT |
The buffers to be written to the flash MUST be aligned, as well as the address on which the buffer is written to the flash.
This variable must be defined for that purpose, according to the MCU align requirements.
Definition at line 86 of file flashpage.h.
#define FLASHPAGE_WRITE_BLOCK_SIZE |
For raw writings to the flash, this constant must define the minimum write length allowed by the MCU.
Definition at line 74 of file flashpage.h.
#define PERIPH_FLASHPAGE_CUSTOM_PAGESIZES |
Defined to signal that the peripheral has non-uniform flash page sizes.
These devices do not define FLASHPAGE_SIZE and do not implement the pagewise api.
Definition at line 106 of file flashpage.h.
#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR |
If non-uniform flash page sizes are required, defined to signal that the peripheral does not implement a custom flashpage_addr function and instead relies on the generic helper function that relies on flashpage_size.
Definition at line 118 of file flashpage.h.
#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE |
If non-uniform flash page sizes are required, defined to signal that the peripheral does not implement a custom flashpage_page function and instead relies on the generic helper function that relies on flashpage_size.
Definition at line 130 of file flashpage.h.
anonymous enum |
Return values used in this interface.
Enumerator | |
---|---|
FLASHPAGE_OK | everything succeeded |
FLASHPAGE_NOMATCH | page differs from target data |
Definition at line 136 of file flashpage.h.
|
inlinestatic |
Translate the given page number into the page's starting address.
[in] | page | page number to get the address of |
Definition at line 202 of file flashpage.h.
void flashpage_erase | ( | unsigned | page | ) |
Erase the given page.
[in] | page | Page to erase |
|
inlinestatic |
Translate the given address into the corresponding page number.
The given address can be any address inside a page.
[in] | addr | address inside the targeted page |
Definition at line 218 of file flashpage.h.
void flashpage_read | ( | unsigned | page, |
void * | data | ||
) |
Read the given page into the given memory location.
[in] | page | page to read |
[out] | data | memory to write the page to, MUST be FLASHPAGE_SIZE byte |
|
inlinestatic |
Get the page size of the given page number.
[in] | page | page number to get the size for |
Definition at line 186 of file flashpage.h.
int flashpage_verify | ( | unsigned | page, |
const void * | data | ||
) |
Verify the given page against the given data.
[in] | page | page to verify |
[in] | data | data to compare page against, MUST be FLASHPAGE_SIZE byte of data |
data
void flashpage_write | ( | void * | target_addr, |
const void * | data, | ||
size_t | len | ||
) |
Write any number of data bytes to a given location in the flash memory.
Both target address and data address must be aligned to FLASHPAGE_BLOCK_ALIGN. len
must be a multiple of FLASHPAGE_WRITE_BLOCK_SIZE. This function doesn't erase any area in flash, thus be sure the targeted memory area is erased before writing on it (using the flashpage_write function).
[in] | target_addr | address in flash to write to. MUST be aligned to FLASHPAGE_WRITE_BLOCK_ALIGNMENT. |
[in] | data | data to write to the address. MUST be aligned to FLASHPAGE_WRITE_BLOCK_ALIGNMENT. |
[in] | len | length of the data to be written. It MUST be multiple of FLASHPAGE_WRITE_BLOCK_SIZE. Also, ensure it doesn't exceed the actual flash memory size. |
int flashpage_write_and_verify | ( | unsigned | page, |
const void * | data | ||
) |
Write the given page and verify the results.
This is a convenience function wrapping flashpage_write and flashpage_verify.
[in] | page | page to write |
[in] | data | data to write to the page, MUST be FLASHPAGE_SIZE byte. |
void flashpage_write_page | ( | unsigned | page, |
const void * | data | ||
) |
Write the given page with the given data.
[in] | page | page to write |
[in] | data | data to write to the page, MUST be FLASHPAGE_SIZE byte. Set to NULL for page erase only. |