I'm trying to store a value into the user page of the flash, but it's unclear to me how to write it first to the page buffer.
Using the AVR32UC3A1265
From the [Datasheet]:
Embedded Flash Start Address: 0x8000_0000
Flash Size (FLASH_PW): 256Kbytes
Number of pages (FLASH__P): 512
Page size (FLASH_W): 128 words
I came up with the code below, but I'm not sure if it's correct. Especily how to store my data (the user_page_data_t struct) in the page buffer.
There is no defined address for the pagebuffer? So how does flashc_write_user_page() know what to write?
//struct size must be == AVR32_FLASHC_PAGE_SIZE == 512
typedef struct
{
uint8_t cell_address;
uint8_t Reserved[511];
} userpage_data_t;
userpage_data_t userpageData;
//prepare data to be written
userpageData.cell_address = cell_address;
//clear page buffer (set all bits from zero to one)
flashc_clear_page_buffer();
//get the address of page buffer
uint32_t page_buffer_address = AVR32_FLASHC_USER_PAGE_ADDRESS;
// write the data to the upage buffer (Writing to the page buffer can only change page buffer bits from one to zero)
*page_buffer_address = userpageData;
//erase the userpage
flashc_erase_user_page(true);
//write from the user_page buffer to the actual user_page
flashc_write_user_page();
Can anyone elaborate on the page buffer, and how to use it to store the data you want to write to the (user) page?