HWA
Bare metal programming with style
Class _fla: Flash memory

This class is used by:

Actions



hw( read, ... ) - Read one byte at given memory address:

uint8_t byte = hw( read, flash0, addr ); // Read byte at address addr



hw( read_bytes, ... ) - Copy n bytes from Flash memory to RAM:

uint8_t dst[10];
uint8_t count = sizeof(dst);
hw( read_bytes, flash0, dst, addr, count ); // Copy count bytes from Flash address addr to dst



hw( load_buffer, ... ), hw( erase_page, ... ), hw( write_page, ... ) - Write data to Flash memory

Writing into the memory requires a special procedure:

  1. Load a page buffer with the content to be written. HW_DEVICE_FLASH_PAGE_SIZE gives the page buffer size.
  2. Erase the page to be programmed.
  3. Program the page with the content of the page buffer.

Steps 1 & 2 can be done in any order.

intptr_t zpage = address & ~(HW_DEVICE_FLASH_PAGE_SIZE-1) ;
hw( load_buffer, flash0, page ); // Store data into the memory page buffer
hw( erase_page, flash0, zpage ); // Erase memory page
hw( write_page, flash0, zpage ); // Program memory page with page buffer content

Registers

Harware registers:

Logical registers:

HW_DEVICE_FLASH_PAGE_SIZE
#define HW_DEVICE_FLASH_PAGE_SIZE
Definition: atmega168x.h:37
hw
#define hw(...)
hw( action, object [,...] ) executes an action immediately on an object.
Definition: hwa_macros.h:523