Skip to content

Commit

Permalink
Allow to run without SD card (eg. to change fuses)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Nov 9, 2012
1 parent 37abb00 commit 1469ebf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
9 changes: 5 additions & 4 deletions Atmega_Board_Programmer/Atmega_Board_Programmer.ino
Expand Up @@ -299,6 +299,9 @@ void pollUntilReady ()
// commit page
void commitPage (unsigned long addr)
{
Serial.print (F("Committing page starting at 0x"));
Serial.println (addr, HEX);

addr >>= 1; // turn into word address

// set the extended (most significant) address byte if necessary
Expand All @@ -308,9 +311,6 @@ void commitPage (unsigned long addr)
program (loadExtendedAddressByte, 0, MSB);
lastAddressMSB = MSB;
} // end if different MSB

Serial.print (F("Committing page starting at 0x"));
Serial.println (addr, HEX);

program (writeProgramMemory, highByte (addr), lowByte (addr));
pollUntilReady ();
Expand Down Expand Up @@ -364,7 +364,6 @@ void writeBootloader ()
unsigned int len = signatures [foundSig].loaderLength;
unsigned long pagesize = signatures [foundSig].pageSize;
unsigned long pagemask = ~(pagesize - 1);
unsigned long oldPage = addr & pagemask;
byte * bootloader = signatures [foundSig].bootloader;


Expand Down Expand Up @@ -399,6 +398,8 @@ void writeBootloader ()
Serial.println (F("Using Uno Optiboot 16 MHz loader."));
} // end of being Atmega328P

unsigned long oldPage = addr & pagemask;

Serial.println (F("Type 'V' to verify, or 'G' to program the chip with the bootloader ..."));
char command;
do
Expand Down
51 changes: 43 additions & 8 deletions Atmega_Hex_Uploader/Atmega_Hex_Uploader.ino
Expand Up @@ -19,6 +19,7 @@
// Version 1.11: Added signature for Atmega8
// Version 1.11: Added signature for Atmega32U4
// Version 1.12: Added option to allow target to run when not being programmed
// Version 1.13: Changed so you can set fuses without an SD card active.

const bool allowTargetToRun = true; // if true, programming lines are freed when not programming

Expand Down Expand Up @@ -60,7 +61,7 @@ const bool allowTargetToRun = true; // if true, programming lines are freed whe

// #include <memdebug.h>

const char Version [] = "1.12";
const char Version [] = "1.13";

// bit banged SPI pins
const byte MSPIM_SCK = 4; // port D bit 4
Expand Down Expand Up @@ -320,6 +321,7 @@ int foundSig = -1;
byte lastAddressMSB = 0;
// copy of current signature entry for matching processor
signatureType currentSignature;
boolean haveSDcard;

// execute one programming instruction ... b1 is command, b2, b3, b4 are arguments
// processor may return a result on the 4th transfer, this is returned.
Expand Down Expand Up @@ -953,6 +955,12 @@ boolean updateFuses (const boolean writeIt)

void showDirectory ()
{
if (!haveSDcard)
{
Serial.println (F("*** No SD card detected."));
return;
}

// list files in root directory

SdFile file;
Expand Down Expand Up @@ -1028,9 +1036,15 @@ void setup ()
// initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
// breadboards. use SPI_FULL_SPEED for better performance.
if (!sd.begin (chipSelect, SPI_HALF_SPEED))
sd.initErrorHalt();

showDirectory ();
{
sd.initErrorPrint();
haveSDcard = false;
}
else
{
haveSDcard = true;
showDirectory ();
}

// Serial.print (F("Free memory = "));
// Serial.println (getFreeMemory (), DEC);
Expand Down Expand Up @@ -1093,6 +1107,12 @@ boolean getYesNo ()

void readFlashContents ()
{
if (!haveSDcard)
{
Serial.println (F("*** No SD card detected."));
return;
}

progressBarCount = 0;
pagesize = currentSignature.pageSize;
pagemask = ~(pagesize - 1);
Expand Down Expand Up @@ -1219,6 +1239,12 @@ void readFlashContents ()

void writeFlashContents ()
{
if (!haveSDcard)
{
Serial.println (F("*** No SD card detected."));
return;
}

if (chooseInputFile ())
return;

Expand All @@ -1238,6 +1264,12 @@ void writeFlashContents ()

void verifyFlashContents ()
{
if (!haveSDcard)
{
Serial.println (F("*** No SD card detected."));
return;
}

if (chooseInputFile ())
return;

Expand Down Expand Up @@ -1389,10 +1421,13 @@ void loop ()
Serial.println (F("Actions:"));
Serial.println (F(" [E] erase flash"));
Serial.println (F(" [F] modify fuses"));
Serial.println (F(" [L] list directory"));
Serial.println (F(" [R] read from flash (save to disk)"));
Serial.println (F(" [V] verify flash (compare to disk)"));
Serial.println (F(" [W] write to flash (read from disk)"));
if (haveSDcard)
{
Serial.println (F(" [L] list directory"));
Serial.println (F(" [R] read from flash (save to disk)"));
Serial.println (F(" [V] verify flash (compare to disk)"));
Serial.println (F(" [W] write to flash (read from disk)"));
} // end of if SD card detected
Serial.println (F("Enter action:"));

// discard any old junk
Expand Down

0 comments on commit 1469ebf

Please sign in to comment.