Problem with Snooze library - USB Program mode

Status
Not open for further replies.

r5gordini

Member
Hi All,

Great stuff on the Teensy and all the amazing libraries especially targeted to it.

I have an embedded application where the Teensy will be powered 24/7. It will sleep (hibernate or deepSleep) using the Snooze library. Occasionally, I may want to program the Teensy. Problem is, it will be inaccessible, so I won't be able to press the Program button.

Normally that's not an issue, but I'm finding that the Teensy will not respond to a USB-based request to enter program mode AFTER it has been slept and woken. Does anyone have any experience of solving this issue?

I don't want to add a manual button to my project due to its embedded nature - I only have two button inputs to the project and these have different functions.

Here's my code. Yes, I am using the USBSerial driver for Snooze.

Code:
SnoozeDigital motionDigital;
SnoozeDigital ignDigital;
SnoozeUSBSerial usb;

SnoozeBlock config_teensy32(usb, motionDigital, ignDigital);

motionDigital.pinMode(wakePin, INPUT, FALLING);//pin, mode, type 
ignDigital.pinMode(ignPin, INPUT, RISING);//pin, mode, type 

int who = Snooze.hibernate( config_teensy32 );// return module that woke processor

// wait for serial monitor
  elapsedMillis time = 0;
  while (!Serial && time < 1000) {
    Serial.write(0x00);// print out a bunch of NULLS to serial monitor
    digitalWriteFast(LED_BUILTIN, HIGH);
    threads.delay(30);
    digitalWriteFast(LED_BUILTIN, LOW);
    threads.delay(30);
  }
  // normal delay for Arduino Serial Monitor
  threads.delay(2000);

Andrew
 
Not sure about Snooze and if Hibernate somehow precludes USB from restarting - glanced at the Snooze page and it didn't say so.

Also no idea if threads.delay() may be doing something that prevents the USB initialization process - or the controlling code has this as one thread among others where its servicing process may be the problem. That isn't a complete runnable program.

There is an example :: hardware\teensy\avr\libraries\Snooze\examples\sleep\sleep_usb_serial\sleep_usb_serial.ino That should give proper function, though - except the threads.delay() - looks like that code may have been used for reference. That code isn't going to run for the application at hand - but if it runs as written and then again substituting Hibernate then the problem would seem to be elsewhere in code shown or not shown.

Also not indicated what the USB Host OS and Serial App in use is - it may not respond as quickly as hoped in this situation either because the app or OS isn't getting/giving clear signals. Depending on the hub or connective hardware and software 2 or 2.5+ seconds might be needed. Running the indicated sample will give a way to see that needed time beyond 1000 ms.
 
Using deepSleep or hibernate will put the boot-loader chip into a low power state that only wakes with the program button push to get it into boot loader mode again. You don't have to use Snooze and roll your own lower power code and this will be true also.
 
Thanks guys. Sorry for not posting a fully runnable program. I know the rules!

So the boot-loader goes into a low power state that only wakes with the program button push. Interesting!

I wonder if it could be pulled low by a digital write from another Teensy pin? Obviously I'd need some way of triggering it at the appropriate time...

Andrew
 
Using deepSleep or hibernate will put the boot-loader chip into a low power state that only wakes with the program button push to get it into boot loader mode again. You don't have to use Snooze and roll your own lower power code and this will be true also.

Hi duff,

I am a beginner user.

In my project, after hibernating I need to perform a reset. To do this, I execute the following:

Code:
static void hibernate(void) {
  // Get the module that woke processor
  int who = Snooze.hibernate( config_teensy35 );

  if (who == SNOOZE_DIGITAL_PIN_SELECTED) { // pin wakeup source is its pin value
    for (int i = 0; i < 1; i++) {
      digitalWrite(LED_BUILTIN, HIGH);
      delay(200);
      digitalWrite(LED_BUILTIN, LOW);
      delay(200);
    }
  }

  if (who == 36) { // timer wakeup value
    for (int i = 0; i < 2; i++) {
      digitalWrite(LED_BUILTIN, HIGH);
      delay(200);
      digitalWrite(LED_BUILTIN, LOW);
      delay(200);
    }
  }
   _reboot_Teensyduino_();   // <-- reset by hardware, working in 3.5 version

} // hibernate

Is there a way to restart the boot-loader after waking up from hibernation without physically pressing the button?

Thank you.
 
Is there a way to restart the boot-loader after waking up from hibernation without physically pressing the button?

What Teensy are you using? If not T4.0/1 then not currently but it will in the next update. There will be an option to wakeup from a reset with hibernate. I'm going to try to work on the library in the next week if I can get time and energy :).
 
Status
Not open for further replies.
Back
Top