-
Notifications
You must be signed in to change notification settings - Fork 39
Composite with Audio may cause Hard Fault #36
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't workinginternal bug trackerIssue confirmed and reported into a ticket in the internal bug tracking systemIssue confirmed and reported into a ticket in the internal bug tracking systemmwMiddleware-related issue or pull-request.Middleware-related issue or pull-request.st usbSTMicroelectronics' Universal Serial Bus (Host or Device) librarySTMicroelectronics' Universal Serial Bus (Host or Device) libraryusbUSB-related (host or device) issue or pull-requestUSB-related (host or device) issue or pull-request
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinginternal bug trackerIssue confirmed and reported into a ticket in the internal bug tracking systemIssue confirmed and reported into a ticket in the internal bug tracking systemmwMiddleware-related issue or pull-request.Middleware-related issue or pull-request.st usbSTMicroelectronics' Universal Serial Bus (Host or Device) librarySTMicroelectronics' Universal Serial Bus (Host or Device) libraryusbUSB-related (host or device) issue or pull-requestUSB-related (host or device) issue or pull-request
Type
Fields
Give feedbackNo fields configured for Bug.
Projects
Status
Analyzed
Describe the bug
In composite mode, the AUDIO class uses
pdev->classIdinsideUSBD_AUDIO_Sync(). This is unsafe whenUSBD_AUDIO_Sync()is called from an async context (e.g. I2S DMA callback), becausepdev->classIdmay currently point to another class (HID), leading to wrongpClassDataCmsit[]/pUserData[]indexing and a HardFault.How To Reproduce
Indicate the global behavior of your application project.
USBD_AUDIO_Sync()to adjust/read audio buffer state and triggerAudioCmd().The modules that you suspect to be the cause of the problem (Driver, BSP, MW ...).
Class/AUDIO(specificallyUSBD_AUDIO_Sync()).classIdis used as a global context selector.The use case that generates the problem.
HardFault_Handler.How we can reproduce the problem.
Composite Audio + HID application example:
https://github.com/STMicroelectronics/STM32CubeH7/tree/dev/usb/composite/Projects/STM32H743I-EVAL/Applications/USB_Device/Composite_Audio_HID
Additional context
Root cause:
USBD_AUDIO_Sync()assumes it is always called withpdev->classIdalready set to the AUDIO instance. That assumption is not true whenUSBD_AUDIO_Sync()is invoked from non-USB asynchronous contexts (DMA callbacks).Proposed fix idea: make
USBD_AUDIO_Sync()(and any similar helper callable outside USB context) not depend onpdev->classId, similar toUSBD_HID_SendReport.If the intended usage is “
USBD_AUDIO_Sync()must only be called from the AUDIO class callbacks (where classId is set by the core)”, it would help a lot to document that requirement clearly, because it’s very easy to call it from the audio DMA layer, and the failure mode is a hard crash.