Skip to content

Commit b9ac48c

Browse files
committed
Implement low power functionality on USB subsystem
This enables remote wakeup on CDC driver, so we can safely call standby() and maintain the Serial prints on resume.
1 parent 95c9ec6 commit b9ac48c

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

cores/arduino/USB/SAMD21_USBDevice.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class USBDevice_SAMD21G18x {
4848

4949
inline void runInStandby() { usb.CTRLA.bit.RUNSTDBY = 1; }
5050
inline void noRunInStandby() { usb.CTRLA.bit.RUNSTDBY = 0; }
51+
inline void wakeupHost() { usb.CTRLB.bit.UPRSM = 1; }
5152

5253
// USB speed
5354
inline void setFullSpeed() { usb.CTRLB.bit.SPDCONF = USB_DEVICE_CTRLB_SPDCONF_FS_Val; }

cores/arduino/USB/USBAPI.h

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class USBDeviceClass {
6565
bool configured();
6666
bool connected();
6767

68+
void standby();
69+
6870
// Setup API
6971
bool handleClassInterfaceSetup(USBSetup &setup);
7072
bool handleStandardSetup(USBSetup &setup);

cores/arduino/USB/USBCore.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ bool USBDeviceClass::sendDescriptor(USBSetup &setup)
250250
return true;
251251
}
252252

253+
void USBDeviceClass::standby() {
254+
usbd.noRunInStandby();
255+
}
256+
257+
253258
void USBDeviceClass::handleEndpoint(uint8_t ep)
254259
{
255260
#if defined(CDC_ENABLED)

cores/arduino/USB/USBCore.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ _Pragma("pack()")
258258
* idVendor, idProduct, bcdDevice, iManufacturer, iProduct, iSerialNumber, bNumConfigurations */
259259

260260
#define D_CONFIG(_totalLength,_interfaces) \
261-
{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(500) }
261+
{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(500) }
262262
/* Table 9-10. Standard Configuration Descriptor
263263
* bLength, bDescriptorType, wTotalLength, bNumInterfaces, bConfigurationValue, iConfiguration
264264
* bmAttributes, bMaxPower */

0 commit comments

Comments
 (0)