AV32 write to user page: user_page_buffer

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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? 

Last Edited: Tue. Jun 28, 2022 - 09:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
//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;

does not put anything into the page buffer.


Replace the above with memcpy( (void *) AVR32_FLASHC_USER_PAGE_ADDRESS, &userpageData, sizeof( userpageData ) );

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So the page buffer is the same as the AVR32_FLASHC_USER_PAGE_ADDRES?
That is not what I was expecting, since the datasheet instructs that you first have to write to the page buffer,
Then the page buffer is written to the page (user page in my case). 
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If AVR32 are like other AVRs then there's something like an overlaying "holding tank" superimposed on a flash page. So you start to make writes to a range of addresses in a page. But the bytes don't immediately go to the flash but a "hidden" page of RAM. When you have set up everything you want to commit you then issue a command to say "write buffer to page" (or maybe "erase page then write buffer to it") and then the whole high-voltage process of writing the N bytes of the page from buffer to actual flash occurs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah oke, I think that principle is also there in the AVR32, where the "holding tank" is the page buffer. 
I couldn't find any information about this buffer, but your suggestion explains that: the page buffer is already the page (but "hidden"). and the write will make that persists.
(I know it doesn't exactly work like that, but a basic understanding of the principle is enough for me, so I can use the flash functions correctly).

I will give it a try in the next few days, and I will give an update with the results.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It worked , final code to read and write to the userpage of AVR32:
Thanks for the help.

 

                //prepare data to be written
                userpageData.cell_address = 255; 
                //clear page buffer
                flashc_clear_page_buffer(); 
                // write the data to the user_page buffer
                memcpy( (void *) AVR32_FLASHC_USER_PAGE_ADDRESS, &userpageData, sizeof( userpageData ) );
                //erase the userpage
                flashc_erase_user_page(TRUE);
                //write from the user_page buffer to the actual user_page
                flashc_write_user_page();
                
                //read the cell address from userpage 
                userpage_data_t* pointer = (userpage_data_t*)AVR32_FLASHC_USER_PAGE_ADDRESS;
                userpage_data_t userpageReadData = *pointer;
                CELL_ADDRESS = userpageReadData.cell_address;