STM32F407 USB related questions
Hi! I have several questions regarding standard USB host implementation.
1) Host mode: File "stm32f4xx_ll_usb.c", function "USB_HC_StartXfer" there is a piece of code
if (dma == 0U) /* Slave mode */
{
if ((hc->ep_is_in == 0U) && (hc->xfer_len > 0U))
{
switch (hc->ep_type)
{
/* Non periodic transfer */
case EP_TYPE_CTRL:
case EP_TYPE_BULK:
len_words = (uint16_t)((hc->xfer_len + 3U) / 4U);
/* check if there is enough space in FIFO space */
if (len_words > (USBx->HNPTXSTS & 0xFFFFU))
{
/* need to process data in nptxfempty interrupt */
USBx->GINTMSK |= USB_OTG_GINTMSK_NPTXFEM;
}
break;
/* Periodic transfer */
case EP_TYPE_INTR:
case EP_TYPE_ISOC:
len_words = (uint16_t)((hc->xfer_len + 3U) / 4U);
/* check if there is enough space in FIFO space */
if (len_words > (USBx_HOST->HPTXSTS & 0xFFFFU)) /* split the transfer */
{
/* need to process data in ptxfempty interrupt */
USBx->GINTMSK |= USB_OTG_GINTMSK_PTXFEM;
}
break;
default:
break;
}
/* Write packet into the Tx FIFO. */
(void)USB_WritePacket(USBx, hc->xfer_buff, hc->ch_num, (uint16_t)hc->xfer_len, 0);
}
}It is supposed to check if there is a space available in TXFIFO, but it writes the data regardless of free space. Moreover, it unmasks the interrupt for NPTXFIFO/PTXFIFO to deal with it later. But the interrupt handler "HAL_HCD_IRQHandler" doesn't give a care about those interrupts, NPTXE isn't even cleared:
if (__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE))
{
/* Incorrect mode, acknowledge the interrupt */
__HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE);
}Am I missing something here?
2) General: What the point of masking + unmasking an interrupt inside an interrupt handler?
USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
HCD_RXQLVL_IRQHandler(hhcd);
USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);3) Device mode: Endpoint address is masked with 0x7F instead of 0xF inside generated file usbd_conf.c
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
{
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData;
if((ep_addr & 0x80) == 0x80)
{
return hpcd->IN_ep[ep_addr & 0x7F].is_stall; // 7f error!
}
else
{
return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; // 7f error!
}4) Device: In StdRequest handler device's address is set before the status is sent to host:
pdev->dev_address = dev_addr;
(void)USBD_LL_SetUSBAddress(pdev, dev_addr);
(void)USBD_CtlSendStatus(pdev);Is it okay?
5) There are a lot of copy pasted comments which doesn't make any sense. There are even wrong ones, suggesting to use "15" (0xF) value to flush all EPs/channels, although the correct one is "16" (0x10).
6) There are some minor bugs found everywhere in code, although i didn't noted all of them.
7) Am i using an outdated software package? My version is STM32Cube_FW_F4_V1.25.0
