AnsweredAssumed Answered

STM32F3 processes an invalid USB Setup Packet in PCD_EP_ISR_Handler with ep->xfer_count very large

Question asked by RokitanskyAschoff on Jun 23, 2016
Latest reply on Oct 5, 2016 by RokitanskyAschoff
Hi all,

I have a STM32F302CBT6, and have created a USB Audio Device (speaker) project for it using STM32CubeF3 version 1.5.

Basically, the project initially works. If I for example, set the STM32 as the default audio device and then click the Windows volume control it plays that sound to the STM32, and data are received in the USBD_AUDIO_DataOut etc.

However, this only works the first time. The program ends up in the Hard Fault handler. The call stack shows:

#0 ??     HardFault_Handler () (C:\SoftwareProject\Arm\STM32F3\STM32F302_USB_Speaker\src\stm32f3xx_it.c:75)
#2 0x801335c     USBD_ParseSetupRequest(req=0x208, pdata=0x20004f20 <hpcd_USB_FS+884> "C") (C:\SoftwareProject\Arm\STM32F3\STM32F302_USB_Speaker\usb\usbd_ctlreq.c:701)
#3 0x8012804     USBD_LL_SetupStage(pdev=0x0, psetup=0x20004f20 <hpcd_USB_FS+884> "C") (C:\SoftwareProject\Arm\STM32F3\STM32F302_USB_Speaker\usb\usbd_core.c:266)
#4 0x8011a3c     HAL_PCD_SetupStageCallback(hpcd=0x20004bac <hpcd_USB_FS>) (C:\SoftwareProject\Arm\STM32F3\STM32F302_USB_Speaker\src\usbd_conf.c:130)
#5 0x800a5ea     PCD_EP_ISR_Handler(hpcd=0x20004bac <hpcd_USB_FS>) (C:\SoftwareProject\Arm\STM32F3\STM32F302_USB_Speaker\hal\stm32f3xx_hal_pcd.c:401)
#6 0x800ab26     HAL_PCD_IRQHandler(hpcd=0x20004bac <hpcd_USB_FS>) (C:\SoftwareProject\Arm\STM32F3\STM32F302_USB_Speaker\hal\stm32f3xx_hal_pcd.c:566)
#7 0x801182a     USB_LP_IRQHandler() (C:\SoftwareProject\Arm\STM32F3\STM32F302_USB_Speaker\src\stm32f3xx_it.c:254)
#9 ??     main () (C:\SoftwareProject\Arm\STM32F3\STM32F302_USB_Speaker\src\main.c:109)

At #3 you can see there is a problem: pdev should not be 0x0. Somehow it changed. Note that it must have had a valid value for all of the previous setup requests to work, and for the first audio data out to work.

Any Ideas? This problem occurs with the minimal code straigh out of STM32Cube, which I will try to attach. EDIT: Project code is attached. Its a minimal project that exhibits this problem, straight out of STM32Cube. I think the only things I changed in STM32Cube was the audio sampling frequency from 22100 to 48000 Hz.

Just as a caveat: If I set a breakpoint at USBD_ParseSetupRequest (anywhere in that function) pdev is not modified and the program continues to run correctly