/** * @brief USB low level reset routine. * * @param[in] usbp pointer to the @p USBDriver object * * @notapi */ void usb_lld_reset(USBDriver *usbp) { /* Post reset initialization.*/ /* EP0 initialization.*/ usbp->epc[0] = &ep0config; usb_lld_init_endpoint(usbp, 0); }
/** * @brief Enables an endpoint. * @details This function enables an endpoint, both IN and/or OUT directions * depending on the configuration structure. * @note This function must be invoked in response of a SET_CONFIGURATION * or SET_INTERFACE message. * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number * @param[in] epcp the endpoint configuration * * @iclass */ void usbInitEndpointI(USBDriver *usbp, usbep_t ep, const USBEndpointConfig *epcp) { osalDbgCheckClassI(); osalDbgCheck((usbp != NULL) && (epcp != NULL)); osalDbgAssert(usbp->state == USB_ACTIVE, "invalid state"); osalDbgAssert(usbp->epc[ep] == NULL, "already initialized"); /* Logically enabling the endpoint in the USBDriver structure.*/ if (epcp->in_state != NULL) memset(epcp->in_state, 0, sizeof(USBInEndpointState)); if (epcp->out_state != NULL) memset(epcp->out_state, 0, sizeof(USBOutEndpointState)); usbp->epc[ep] = epcp; /* Low level endpoint activation.*/ usb_lld_init_endpoint(usbp, ep); }
/** * @brief USB low level reset routine. * * @param[in] usbp pointer to the @p USBDriver object * * @notapi */ void usb_lld_reset(USBDriver *usbp) { uint32_t cntr; /* Post reset initialization.*/ STM32_USB->BTABLE = BTABLE_ADDR; STM32_USB->ISTR = 0; STM32_USB->DADDR = DADDR_EF; cntr = /*CNTR_ESOFM | */ CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM | /*CNTR_ERRM | CNTR_PMAOVRM |*/ CNTR_CTRM; /* The SOF interrupt is only enabled if a callback is defined for this service because it is an high rate source.*/ if (usbp->config->sof_cb != NULL) cntr |= CNTR_SOFM; STM32_USB->CNTR = cntr; /* Resets the packet memory allocator.*/ usb_pm_reset(usbp); /* EP0 initialization.*/ usbp->epc[0] = &ep0config; usb_lld_init_endpoint(usbp, 0); }
/** * @brief USB low level reset routine. * * @param[in] usbp pointer to the @p USBDriver object * * @notapi */ void usb_lld_reset(USBDriver *usbp) { /* Post-reset initialization.*/ /* Reset and enable via toggling the USB macro logic overall enable bit */ USBCON &= ~(1 << USBE); USBCON |= (1 << USBE); /* Unfreeze clock */ USBCON &= ~(1 << FRZCLK); /* Set Device mode */ /* TODO: Support HOST/OTG mode if needed */ UHWCON |= (1 << UIMOD); /* Set FULL 12mbps speed */ UDCON &= ~(1 << LSM); /* Enable device pin interrupt */ USBCON |= (1 << VBUSTE); /* EP0 initialization.*/ UERST |= (1 << 0); UERST &= ~(1 << 0); usbp->epc[0] = &ep0config; usb_lld_init_endpoint(usbp, 0); /* Enable device-level event interrupts */ UDINT &= ~(1 << SUSPI); UDIEN = (1 << UPRSME) | (1 << EORSME) | (1 << WAKEUPE) | (1 << EORSTE) | (1 << SUSPE); /* The SOF interrupt is only enabled if a callback is defined for this service because it is a high rate source. */ if (usbp->config->sof_cb != NULL) UDIEN |= (1 << SOFE); /* Set OTG PAD to on which will trigger VBUS transition if plugged in. */ USBCON |= (1 << OTGPADE); }