duff2013 / Snooze

Teensy Low Power Library
MIT License
132 stars 37 forks source link

Teensy MicroMod support #109

Closed david-res closed 2 years ago

david-res commented 2 years ago

I know the T4.1 was never fully supported with this library, as the original T4.x support was implemented for the 31 pins on the T4.0 But I just tried to run a simple example on a Teensy MicroMod and it doesn't even reboot. After flashing the Teensy I get 9 blinks on the program led. From the PJRC website under the T4 bootloader page:

9 Blinks = ARM JTAG DAP Init Error The ARM JTAG DAP was detected (4 blinks) but could not be initialized. This error is rather unlikely!

`#include "Snooze.h"

include "FlexCAN_T4.h"

define canRx 30

FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_16> Can0;

SnoozeUSBSerial usb; SnoozeDigital digital;// this is the pin wakeup driver SnoozeBlock config_teensy(usb, digital);

void setup() { pinMode(13, OUTPUT); digitalWrite(13, HIGH); Can0.begin(); Can0.setClock(CLK_60MHz); Can0.setBaudRate(500000); //Can0.enablInterrupt(); Can0.onReceive(canSniff); }

const int loopDelay1 = 5; unsigned long timeNow1 = 0; const long SleepTimer = 30000; // Time to go to sleep unsigned long startTime = 0;

void loop() { if (millis() > startTime + SleepTimer) { hibernateTeensy(); } else{ if (millis() > timeNow1 + loopDelay1){ timeNow1 = millis(); } } }

void hibernateTeensy(){ Serial.println("...Time to Sleep...."); digitalWrite(13, LOW); digital.pinMode(canRx, INPUT_PULLUP, RISING);

//Snooze.deepSleep( config_teensy ); //Snooze.sleep( config_teensy ); Snooze.hibernate(config_teensy); }

void canSniff (const CAN_message_t &msg){ startTime = millis(); // Resets the go to sleep clock at the beginning of the loop }`

I will test the code on a T4 and 4.1 and see if it can be replicated there as well.

david-res commented 2 years ago

Fixed by setting function startup_early_hook into FLASHMEM