Functions for handling internal flash memory.
The internal flash memory on the XMEGA devices consists of the application section, the application table section and the bootloader section. All these sections can store program code for the MCU, but if there is available space, they can be used for storing other persistent data.
Writing the flash memory can only be done one page at a time. It consists of loading the data to the internal page buffer and then running one of the write commands. If the page has not been erased before writing, the data will not be written correctly.
In order to be able to write to flash memory the programming commands need to be run from the boot section.
Macros | |
#define | FLASH_PAGE_SIZE |
#define | FLASH_SIZE |
Size of a flash page in bytes. More... | |
#define | IAR_FLASH_PTR __farflash |
Flash pointer type to use for accessing flash memory with IAR. More... | |
Typedefs | |
typedef uint32_t | flash_addr_t |
Data type for holding flash memory addresses. More... | |
Functions | |
static void | nvm_flash_atomic_write_app_page (flash_addr_t page_addr) |
Erase and write a page within the application section. More... | |
static void | nvm_flash_atomic_write_boot_page (flash_addr_t page_addr) |
Erase and write a page within the boot section. More... | |
void | nvm_flash_erase_and_write_buffer (flash_addr_t address, const void *buf, uint16_t len, bool b_blank_check) |
Erase and write specific parts of application flash section. More... | |
static void | nvm_flash_erase_app (void) |
Erase entire application section. More... | |
static void | nvm_flash_erase_app_page (flash_addr_t page_addr) |
Erase a page within the application section. More... | |
static void | nvm_flash_erase_boot_page (flash_addr_t page_addr) |
Erase a page within the boot section. More... | |
static void | nvm_flash_erase_user_section (void) |
Erase the user calibration section page. More... | |
static void | nvm_flash_flush_buffer (void) |
Flush flash page buffer. More... | |
void | nvm_flash_load_word_to_buffer (uint32_t word_addr, uint16_t data) |
Load word into flash page buffer. More... | |
void | nvm_flash_read_buffer (flash_addr_t address, void *buf, uint16_t len) |
Read buffer within the application section. More... | |
static uint8_t | nvm_flash_read_byte (flash_addr_t addr) |
Load byte from flash memory. More... | |
static uint16_t | nvm_flash_read_word (flash_addr_t addr) |
Load word from flash memory. More... | |
static void | nvm_flash_split_write_app_page (flash_addr_t page_addr) |
Write a page within the application section. More... | |
static void | nvm_flash_split_write_boot_page (flash_addr_t page_addr) |
Write a page within the boot section. More... | |
static void | nvm_flash_write_user_page (void) |
Write the user calibration section page. More... | |
void | nvm_issue_flash_range_crc (flash_addr_t start_addr, flash_addr_t end_addr) |
Issue flash range CRC command. More... | |
void | nvm_user_sig_read_buffer (flash_addr_t address, void *buf, uint16_t len) |
Read buffer within the user section. More... | |
void | nvm_user_sig_write_buffer (flash_addr_t address, const void *buf, uint16_t len, bool b_blank_check) |
Write specific parts of user flash section. More... | |
#define FLASH_PAGE_SIZE |
Referenced by fill_flash_page_buffer(), is_flash_page_equal_to_buffer(), nvm_flash_erase_and_write_buffer(), nvm_get_page_size(), nvm_get_pagenumber(), nvm_get_size(), nvm_page_erase(), nvm_user_sig_read_buffer(), nvm_user_sig_write_buffer(), set_buffer(), test_atomic_write_app_table(), test_atomic_write_boot(), test_split_write_app_table(), and test_split_write_boot().
#define FLASH_SIZE |
Size of a flash page in bytes.
The page size in bytes taken from the toolchain header files.
Referenced by nvm_get_size().
#define IAR_FLASH_PTR __farflash |
Flash pointer type to use for accessing flash memory with IAR.
Referenced by nvm_flash_read_byte(), and nvm_flash_read_word().
typedef uint32_t flash_addr_t |
Data type for holding flash memory addresses.
|
inlinestatic |
Erase and write a page within the application section.
Erase and the write a page within the application section with the data stored in the page buffer. Erase and write is done in an atomic operation.
page_addr | Byte address to the page to delete |
References nvm_common_spm(), and nvm_wait_until_ready().
Referenced by nvm_flash_erase_and_write_buffer(), and test_atomic_write_app_table().
|
inlinestatic |
Erase and write a page within the boot section.
Erase and the write a page within the boot section with the data stored in the page buffer. Erase and write is done in an atomic operation.
page_addr | Byte address to the page to delete |
References nvm_common_spm(), and nvm_wait_until_ready().
Referenced by test_atomic_write_boot().
void nvm_flash_erase_and_write_buffer | ( | flash_addr_t | address, |
const void * | buf, | ||
uint16_t | len, | ||
bool | b_blank_check | ||
) |
Erase and write specific parts of application flash section.
address | the address to where to write |
buf | pointer to the data |
len | the number of bytes to write |
b_blank_check | if True then the page flash is checked before write to run or not the erase page command. |
Set b_blank_check to false if all application flash is erased before.
References FLASH_PAGE_SIZE, LSB, MSB, nvm_flash_atomic_write_app_page(), nvm_flash_load_word_to_buffer(), nvm_flash_read_word(), nvm_flash_split_write_app_page(), and nvm_wait_until_ready().
Referenced by nvm_write(), and nvm_write_char().
|
inlinestatic |
Erase entire application section.
Erase all of the application section.
References nvm_common_spm(), and nvm_wait_until_ready().
|
inlinestatic |
Erase a page within the application section.
Erase one page within the application section
page_addr | Byte address to the page to delete |
References nvm_common_spm(), and nvm_wait_until_ready().
Referenced by nvm_page_erase(), and test_split_write_app_table().
|
inlinestatic |
Erase a page within the boot section.
Erase one page within the boot section
page_addr | Byte address to the page to delete |
References nvm_common_spm(), and nvm_wait_until_ready().
Referenced by nvm_page_erase(), and test_split_write_boot().
|
inlinestatic |
Erase the user calibration section page.
Erase the user calibration section page. There is only one page, so no parameters are needed.
References nvm_common_spm(), and nvm_wait_until_ready().
Referenced by nvm_page_erase(), and nvm_user_sig_write_buffer().
|
inlinestatic |
Flush flash page buffer.
Clear the NVM controller page buffer for flash. This needs to be called before using nvm_flash_load_word_to_buffer if it has not already been cleared.
References nvm_common_spm(), and nvm_wait_until_ready().
void nvm_flash_load_word_to_buffer | ( | uint32_t | word_addr, |
uint16_t | data | ||
) |
Load word into flash page buffer.
Clear the NVM controller page buffer for flash. This needs to be called before using nvm_flash_load_word_to_buffer if it has not already been cleared.
word_addr | Address to store data. The upper bits beyond the page size is ignored. FLASH_PAGE_SIZE |
data | Data word to load into the page buffer |
Referenced by fill_flash_page_buffer(), nvm_flash_erase_and_write_buffer(), and nvm_user_sig_write_buffer().
void nvm_flash_read_buffer | ( | flash_addr_t | address, |
void * | buf, | ||
uint16_t | len | ||
) |
Read buffer within the application section.
address | the address to where to read |
buf | pointer to the data |
len | the number of bytes to read |
References nvm_flash_read_byte(), and nvm_wait_until_ready().
Referenced by nvm_read().
|
inlinestatic |
Load byte from flash memory.
Load one word of flash using byte addressing. IAR has __flash pointers and GCC have pgm_read_byte_xx functions which load data from flash memory. This function used for compatibility between the compilers.
addr | Byte address to load |
References IAR_FLASH_PTR.
Referenced by nvm_flash_read_buffer(), nvm_read_char(), and sound_get_8_bit_sample().
|
inlinestatic |
Load word from flash memory.
Load one word of flash using byte addressing. IAR has __flash pointers and GCC have pgm_read_byte_xx functions which load data from flash memory. This function used for compatibility between the compilers.
addr | Byte address to load (last bit is ignored) |
References IAR_FLASH_PTR.
Referenced by is_flash_page_equal_to_buffer(), nvm_flash_erase_and_write_buffer(), sound_get_16_bit_sample(), and sound_get_next_sinewave_sample().
|
inlinestatic |
Write a page within the application section.
Write a page within the application section with the data stored in the page buffer. The page needs to be erased before the write to avoid corruption of the data written.
page_addr | Byte address to the page to delete |
References nvm_common_spm(), and nvm_wait_until_ready().
Referenced by nvm_flash_erase_and_write_buffer(), and test_split_write_app_table().
|
inlinestatic |
Write a page within the boot section.
Write a page within the boot section with the data stored in the page buffer. The page needs to be erased before the write to avoid corruption of the data written.
page_addr | Byte address to the page to delete |
References nvm_common_spm(), and nvm_wait_until_ready().
Referenced by test_split_write_boot().
|
inlinestatic |
Write the user calibration section page.
Write a the user calibration section page with the data stored in the page buffer. The page needs to be erased before the write to avoid corruption of the data written. There is only one page, so no parameters are needed.
References nvm_common_spm(), and nvm_wait_until_ready().
Referenced by nvm_user_sig_write_buffer().
void nvm_issue_flash_range_crc | ( | flash_addr_t | start_addr, |
flash_addr_t | end_addr | ||
) |
Issue flash range CRC command.
This function sets the FLASH range CRC command in the NVM.CMD register. It then loads the start and end byte address of the part of FLASH to generate a CRC-32 for into the ADDR and DATA registers and finally performs the execute command.
start_addr | end byte address |
end_addr | start byte address |
References ccp_write_io().
void nvm_user_sig_read_buffer | ( | flash_addr_t | address, |
void * | buf, | ||
uint16_t | len | ||
) |
Read buffer within the user section.
address | the address to where to read |
buf | pointer to the data |
len | the number of bytes to read |
References FLASH_PAGE_SIZE, and nvm_read_user_signature_row().
Referenced by nvm_read(), nvm_read_char(), nvram_read(), and test_read().
void nvm_user_sig_write_buffer | ( | flash_addr_t | address, |
const void * | buf, | ||
uint16_t | len, | ||
bool | b_blank_check | ||
) |
Write specific parts of user flash section.
address | the address to where to write |
buf | pointer to the data |
len | the number of bytes to write |
b_blank_check | if True then the page flash is checked before write to run or not the erase page command. |
Set b_blank_check to false if all application flash is erased before.
References FLASH_PAGE_SIZE, LSB, MSB, nvm_flash_erase_user_section(), nvm_flash_load_word_to_buffer(), nvm_flash_write_user_page(), and nvm_read_user_signature_row().
Referenced by nvm_write(), nvm_write_char(), nvram_write(), test_read(), test_write_and_erase(), and test_write_no_erase().