cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to disable USB endpoints on STM32F4

Antoine Sebert
Associate

I read some related topics on this community but none of them could fixes the issue.

I'm currently trying to disable a USB OUT endpoint (following the steps from the Reference Manual) but the Global NAK Effective interrupt bit (GONAKEFF in USB_OTG_FS_GINTSTS) is never set, after I set the USB_OTG_DCTL_SGONAK bit in USB_OTG_FS_DEVICE_DCTL while the interrupt is masked (as it is supposed to be, according to the doc). Is there some thing I'm missing to disable properly the endpoint ?

Thank you in advance

1 REPLY 1
LM.3
Associate

I had same problem with STM32F7 (HAL version 1.16.0).

Found interesting comment in NuttX source code (stm32_otgdev.c)

/* Wait for the GONAKEFF interrupt that indicates that the OUT NAK
   * mode is in effect.  When the interrupt handler pops the OUTNAK word
   * from the RxFIFO, the core sets the GONAKEFF interrupt.
   */
 
/* Since we are in the interrupt handler, we cannot wait inline for the
   * GONAKEFF because it cannot occur until service the RXFLVL global interrupt
   * and pop the OUTNAK word from the RxFIFO.

I tried to manually flush RxFifo (while in ISR) with this code and eventually got BOUTNAKEFF set (GONAKEFF is defined as BOUTNAKEFF in HAL libraries)

if ((USB_OTG_HS->GINTSTS & USB_OTG_GINTSTS_BOUTNAKEFF) == 0)
{
	((USB_OTG_DeviceTypeDef *)(USB_OTG_HS_PERIPH_BASE + USB_OTG_DEVICE_BASE))->DCTL = USB_OTG_DCTL_SGONAK;
	while ((USB_OTG_HS->GINTSTS & USB_OTG_GINTSTS_BOUTNAKEFF) == 0)
	{
		if (USB_OTG_HS->GINTSTS & USB_OTG_GINTSTS_RXFLVL)
		{
			uint32_t temp = USBx->GRXSTSP;
			
			while (USB_OTG_HS->GINTSTS & USB_OTG_GINTSTS_RXFLVL)
				temp = USBx->GRXSTSP;
		}
	}
	/* ... */
	((USB_OTG_DeviceTypeDef *)(USB_OTG_HS_PERIPH_BASE + USB_OTG_DEVICE_BASE))->DCTL = USB_OTG_DCTL_CGONAK;
}