diff --git a/os/hal/ports/STM32/LLD/USBv1/hal_usb_lld.c b/os/hal/ports/STM32/LLD/USBv1/hal_usb_lld.c index 7966c7fe3..046235b1d 100644 --- a/os/hal/ports/STM32/LLD/USBv1/hal_usb_lld.c +++ b/os/hal/ports/STM32/LLD/USBv1/hal_usb_lld.c @@ -639,11 +639,13 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) { uint16_t nblocks; /* Endpoint size and address initialization.*/ - if (epcp->out_maxsize > 62) - nblocks = (((((epcp->out_maxsize - 1U) | 0x1FU) + 1U) / 32U) << 10) | - 0x8000; - else - nblocks = ((((epcp->out_maxsize - 1U) | 1U) + 1U) / 2U) << 10; + if (epcp->out_maxsize > 62) { + nblocks = (((((uint32_t)epcp->out_maxsize - 1U) | 0x1FU) / 32U) << 10) | + 0x8000U; + } + else { + nblocks = ((((uint32_t)(epcp->out_maxsize - 1U) | 1U) + 1U) / 2U) << 10; + } dp->RXCOUNT0 = nblocks; dp->RXADDR0 = usb_pm_alloc(usbp, epcp->out_maxsize); diff --git a/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.c b/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.c index 80881d216..7c6e2793e 100644 --- a/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.c +++ b/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.c @@ -753,7 +753,7 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) { /* Endpoint size and address initialization.*/ if (epcp->out_maxsize > 62U) { - nblocks = ((((((uint32_t)epcp->out_maxsize - 1U) | 0x1FU) + 1U) / 32U) << 26) | + nblocks = (((((uint32_t)epcp->out_maxsize - 1U) | 0x1FU) / 32U) << 26) | 0x80000000U; } else {