Skip to content

Commit

Permalink
Updating OTG code from upstream
Browse files Browse the repository at this point in the history
- Porting back changes from official ChibiOS code.
  • Loading branch information
josesimoes committed Jan 29, 2024
1 parent 2ba13ac commit 9a57970
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit 9a57970

Please sign in to comment.