Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Teensy 4.1 snooze library ... resets

  1. #1
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    507

    Teensy 4.1 snooze library ... resets

    Hi,

    For the TeensyBatdetector I am currently implementing a simple way to allow users to put the device somewhere ready to record (autorecording) ultrasounds at night without a need to look
    after the device. The device is programmed with a wakeup and a sleep moment and during the sleep I want to use the snooze library.
    I have allready added and tested this to the code for a Teensy 3.6 and it works fine. But for the T4.1 I do not seem to be able to get the sleep routine to recover without simply resetting.

    I cant share the full code as this is part of a larger project but I followed the main guidelines:

    Code:
    #include "Snooze.h"
    uint16_t timerWakeup_counter = 0; //keep track of the no of wakeups
    SnoozeTimer timer;
    SnoozeUSBSerial usb;
    
    #if defined(__IMXRT1062__)
    SnoozeBlock config_teensy41(usb, timer);
    #elif defined(__MK66FX1M0__)
    SnoozeBlock config_teensy36(usb, timer);
    #endif
    then in setup
    Code:
    #if defined(__IMXRT1062__)
      timer.setTimer(10);// seconds on T4.1
      //alarm.setRtcTimer(0, 0, 5);
    #elif defined(__MK66FX1M0__)
      timer.setTimer(5000);// milliseconds on T3.6
    #endif
    and finally in the loop
    Code:
    #if defined(__IMXRT1062__)
          who = Snooze.deepSleep(config_teensy41);// return module that woke processor
        #elif defined(__MK66FX1M0__)
          who = Snooze.sleep(config_teensy36);// return module that woke processor
        #endif
    delay(100); // start with a minor delay after wakeup to keep the USB-powerpack "alive"
    In the T3.6 this works, on the T4.1 it fails ... and its very unclear where it fails ...
    Any help/guidance is appreciated, the snooze library seems the only public library to make this kind of thing "reasonably" simple.

    kind regards
    Cor

  2. #2
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    416
    Yes, for the T4.1 the wake-up method from DeepSleep is reset.
    The Library does not seem to be supported any more. I have asked info about the library a number of times without any response.

  3. #3
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    507
    Ah ... I see my code still shows deepsleep ... my bad. But I have tried the same with sleep and this also fails. When I use the demo-code (sleep_usb_serial.ino) from the
    library that does work as planned. But I have the feeling the library is not taking all the options a T4.1 can be using into account or so. Very unclear what causes the reset.
    But its the "default" when I use sleep or deepsleep, and on the T3.6 this does work predicatable.
    Unfortunately for us the author probably has more important things to attend to, and still I appreciate the work he has done allready !

    Cor

  4. #4
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    507
    I inspected the hal.c file inside the Teensy40 directory in the snooze library and this line is used on the top of
    Code:
    int hal_sleep(void)
    SCB_SCR = SCB_SCR_SLEEPDEEP;
    That measn the System Control Register is set to deepsleep instead of sleep and I wonder if that has anything to do with the problems I am experiencing.
    The code in this library isnt very easy to understand as it contains many registers and combinations of "| & and ~" to set bits in several registers. Some of them
    are filled with values that I have trouble tracing back to the origins.
    For instance just before the system issues the WAITFORINTERRUPT (wfi) I see:
    Code:
    IOMUXC_GPR_GPR8 = 0xaaaaaaaa;
        IOMUXC_GPR_GPR12 = 0x0000002a
    The AN12085 document states
    Code:
    Before entering low power mode:
    IOMUXC_GPR->GPR8 = 0xaaaaaaaa;
    IOMUXC_GPR->GPR12 = 0x0000000a;
    After wake-up:
    IOMUXC_GPR->GPR8 = 0x00000000;
    IOMUXC_GPR->GPR12 = 0x00000000;
    Again unclear why ...

  5. #5
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    416
    You might be interested in some work I did to investigate the Teensy recovery time from various sleep states for various Teensy.
    The results are here.

  6. #6
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    507
    Nice work from you as that is important for users. But in my case I allready have a 100ms wait after the system should recover from sleep. Thats more than enough as your timings are closer to a few ms. We are running the batdetectors from USB-powerpacks and they need a bit of load. So the timer is not programmed for long sleeps and after it comes back from sleep we wait a bit to keep the powerpack active. And this all works fine on a T3.6 but on a T4.1 things are very different and I have trouble understanding the code even with the application notes for this processor at hand.
    But it seems this feature is a bit of a niche as not too many people seem to be letting their devices sleep. In the end we might have to fall back to additional hardware to achieve this.

  7. #7
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    416
    Yes, I was going to use T4.0 for my satellite stations, but have had to fall back to T3.2 or even LC.

  8. #8
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    507
    I am willing to spend time improving this library but its difficult without a clear guidance that I can follow. The application notes of NXP are quite abstract and do not explain in detail what should be set exactly. Most stuff is then becoming a hit and miss operation without a single debug-bit possible ... it goes to sleep (it always does) but does not seem to return in an expected fashion ... but how to trace what was wrong ?

  9. #9
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    507
    Done a bit more work on the possible issues. I now have the T4.1 running on sleep but with partial functionality. All functionality that uses storage in PSRAM had to be switched off, the TFT has to be switched off after sleep.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •