I gave my Teensy a virus, and now I can't flash it

Status
Not open for further replies.
Hey all,

I think I've rendered my Teensy useless by uploading some code to it that makes the MCU go into sleep mode 3 seconds after it boots up.

To make matters worse, I tweaked the code after loading it, so I don't have the exact code that is on it to debug.

I'm using the LowPower library from duff.

Here is the code that I believe is loaded on it:

Code:
#include <LowPower_Teensy3.h>

TEENSY3_LP LP = TEENSY3_LP();

volatile boolean teensySleep=false;
float startTime=millis();

uint32_t Serialbaud = 4800;

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns

byte colPins[COLS] = {
  19, 20, 21, 22}; //connect to the row pinouts of the keypad
byte rowPins[ROWS] = {
  15, 16, 17, 18}; //connect to the column pinouts of the keypad

void keypadSleep(){
  for(int r=0; r<ROWS; r++){
    pinMode(rowPins[r],INPUT_PULLUP); //Pull row pins high (internal pullup)
    attachInterrupt(rowPins[r], callbackhandler, CHANGE);
  }
  for (int c=0; c<COLS; c++){
    pinMode(colPins[c], OUTPUT); //Connect columns to ground
    digitalWrite(colPins[c], LOW);
  }
}

void callbackhandler() {
  teensySleep= false;
  Serial.println("Change on a row pin!, disabling Teensy sleep");
  startTime=millis();
}

void setup() { 
  Serial.begin(Serialbaud);  //Begin serial communication with Serial Monitor
  while(!Serial);
  Serial.println("Serial monitor operational");
  Serial.println("Beginning main loop");
}

void loop() {
  delay(3000);
  Serial.println("Putting Teensy to sleep");
  keypadSleep(); //Setup wakeup pins for Teensy
  delay(10);
  LP.Sleep();
  Serial.println("I'm awake!");
  teensySleep=false;
}

If I reboot my PC (to fix the serial driver enumeration problem where Windows doesn't see the Teensy if you plug/unplug it), connect the usb cable to the Teensy, and plug the Teensy into my battery (note: Vusb traces have been cut so Teensy only boots up once I connect the battery), and start clicking on the Serial Monitor button in Arduino IDE, it will open and print "Putting Teensy to sleep".

So, to flash my Teensy with a new program, I need to do so in that initial 3 second window between the Teensy booting up and going to sleep.

Problem is, it's not working. The timing is really hard to get right. You have to click "Upload" in Arduino IDE and then wait for compile, then wait for upload to Teensy Loader, then plug the battery in to boot the Teensy at just the right moment.

I'm not even sure if the Teensy Loader is able to function in such a short time window.

Help!
 
yeah, any time you put honked up code on the Teensy3, you have to compile a known good program like examples/blinky, then push the Teensy's reset button and get it to download a program that doesn't run amok.
 
Phew, got it! Never mind!

Have you ever had a problem, googled for it, and found dead forum threads describing the same problem? If the thread dies because no-one knows how to fix it, nothing can be done. But "fixed it, kthanxbai" does nothing to help the next person.

Which is probably why stevech posted :) - is what he describes also how you solved it?
 
Have you ever had a problem, googled for it, and found dead forum threads describing the same problem? If the thread dies because no-one knows how to fix it, nothing can be done. But "fixed it, kthanxbai" does nothing to help the next person.

Which is probably why stevech posted :) - is what he describes also how you solved it?

Yep, exactly, to the tee, what stevech said. Kept trying the plug the battery in boot method, but couldn't get the timing right. Then, in exasperation, pushed the reset button on the teensy (with a jeweller's screwdriver, since this particular teensy is already embedded in a bike trailer), and the blink example I was trying to upload magically jumped on!
 
Status
Not open for further replies.
Back
Top