arduino / ArduinoCore-samd

Arduino Core for SAMD21 CPU

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

USBCore SET_CONFIGURATION handler is not interrupt-safe

AlanStern opened this issue · comments

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.)