Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: standbyMode() should adopt the sleep() code in the ArduinoLowPower library #68

Open
sergerold opened this issue Jan 9, 2021 · 1 comment
Labels
type: enhancement Proposed improvement

Comments

@sergerold
Copy link

sergerold commented Jan 9, 2021

Hi

These functions are designed to do the same thing but the sleep() function has a number of advantages (e.g. disabling systick) which can cause issues

// RTCZero.cpp
void RTCZero::standbyMode()
{
  // Entering standby mode when connected
  // via the native USB port causes issues.
  SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
  __DSB();
  __WFI();
}
// ArduinoLowPower.cpp
void ArduinoLowPowerClass::sleep() {
	bool restoreUSBDevice = false;
	if (SERIAL_PORT_USBVIRTUAL) {
		USBDevice.standby();
	} else {
		USBDevice.detach();
		restoreUSBDevice = true;
	}
	// Disable systick interrupt:  See https://www.avrfreaks.net/forum/samd21-samd21e16b-sporadically-locks-and-does-not-wake-standby-sleep-mode
	SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;	
	SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
	__DSB();
	__WFI();
	// Enable systick interrupt
	SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;	
	if (restoreUSBDevice) {
		USBDevice.attach();
	}
}

Thanks

@per1234 per1234 added the type: enhancement Proposed improvement label Jan 9, 2021
@adamgarbo
Copy link

I agree that the systick interrupt change should be added, but would note that code in the ArduinoLowPower library prevents the serial port from being reestablished after deep sleep. Currently, this does not occur when manually calling USBDevice.detach() and USBDevice.attach() and using the RTCZero standbyMode() functionality.

I also wonder if the ArduinoLowPower library is attaching and detaching the USBDevice even when no USB connection is present. If so, it could be a good idea to have an auto-detect, or a user-configurable option to not have this action taken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

3 participants