Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
MCUdude committed Oct 6, 2016
1 parent a4cbe1d commit 3edab40
Showing 1 changed file with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
// Define your termination and blank character here
const char terminationChar = '@';

// This is the character that gets printed if the memory doesn't contain any data
// This is the character that gets printed if the memory block doesn't contain any data
const char blankChar = '.';


Expand All @@ -52,7 +52,7 @@ char returnToMenu;
uint8_t ramBuffer[SPM_PAGESIZE];

// This array allocates the space you'll be able to write to
const char flashSpace[SPM_PAGESIZE * NUMBER_OF_PAGES] __attribute__ (( aligned(SPM_PAGESIZE) )) PROGMEM = {
const uint8_t flashSpace[SPM_PAGESIZE * NUMBER_OF_PAGES] __attribute__ (( aligned(SPM_PAGESIZE) )) PROGMEM = {
"This some default content stored on page one"
};

Expand All @@ -77,10 +77,13 @@ void loop()
Serial.print(F("| There are "));
Serial.print(NUMBER_OF_PAGES);
Serial.println(F(" pages that can be read/written to. |"));
Serial.print(F("| Total assigned flash space: "));
Serial.print(NUMBER_OF_PAGES * SPM_PAGESIZE);
Serial.println(F(" bytes. |"));
Serial.println(F("| Change the NUMBER_OF_PAGES constant to |"));
Serial.println(F("| increase or decrease this number. |"));
Serial.println(F("| |"));
Serial.println(F("| Please tell me what you want to do: |"));
Serial.println(F("| What do you want to do? |"));
Serial.println(F("| 1. Show current flash content |"));
Serial.println(F("| 2. Write to flash memory |"));
Serial.println(F("|------------------------------------------------|"));
Expand Down Expand Up @@ -120,22 +123,41 @@ void loop()
Serial.println(F(". The number of pages can be extended by changing NUMBER_OF_PAGES constant"));
}
}
while(pageNumber < 1 || pageNumber > NUMBER_OF_PAGES);
Serial.println(pageNumber);
while(pageNumber > NUMBER_OF_PAGES);

if(pageNumber > 0)
Serial.println(pageNumber);

// READ SELECTED PAGE AND STORE THE CONTENT IN THE ramBuffer ARRAY
// flash_buffer is where the data is stored (contains the memory addresses)
// ramBuffer is where the data gets stored after reading from flash
// pageNumber is the page the data is read from
// blankChar is the character that gets printed/stored if there are unused space (default '.')
// use optiboot_readPage(flashSpace, ramBuffer, pageNumber) if you don't want blank chars
optiboot_readPage(flashSpace, ramBuffer, pageNumber, blankChar);

// Print page content
Serial.print(F("\nContent of page "));
Serial.print(pageNumber);
Serial.println(F(":"));
Serial.println((char*)ramBuffer);

if(pageNumber == 0) // Read all pages
{
Serial.println(F("\nAll flash content:"));
for(uint16_t page = 1; page < NUMBER_OF_PAGES+1; page++)
{
Serial.print(F("Page "));
Serial.print(page);
Serial.print(F(": "));
optiboot_readPage(flashSpace, ramBuffer, page, blankChar);
Serial.println((char*)ramBuffer);
}
}
else // Read selected page
{
optiboot_readPage(flashSpace, ramBuffer, pageNumber, blankChar);

// Print page content
Serial.print(F("\nContent of page "));
Serial.print(pageNumber);
Serial.println(F(":"));
Serial.println((char*)ramBuffer);
}

} // End of flash read option


Expand Down

0 comments on commit 3edab40

Please sign in to comment.