sketches/SerialReadWrite/optiboot.h
// Function to write data to a flash page
Function to write data to a flash page
Function to write data to a flash page
void optiboot_writePage(const char allocated_flash_space[], uint8_t data_to_store[], uint16_t page)
{
  uint16_t word_buffer = 0; 
  optiboot_page_erase((optiboot_addr_t)(void*) &allocated_flash_space[SPM_PAGESIZE*(page-1)]);
  for(uint16_t i = 0; i < SPM_PAGESIZE; i++) 
  {
    if(i % 2 == 0) 
      word_buffer = data_to_store[i];
    else 
    {
      word_buffer += (data_to_store[i] << 8);
      optiboot_page_fill((optiboot_addr_t)(void*) &allocated_flash_space[i + SPM_PAGESIZE*(page-1)], word_buffer);
    }
  }
  optiboot_page_write((optiboot_addr_t)(void*) &allocated_flash_space[SPM_PAGESIZE*(page-1)]);
}
void optiboot_writePage ( const char allocated_flash_space [ ] , uint8_t data_to_store [ ] , uint16_t page ) { uint16_t word_buffer = 0 ; optiboot_page_erase ( ( optiboot_addr_t ) ( void * ) & allocated_flash_space [ SPM_PAGESIZE * ( page - 1 ) ] ) ; for ( uint16_t i = 0 ; i < SPM_PAGESIZE ; i ++ ) { if ( i % 2 == 0 ) word_buffer = data_to_store [ i ] ; else { word_buffer += ( data_to_store [ i ] << 8 ) ; optiboot_page_fill ( ( optiboot_addr_t ) ( void * ) & allocated_flash_space [ i + SPM_PAGESIZE * ( page - 1 ) ] , word_buffer ) ; } } optiboot_page_write ( ( optiboot_addr_t ) ( void * ) & allocated_flash_space [ SPM_PAGESIZE * ( page - 1 ) ] ) ; }
Function to write data to a flash page
Function to write data to a flash page
// Erase the flash page // Copy ram buffer to temporary flash buffer // We must write words // Writing temporary buffer to flash