Skip to content

Commit

Permalink
stm32g0xx: usb: fix stall on high load USB endpoints
Browse files Browse the repository at this point in the history
Having two writes to clean and set COUNTn_RX and NUM_BLOCK results in
a small windows in which COUNTn_RX and NUM_BLOCK are zero.

This results in a stall as the buffer is empty (ready to receive) but
also has no space to receive the package into.

Signed-off-by: Jonas Martin <j.martin@pengutronix.de>
  • Loading branch information
lichtfeind authored and marckleinebudde committed Feb 13, 2023
1 parent b6d1028 commit dffacde
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions libs/STM32_HAL/include/stm32g0xx/stm32g0xx_ll_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ typedef struct
(wNBlocks)--; \
} \
\
(pdwReg)|= (uint32_t)((((wNBlocks) << 26U)) | USB_CNTRX_BLSIZE); \
(pdwReg) = ((pdwReg) & ~USB_CNTRX_NBLK_MSK) | (uint32_t)((((wNBlocks) << 26U)) | USB_CNTRX_BLSIZE); \
} while(0) /* USB_DRD_CALC_BLK32 */

#define USB_DRD_CALC_BLK2(pdwReg, wCount, wNBlocks) \
Expand All @@ -653,15 +653,13 @@ typedef struct
{ \
(wNBlocks)++; \
} \
(pdwReg) |= (uint32_t)((wNBlocks) << 26U); \
(pdwReg) = ((pdwReg) & ~(USB_CNTRX_BLSIZE | USB_CNTRX_NBLK_MSK)) | (uint32_t)((wNBlocks) << 26U); \
} while(0) /* USB_DRD_CALC_BLK2 */

#define USB_DRD_SET_CHEP_CNT_RX_REG(pdwReg, wCount) \
do { \
uint32_t wNBlocks; \
\
(pdwReg) &= ~(USB_CNTRX_BLSIZE | USB_CNTRX_NBLK_MSK); \
\
if ((wCount) > 62U) \
{ \
USB_DRD_CALC_BLK32((pdwReg), (wCount), wNBlocks); \
Expand All @@ -670,7 +668,7 @@ typedef struct
{ \
if ((wCount) == 0U) \
{ \
(pdwReg) |= USB_CNTRX_BLSIZE; \
(pdwReg) = ((pdwReg) & ~USB_CNTRX_NBLK_MSK) | USB_CNTRX_BLSIZE; \
} \
else \
{ \
Expand Down

0 comments on commit dffacde

Please sign in to comment.