Skip to content

Commit

Permalink
TARGET_STM: fix unterminated multi-packet USB transaction
Browse files Browse the repository at this point in the history
Fix issue #15384 by sending a zero-length packet if the packet sent had
the same size as the endpoint buffer size. This is needed to comply with
the USB protocol which assumes an ongoing multi-packet USB transaction
otherwise.

STM32 HAL PCD handle parameters are used to avoid data duplication in RAM.

Signed-off-by: Daniel Starke <daniel-email@gmx.net>
  • Loading branch information
daniel-starke committed Nov 18, 2023
1 parent 72f27ce commit c10068f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions targets/TARGET_STM/USBPhy_STM32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,19 @@ void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
{
USBPhyHw *priv = ((USBPhyHw *)(hpcd->pData));
uint8_t endpoint = LOG_IN_TO_EP(epnum);
priv->epComplete[EP_TO_IDX(endpoint)] = 1;
uint8_t &epComplete = priv->epComplete[EP_TO_IDX(endpoint)];

if (epnum) {
priv->events->in(endpoint);
if (epComplete == 2 && hpcd->IN_ep[epnum].xfer_count == hpcd->IN_ep[epnum].maxpacket) {
/* transmit zero-length packet to avoid ongoing multi-packet transaction */
epComplete = 3;
HAL_PCD_EP_Transmit(hpcd, epnum, NULL, 0);
} else {
epComplete = 1;
priv->events->in(endpoint);
}
} else {
epComplete = 1;
priv->events->ep0_in();
}
}
Expand Down

0 comments on commit c10068f

Please sign in to comment.