Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating OTG code from upstream #391

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c
Original file line number Diff line number Diff line change
Expand Up @@ -1448,35 +1448,40 @@ OSAL_IRQ_HANDLER(STM32_OTG2_HANDLER) {
static void otg_core_reset(stm32_otg_t *const otgp) {

/* Wait AHB idle condition.*/
while ((otgp->GRSTCTL & GRSTCTL_AHBIDL) == 0) osalSysPolledDelayX(1);
while ((otgp->GRSTCTL & GRSTCTL_AHBIDL) == 0)
;

/* Core reset and delay of at least 3 PHY cycles.*/
otgp->GRSTCTL = GRSTCTL_CSRST;
osalSysPolledDelayX(12);
while ((otgp->GRSTCTL & GRSTCTL_CSRST) != 0) osalSysPolledDelayX(1);
while ((otgp->GRSTCTL & GRSTCTL_CSRST) != 0)
;

osalSysPolledDelayX(18);

/* Wait AHB idle condition again.*/
while ((otgp->GRSTCTL & GRSTCTL_AHBIDL) == 0) osalSysPolledDelayX(1);
while ((otgp->GRSTCTL & GRSTCTL_AHBIDL) == 0)
;
}

static void otg_rxfifo_flush(USBHDriver *usbp) {
stm32_otg_t *const otgp = usbp->otg;

otgp->GRSTCTL = GRSTCTL_RXFFLSH;
while ((otgp->GRSTCTL & GRSTCTL_RXFFLSH) != 0) osalSysPolledDelayX(1);
while ((otgp->GRSTCTL & GRSTCTL_RXFFLSH) != 0)
;
/* Wait for 3 PHY Clocks.*/
osalSysPolledDelayX(24);
osalSysPolledDelayX(18);
}

static void otg_txfifo_flush(USBHDriver *usbp, uint32_t fifo) {
stm32_otg_t *const otgp = usbp->otg;

otgp->GRSTCTL = GRSTCTL_TXFNUM(fifo) | GRSTCTL_TXFFLSH;
while ((otgp->GRSTCTL & GRSTCTL_TXFFLSH) != 0) osalSysPolledDelayX(1);
while ((otgp->GRSTCTL & GRSTCTL_TXFFLSH) != 0)
;
/* Wait for 3 PHY Clocks.*/
osalSysPolledDelayX(24);
osalSysPolledDelayX(18);
}

static void _init(USBHDriver *host) {
Expand Down
Loading