From d93fdcd424c049078009119940d0042bb229ed38 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 27 Dec 2015 11:12:09 +0000 Subject: Fixed stability problems in OTGv1. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8651 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/OTGv1/usb_lld.c | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'os/hal/ports/STM32/LLD') diff --git a/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c b/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c index 00ada1203..a4a784d2a 100644 --- a/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c +++ b/os/hal/ports/STM32/LLD/OTGv1/usb_lld.c @@ -511,6 +511,19 @@ static void usb_lld_serve_interrupt(USBDriver *usbp) { sts &= otgp->GINTMSK; otgp->GINTSTS = sts; + /* Reset interrupt handling.*/ + if (sts & GINTSTS_USBRST) { + + /* Resetting pending operations.*/ + usbp->txpending = 0; + + /* Default reset action.*/ + _usb_reset(usbp); + + /* Preventing execution of more handlers, the core has been reset.*/ + return; + } + /* Wake-up handling.*/ if (sts & GINTSTS_WKUPINT) { /* If clocks are gated off, turn them back on (may be the case if @@ -529,13 +542,11 @@ static void usb_lld_serve_interrupt(USBDriver *usbp) { /* Suspend handling.*/ if (sts & GINTSTS_USBSUSP) { - _usb_suspend(usbp); - } - - /* Reset interrupt handling.*/ - if (sts & GINTSTS_USBRST) { + /* Resetting pending operations.*/ + usbp->txpending = 0; - _usb_reset(usbp); + /* Default suspend action.*/ + _usb_suspend(usbp); } /* Enumeration done.*/ @@ -920,18 +931,18 @@ void usb_lld_reset(USBDriver *usbp) { /* Flush the Tx FIFO.*/ otg_txfifo_flush(usbp, 0); + /* Endpoint interrupts all disabled and cleared.*/ + otgp->DIEPEMPMSK = 0; + otgp->DAINTMSK = DAINTMSK_OEPM(0) | DAINTMSK_IEPM(0); + /* All endpoints in NAK mode, interrupts cleared.*/ for (i = 0; i <= usbp->otgparams->num_endpoints; i++) { otgp->ie[i].DIEPCTL = DIEPCTL_SNAK; otgp->oe[i].DOEPCTL = DOEPCTL_SNAK; - otgp->ie[i].DIEPINT = 0xFF; - otgp->oe[i].DOEPINT = 0xFF; + otgp->ie[i].DIEPINT = 0xFFFFFFFF; + otgp->oe[i].DOEPINT = 0xFFFFFFFF; } - /* Endpoint interrupts all disabled and cleared.*/ - otgp->DAINT = 0xFFFFFFFF; - otgp->DAINTMSK = DAINTMSK_OEPM(0) | DAINTMSK_IEPM(0); - /* Resets the FIFO memory allocator.*/ otg_ram_reset(usbp); -- cgit v1.2.3