From d93ab59b74f79948b805dc6070f554366eae3331 Mon Sep 17 00:00:00 2001 From: codetector Date: Tue, 29 Dec 2020 04:12:23 -0500 Subject: [PATCH 1/2] [HAL:LPC11Uxx]: add error for unsupported ST configuration --- os/hal/ports/LPC/LLD/STM/hal_st_lld.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/os/hal/ports/LPC/LLD/STM/hal_st_lld.h b/os/hal/ports/LPC/LLD/STM/hal_st_lld.h index a12571ce..cf014ae6 100644 --- a/os/hal/ports/LPC/LLD/STM/hal_st_lld.h +++ b/os/hal/ports/LPC/LLD/STM/hal_st_lld.h @@ -53,6 +53,10 @@ /* Derived constants and error checks. */ /*===========================================================================*/ +#if OSAL_ST_MODE_PERIODIC == OSAL_ST_MODE_FREERUNNING + #error "OSAL_ST_MODE_FREERUNNING is not supported. Check CH_CFG_ST_TIMEDELTA" +#endif + /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ From 8702f416e013ee00ffe4b359fc9be350bf7d9ba9 Mon Sep 17 00:00:00 2001 From: codetector Date: Tue, 29 Dec 2020 14:28:08 -0500 Subject: [PATCH 2/2] [HAL/LPC]: USB: Fix short packet for normal EPs. --- os/hal/ports/LPC/LLD/USB/hal_usb_lld.c | 27 +++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/os/hal/ports/LPC/LLD/USB/hal_usb_lld.c b/os/hal/ports/LPC/LLD/USB/hal_usb_lld.c index e78bc1df..aeb38a47 100644 --- a/os/hal/ports/LPC/LLD/USB/hal_usb_lld.c +++ b/os/hal/ports/LPC/LLD/USB/hal_usb_lld.c @@ -145,8 +145,7 @@ static size_t usb_packet_receive(USBDriver *usbp, usbep_t ep) { const USBEndpointConfig *epcp = usbp->epc[ep]; USBOutEndpointState *osp = usbp->epc[ep]->out_state; uint32_t n = (USB_EPLIST->entry[4 * ep] & EPLIST_ENTRY_NBYTES_MASK) >> EPLIST_ENTRY_NBYTES_POS; - const size_t xfer_size = (osp->rxsize > epcp->out_maxsize) ? epcp->out_maxsize : osp->rxsize; - n = xfer_size - n; + n = epcp->out_maxsize - n; if (osp->rxbuf != NULL && n > 0) { memcpy(osp->rxbuf, usbp->epn_buffer[ep * 2], n); osp->rxbuf += n; @@ -157,14 +156,15 @@ static size_t usb_packet_receive(USBDriver *usbp, usbep_t ep) { osp->rxcnt += n; osp->rxsize -= n; - size_t next_xfer = (osp->rxsize > epcp->out_maxsize) ? epcp->out_maxsize : osp->rxsize; USB_EPLIST->entry[4 * ep] &= ~(0x3FFFFFF | EPLIST_ENTRY_STALL | EPLIST_ENTRY_ACTIVE); - if (next_xfer > 0) { + if (osp->rxsize > 0) { // ReSetup for recieve - USB_EPLIST->entry[4 * ep] |= EPLIST_ENTRY_NBYTES(next_xfer) | + USB_EPLIST->entry[4 * ep] |= EPLIST_ENTRY_NBYTES(epcp->out_maxsize) | EPLIST_ADDR(usbp->epn_buffer[ep * 2]) | EPLIST_ENTRY_ACTIVE; } else { - USB_EPLIST->entry[4 * ep] |= EPLIST_ENTRY_STALL; + if (ep != 0) { + USB_EPLIST->entry[4 * ep] |= EPLIST_ENTRY_STALL; + } } return n; @@ -218,13 +218,16 @@ OSAL_IRQ_HANDLER(LPC_USB_IRQ_VECTOR) { } else { // OUT endpoint, receive USBOutEndpointState *osp = usbp->epc[ep]->out_state; + size_t actual_rx = 0; if (osp->rxsize > 0) { osalSysLockFromISR(); - usb_packet_receive(usbp, ep); + actual_rx = usb_packet_receive(usbp, ep); osalSysUnlockFromISR(); } if (osp->rxsize == 0) { // TODO: Check if this is correct _usb_isr_invoke_out_cb(usbp, ep); + } else if (actual_rx < usbp->epc[ep]->out_maxsize && ep != 0) { + _usb_isr_invoke_out_cb(usbp, ep); } } } @@ -569,24 +572,16 @@ void usb_lld_start_out(USBDriver *usbp, usbep_t ep) { USBOutEndpointState *osp = usbp->epc[ep]->out_state; const USBEndpointConfig *epcp = usbp->epc[ep]; - size_t rx_size = 0; - if (osp->rxsize == 0) { /* Special case for zero sized packets.*/ osp->rxpkts = 1; - rx_size = 0; } else { osp->rxpkts = (uint16_t)((osp->rxsize + epcp->out_maxsize - 1) / epcp->out_maxsize); - if (osp->rxsize > epcp->out_maxsize) { - rx_size = epcp->out_maxsize; - } else { - rx_size = osp->rxsize; - } } USB_EPLIST->entry[ep * 4] &= ~(0x3FFFFFF | EPLIST_ENTRY_STALL | EPLIST_ENTRY_ACTIVE); USB_EPLIST->entry[ep * 4] |= EPLIST_ENTRY_ACTIVE | - EPLIST_ENTRY_NBYTES(rx_size) | + EPLIST_ENTRY_NBYTES(epcp->out_maxsize) | EPLIST_ADDR(usbp->epn_buffer[ep * 2]); if (ep == 0)