cancel
Showing results for 
Search instead for 
Did you mean: 

Determine USB-cable connected/disconnected status and transmit-in-progress status without being dependent on interrupts?

arnold_w
Senior

I'm working with the Nucleo-64 development board with an STM32L476 microcontroller and I'm using the USB source code that STM32CubeMX has generated for me. In my project the peripheral interrupts have the same priority as OTG_FS_IRQHandler and hence, they can't interrupt each other. I wish to transmit a USB-packet from within a peripheral interrupt, but before doing so I need to make sure a cable is (still) connected and no transmit is currently ongoing (remember, CDC_Transmit_FS is asynchronous). I understand that HAL_PCD_ResumeCallback and HAL_PCD_SuspendCallback will be called when the cable is connected/disconnected and that USBD_CDC_HandleTypeDef -> TxState tells me when transmit is ongoing. However, these will not be updated properly in time in case OTG_FS_IRQHandler has the same priority as the interrupt I wish to send the USB-packet from. Is there a solution to this that does not require me to raise the priority level of OTG_FS_IRQHandler?

1 REPLY 1
TDK
Guru

Not really. The USB state machine relies on TxState to give the current status of the peripheral, and it's updated during the USB interrupt, as you note.

You could write your own USB stack, but it seems like bumping up the USB IRQ priority is the better solution. If you wrote your own, you would need to do what the USB IRQ is doing anyway, so not much time would be saved.

If you feel a post has answered your question, please click "Accept as Solution".