BriscoeTech / Arduino-FreeRTOS-SAMD51

A port of FreeRTOS that runs on Arduino Samd51 boards
19 stars 13 forks source link

Receiving USART in SLEEPMODE = STANDBY #5

Closed FordJ closed 2 years ago

FordJ commented 3 years ago

I’m working on a project using a SAMD51 and GSM modem, and struggling to get Serial comms when in standby.

Because of reliance on some Arduino libraries for UI and screen, I'm using an identical approach to this library, and compiling with the Adafruit ArduinoCore-samd.

Having minimal power consumption is key, so need to have the SAMD51 in STANDBY mode as much as possible, using PM->SLEEPCFG.bit.SLEEPMODE = PM_SLEEPCFG_SLEEPMODE_STANDBY_Val.

If using PM_SLEEPCFG_SLEEPMODE_IDLE2_Val instead, data is received exactly as expected, but unfortunately power consumption is too high.

When in STANDBY power mode, the device isn’t receiving anything into Serial buffer.

When idle, the time until next task is used to start a timer with appropriate match value to wake up. This part of it is working fine, and just changing the SLEEPMODE from STANDBY to IDLE2 gets the USART working as expected.

This is normally using GCLK3 (32.768KHz) and works fine, but when testing with GCLK1 (48MHz), which I believe is what the USART is clocked by, this does NOT function in STANDBY, but does in IDLE2.

It obviously points to the 48MHz clock (GCLK1) going off in STANDBY, but setting GCLK->GENCTRL[1].bit.RUNSTDBY = 1 has no effect. I’ve also tried OSCCTRL->DFLLCTRLA.bit.RUNSTDBY = 1, which also makes no difference.

All help or suggestions of next steps are very much appreciated

BriscoeTech commented 3 years ago

I have only dabbled with the sleep modes in the samd51, and have come to the conclusion its not straightforward or simple as the datasheet advertises. I ran into some similar things, but I was having issues trying to get peripherals to turn off in the standby mode with sleepwalking.

I think the key is in how the "sleepwalking" feature works in this chip. It tries to intelligently turn of peripherals only if they are not clocked or setup, and I have a feeling that since the Arduino core sets everything up by default (very convenient) is why the standby mode power consumption is barley lower than idle from my experience.

Also there are 11 power modes, 4 of them are "Standby" modes. I think the best way to solve this problem is to live, eat, and breath the Power Management section of the datasheet. This chip has a handful of registers to set to specify each mode, and I have a sneaky hunch you may also have to completely learn the clocking section as well to understand how sleepwalking actually works. I got stuck trying to find the right supplemental datasheet or section that really explains how the sleepwalking worked, and could not figure out how to enable/disable it for each peripheral at will.

https://ww1.microchip.com/downloads/en/DeviceDoc/SAM_D5x_E5x_Family_Data_Sheet_DS60001507G.pdf PM - Power Manager pg 199

I am interested to know if you figure out how to bend the sleepwalking feature to your will. It would be nice to know what register/s the sleepwalking looks at for each peripheral to know if it can power off a peripheral or not. If you figure that out, you can then disable all the unused peripherals and hopefully get the power down.

Also for anyone else who reads this ticket, this has nothing to do with this FreeRtos library. I should figure out how to enable the github discussion sections one of these days and move this there.

Good luck!