Skip to content

Commit

Permalink
safe mode
Browse files Browse the repository at this point in the history
- allows you to reflash the device even if you've uploaded a sketch that
  interferes with the normal reflashing process (corrupts memory, turns
  off power to USB, etc)
- Thanks @Wozza365 for giving me this idea.

This is also solvable by shorting the reset pin but @Wozza365 was having
a heck of a time getting that working because the 8 seconds that you're
given to start the upload post reset were too short.  His computer was
not  recognizing the USB device in that amount of time.  This tiny
change would have allowed him to boot into safe mode and then take his
time following the typical reflash process.
  • Loading branch information
joshgoebel committed May 26, 2015
1 parent 55a3a0e commit 2436868
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Arduboy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ void Arduboy::start()
SPI.transfer(end & 0x07);

LCDDataMode();
#ifdef SAFE_MODE
if (pressed(LEFT_BUTTON+UP_BUTTON))
safeMode();
#endif
}

// Safe Mode is engaged by holding down both the LEFT button and UP button
// when plugging the device into USB. It puts your device into a tight
// loop and allows it to be reprogrammed even if you have uploaded a very
// broken sketch that interferes with the normal USB triggered auto-reboot
// functionality of the device.
void Arduboy::safeMode()
{
display(); // too avoid random gibberish
while (true) {
asm volatile("nop \n");

This comment has been minimized.

Copy link
@joshgoebel

joshgoebel May 26, 2015

Author Owner

I can pull this out (the NOP) if there is objection but for some reason I thought it was nicer.

}
}

void Arduboy::LCDDataMode()
Expand Down
2 changes: 2 additions & 0 deletions Arduboy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Print.h>

#define PIXEL_SAFE_MODE
#define SAFE_MODE

#define CS 6
#define DC 4
Expand Down Expand Up @@ -69,6 +70,7 @@ class Arduboy : public Print

private:
unsigned char sBuffer[(HEIGHT*WIDTH)/8];
void safeMode();
uint8_t readCapacitivePin(int pinToMeasure);
uint8_t readCapXtal(int pinToMeasure);
volatile uint8_t *mosiport, *clkport, *csport, *dcport;
Expand Down

0 comments on commit 2436868

Please sign in to comment.