Skip to content

Commit

Permalink
Added checks for accidentally disabling SPIEN or enabling RSTDISBL
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Oct 18, 2013
1 parent 057b270 commit 4782e9d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Atmega_Hex_Uploader/Atmega_Hex_Uploader.ino
Expand Up @@ -25,11 +25,14 @@
// Version 1.16: Allowed for running on the Leonardo, Micro, etc.
// Version 1.17: Added timed writing for Atmega8
// Version 1.18: Added support for running on an Atmega2560
// Version 1.19: Added safety checks for high fuse, so you can't disable SPIEN or enable RSTDISBL etc.

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

#define ALLOW_MODIFY_FUSES true // make false if this sketch doesn't fit into memory
#define ALLOW_FILE_SAVING true // make false if this sketch doesn't fit into memory
#define SAFETY_CHECKS true // check for disabling SPIEN, or enabling RSTDISBL

/*
For more details, photos, wiring, instructions, see:
Expand Down Expand Up @@ -70,7 +73,7 @@ const bool allowTargetToRun = true; // if true, programming lines are freed whe

// #include <memdebug.h>

const char Version [] = "1.18";
const char Version [] = "1.19";

// bit banged SPI pins
#ifdef __AVR_ATmega2560__
Expand Down Expand Up @@ -1430,6 +1433,20 @@ void modifyFuses ()
return;
} // end if no change to fuse

#if SAFETY_CHECKS
if (fusenumber == highFuse && (newValue & 0xC0) != 0xC0)
{
Serial.println (F("Activating RSTDISBL/DWEN/OCDEN/JTAGEN not permitted."));
return;
} // end safety check

if (fusenumber == highFuse && (newValue & 0x40) != 0)

This comment has been minimized.

Copy link
@liudr

liudr Dec 4, 2014

I hope that I'm wrong but I think that your SPIEN bit is wrong! It's 0x20, not 0x40. Read your own def in fuse calc sketch or fuse page.

{
Serial.println (F("Disabling SPIEN not permitted."));
return;
} // end safety check
#endif // SAFETY_CHECKS

// get confirmation
Serial.println (F("WARNING: Fuse changes may make the processor unresponsive."));
Serial.print (F("Confirm change "));
Expand Down

3 comments on commit 4782e9d

@liudr
Copy link

@liudr liudr commented on 4782e9d Dec 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope that I'm wrong but I think that your SPIEN bit is wrong! It's 0x20, not 0x40. Read your own def in fuse calc sketch or fuse page.

@nickgammon
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Fixed in commit 0487a55.

@liudr
Copy link

@liudr liudr commented on 4782e9d Dec 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Nick.

Please sign in to comment.