arduino / arduino/ArduinoCore-avr
USB suspend not implemented
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
I'm using an ATmega32u4, but the issue seems to affect all devices.
According to the manual for that chip, the software is supposed to freeze the USB clock and optionally switch to the internal clock whenever it receives an USB suspend interrupt (SUSPI), and revert whenever it receives the USB wakeup interrupt (WAKEUPI). (Section 6.10 of the manual).
The USB core hints at that. It has the functions USB_ClockDisable() and USB_ClockEnable(), which are referenced in a TODO comment in the ISR (see https://github.com/arduino/ArduinoCore-avr/blob/63092126a406402022f943ac048fa195ed7e944b/cores/arduino/USBCore.cpp#L791 and https://github.com/arduino/ArduinoCore-avr/blob/63092126a406402022f943ac048fa195ed7e944b/cores/arduino/USBCore.cpp#L800), but both aren't actually activated.
Since the USBCore doesn't properly implement suspending, the host device needs to always keep its USB driver active and wakelocking, no matter if the USB connection is actually used. This causes significant battery drain in battery-powered devices.
It would be highly appreciated if this function is implemented.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in cores/arduino/USBCore.cpp at the USB interrupt handler lines linked in the issue, and inspect the existing USB_ClockDisable() and USB_ClockEnable() functions. Consult Section 6.10 of the ATmega32u4 manual for SUSPI and WAKEUPI behavior. Done means USB suspend disables or switches the clock as appropriate and wakeup restores it across affected devices.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100