diff --git a/os/hal/platforms/STM32/OTGv1/stm32_otg.h b/os/hal/platforms/STM32/OTGv1/stm32_otg.h index 083f868a5..4c83a62eb 100644 --- a/os/hal/platforms/STM32/OTGv1/stm32_otg.h +++ b/os/hal/platforms/STM32/OTGv1/stm32_otg.h @@ -849,6 +849,8 @@ typedef struct { */ #define DOEPTSIZ_RXDPID_MASK (3U<<29) /**< Received data PID mask. */ #define DOEPTSIZ_RXDPID(n) ((n)<<29) /**< Received data PID value. */ +#define DOEPTSIZ_STUPCNT_MASK (3U<<29) /**< SETUP packet count mask. */ +#define DOEPTSIZ_STUPCNT(n) ((n)<<29) /**< SETUP packet count value. */ #define DOEPTSIZ_PKTCNT_MASK (0x3FFU<<19)/**< Packet count mask. */ #define DOEPTSIZ_PKTCNT(n) ((n)<<19) /**< Packet count value. */ #define DOEPTSIZ_XFRSIZ_MASK (0x7FFFFU<<0)/**< Transfer size mask. */ diff --git a/os/hal/platforms/STM32/OTGv1/usb_lld.c b/os/hal/platforms/STM32/OTGv1/usb_lld.c index 0059f69dc..327fe17d3 100644 --- a/os/hal/platforms/STM32/OTGv1/usb_lld.c +++ b/os/hal/platforms/STM32/OTGv1/usb_lld.c @@ -767,11 +767,15 @@ void usb_lld_write_packet_buffer(USBDriver *usbp, usbep_t ep, */ void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep, uint8_t *buf, size_t n) { + uint32_t pcnt; + USBOutEndpointState *osp = usbp->epc[ep]->out_state; - (void)usbp; - (void)ep; - (void)buf; - (void)n; + osp->rxbuf = buf; + osp->rxsize = n; + osp->rxcnt = 0; + pcnt = (n + usbp->epc[ep]->out_maxsize - 1) / usbp->epc[ep]->out_maxsize; + OTG->oe[ep].DOEPTSIZ = DOEPTSIZ_STUPCNT(3) | DOEPTSIZ_PKTCNT(pcnt) | + DOEPTSIZ_XFRSIZ(usbp->epc[ep]->out_maxsize); } /** @@ -786,6 +790,7 @@ void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep, */ void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep, const uint8_t *buf, size_t n) { + uint32_t pcnt; USBInEndpointState *isp = usbp->epc[ep]->in_state; isp->txbuf = buf; @@ -798,8 +803,7 @@ void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep, } else { /* Transfer initialization.*/ - uint32_t pcnt = (n + usbp->epc[ep]->in_maxsize - 1) / - usbp->epc[ep]->in_maxsize; + pcnt = (n + usbp->epc[ep]->in_maxsize - 1) / usbp->epc[ep]->in_maxsize; OTG->ie[ep].DIEPTSIZ = DIEPTSIZ_PKTCNT(pcnt) | DIEPTSIZ_XFRSIZ(usbp->epc[ep]->in_state->txsize); } @@ -816,7 +820,8 @@ void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep, void usb_lld_start_out(USBDriver *usbp, usbep_t ep) { (void)usbp; - (void)ep; + + OTG->oe[ep].DOEPCTL |= DOEPCTL_CNAK; } /**