/** * @brief Prepares for a receive operation. * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number * * @notapi */ void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep) { uint32_t pcnt; USBOutEndpointState *osp = usbp->epc[ep]->out_state; /* Transfer initialization.*/ pcnt = (osp->rxsize + usbp->epc[ep]->out_maxsize - 1) / usbp->epc[ep]->out_maxsize; usbp->otg->oe[ep].DOEPTSIZ = DOEPTSIZ_STUPCNT(3) | DOEPTSIZ_PKTCNT(pcnt) | DOEPTSIZ_XFRSIZ(usbp->epc[ep]->out_maxsize); }
void Usb_t::IReset() { Uart.Printf("========= Rst =========\r\n"); TxFifoFlush(); // Set all EPs in NAK mode and clear Irqs for(uint8_t i=0; i < USB_EP_CNT; i++) { OTG_FS->ie[i].DIEPCTL = DIEPCTL_SNAK; OTG_FS->oe[i].DOEPCTL = DOEPCTL_SNAK; OTG_FS->ie[i].DIEPINT = 0xFF; OTG_FS->oe[i].DOEPINT = 0xFF; Ep[i].IsReceiving = false; Ep[i].IsTransmitting = false; Ep[i].IsTxPending = false; } // Disable and clear all EP irqs OTG_FS->DAINT = 0xFFFFFFFF; OTG_FS->DAINTMSK = DAINTMSK_OEPM(0) | DAINTMSK_IEPM(0); OTG_FS->DIEPEMPMSK &= 0xFFFF0000; MemAllocator.Reset(); // RX FIFO init, the address is always zero OTG_FS->GRXFSIZ = RX_FIFO_SZW; RxFifoFlush(); // Reset device address to zero OTG_FS->DCFG = (OTG_FS->DCFG & ~DCFG_DAD_MASK) | DCFG_DAD(0); // Enable EP-related irqs OTG_FS->GINTMSK |= GINTMSK_RXFLVLM | GINTMSK_OEPM | GINTMSK_IEPM; OTG_FS->DIEPMSK = DIEPMSK_XFRCM; OTG_FS->DOEPMSK = DOEPMSK_STUPM | DOEPMSK_XFRCM | DOEPMSK_OTEPDM; // Init EP0 OTG_FS->ie[0].DIEPINT |= 0x5B; // } OTG_FS->oe[0].DOEPINT |= 0x5B; // } Clear interrupts OTG_FS->oe[0].DOEPTSIZ = DOEPTSIZ_STUPCNT(3) | DOEPTSIZ_XFRSIZ(Ep[0].OutMaxSz); OTG_FS->oe[0].DOEPCTL = 0; // EP size is 64 bytes OTG_FS->ie[0].DIEPTSIZ = 0; OTG_FS->ie[0].DIEPCTL = DIEPCTL_TXFNUM(0); OTG_FS->DIEPTXF0 = DIEPTXF_INEPTXFD(TX0_FIFO_SZW) | DIEPTXF_INEPTXSA(RX_FIFO_SZW); // OTG_FS->DIEPTXF0 = DIEPTXF_INEPTXFD(EP0_SZ / 4) | DIEPTXF_INEPTXSA(MemAllocator.Alloc(EP0_SZ / 4)); Ep0State = esWaitingSetup; Ep[0].Rx.Ptr = Ep0RxBuf; }