Skip to content

Commit f90a346

Browse files
committed
Cleared temporary flash area to 0xFF before writing to it
1 parent 3f21793 commit f90a346

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Atmega_Hex_Uploader/Atmega_Hex_Uploader.ino

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
/*
99
10+
For more details, photos, wiring, instructions, see:
11+
12+
http://www.gammon.com.au/forum/?id=11638
13+
14+
1015
Copyright 2012 Nick Gammon.
1116
1217
@@ -380,6 +385,14 @@ void showProgress ()
380385
Serial.print (F("#")); // progress bar
381386
} // end of showProgress
382387

388+
// clear entire temporary page to 0xFF in case we don't write to all of it
389+
void clearPage ()
390+
{
391+
unsigned int len = signatures [foundSig].pageSize;
392+
for (int i = 0; i < len; i++)
393+
writeFlash (i, 0xFF);
394+
} // end of clearPage
395+
383396
// commit page to flash memory
384397
void commitPage (const unsigned long addr)
385398
{
@@ -395,8 +408,10 @@ void commitPage (const unsigned long addr)
395408

396409
program (writeProgramMemory, highByte (addr >> 1), lowByte (addr >> 1));
397410
pollUntilReady ();
398-
} // end of commitPage
399411

412+
clearPage(); // clear ready for next page full
413+
} // end of commitPage
414+
400415
// write data to temporary buffer, ready for committing
401416
void writeData (const unsigned long addr, const byte * pData, const int length)
402417
{
@@ -624,6 +639,7 @@ boolean readHexFile (const char * fName, const byte action)
624639
Serial.println (F("Erasing chip ..."));
625640
program (progamEnable, chipErase); // erase it
626641
pollUntilReady ();
642+
clearPage(); // clear temporary page
627643
Serial.println (F("Writing flash ..."));
628644
break;
629645
} // end of switch

0 commit comments

Comments
 (0)