arduino / arduino/ArduinoCore-samd
USBCore SET_CONFIGURATION handler is not interrupt-safe
- Dominant language
- C
- Stars
- 502
- Forks
- 740
- PR merge metrics
- No merged PRs in 30d
Description
In USBCore.cpp, the handleStandardSetup() interrupt subroutine's SET_CONFIGURATION case calls initEndpoints(), which calls initEP(). For Bulk-OUT endpoints, initEP() calls operator new and possibly operator delete. In the absence of any other information, I assume the implementations of those operators internally rely on malloc() and free(), which are not interrupt-safe.
A proper fix requires a fair amount of reorganization. The DoubleBufferedEPOutHandler class object should be created early, during the initialization of the USB device. When a SET_CONFIGURATION request is received, the object should not be deleted and recreated, but properly reset. (This is related to issue #350, although the problem was present before that.)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in USBCore.cpp at the handleStandardSetup() interrupt subroutine and trace the SET_CONFIGURATION path through initEndpoints() and initEP(). Inspect how DoubleBufferedEPOutHandler is created and destroyed during USB device initialization and configuration changes. Done means SET_CONFIGURATION no longer performs interrupt-unsafe allocation or deletion and instead resets the existing handler.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100