ArduinoLowPower icon indicating copy to clipboard operation
ArduinoLowPower copied to clipboard

Not working on SAMD

Open disk91 opened this issue 6 years ago • 9 comments

The following code never wakeup after the first sleep call (led always on) #include <ArduinoLowPower.h> void setup() { // put your setup code here, to run once: pinMode(6,OUTPUT); }

void loop() { // put your main code here, to run repeatedly: digitalWrite(6,HIGH); LowPower.sleep(500); digitalWrite(6,LOW); LowPower.sleep(500); }

disk91 avatar Jun 10 '18 18:06 disk91

tested on Arduino MKRFOX1200

disk91 avatar Jun 10 '18 18:06 disk91

To be more precise : it works correctly if I remove power supply and restore power it. But it stops working when the device has been programmed from USB.

disk91 avatar Jun 10 '18 18:06 disk91

Hi @disk91 , this may depend on your operating system/USB connection; the code path in case of USB connection is quite different from the normal one. Could you try reverting https://github.com/arduino-libraries/ArduinoLowPower/commit/8cf4c737ddb755e76c20407df3d70cc507bd9651 and see if the behaviour is the expected one (in your setup)?

facchinm avatar Jun 11 '18 07:06 facchinm

We are seeing a similar problem. We also see that sometimes the first sleep call almost immediately returns. Current Setup: Feather M0, using Mac to program/power, reverted the commit above as asked-- When powered from a battery (no data signal), the first call immediately returns, subsequent calls work correctly. Same for power by mac after unplugging. However, after you reprogram, the first call will never return. The reset button continues the previous behavior (ie., it does not change it to the unplugged/replug behavior).

sjernigan avatar Jun 13 '18 21:06 sjernigan

I have the same problem

warriorfenixSM avatar Jun 26 '18 14:06 warriorfenixSM

I think I have this problem as well. I think it may have something to do with the rtc. Recently I added an rtc.begin() in my setup() and this has stopped the OP’s issue from happening.

sslupsky avatar Sep 13 '18 14:09 sslupsky

I found another reference to this issue:

https://forum.arduino.cc/index.php?topic=499101.0

Gormd reported that using LowPower.attachInterruptWakeup() also cleared this up. Seem's to me there is a bug here related to declaration or construction of the RTC object?

sslupsky avatar Sep 14 '18 21:09 sslupsky

You could call
SerialUSB.end(); just before calling LowPower.sleep(); to stop the USB interrupts from happening and continuously waking the system

DanielRIOT avatar Apr 07 '20 09:04 DanielRIOT

Hi @disk91 , this may depend on your operating system/USB connection; the code path in case of USB connection is quite different from the normal one. Could you try reverting 8cf4c73 and see if the behaviour is the expected one (in your setup)?

@facchinm Is there any reason to use USBDevice.standby(); call ? I think it doesn't work in the propper way and in order to avoid issues, I would leave sleep() function simply as this:

void ArduinoLowPowerClass::sleep() {
	USBDevice.detach();
	SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
	__DSB();
	__WFI();
       USBDevice.attach();
}

If standby is used, wouldn't it be necessary to have a function to "resume" and call runInStandby() as well standby function calls noRunInStandby()?

nekuneko avatar Jul 26 '20 21:07 nekuneko