aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2015-12-27 11:12:09 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2015-12-27 11:12:09 +0000
commitd93fdcd424c049078009119940d0042bb229ed38 (patch)
tree52201084180b40246ced4918e47936bbaaff0d97
parentef8ef298b95d0ea9c8807b36b7ae939f2dbab510 (diff)
downloadChibiOS-d93fdcd424c049078009119940d0042bb229ed38.tar.gz
ChibiOS-d93fdcd424c049078009119940d0042bb229ed38.tar.bz2
ChibiOS-d93fdcd424c049078009119940d0042bb229ed38.zip
Fixed stability problems in OTGv1.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8651 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/hal/ports/STM32/LLD/OTGv1/usb_lld.c35
-rw-r--r--os/hal/src/usb.c19
-rw-r--r--testhal/STM32/STM32F7xx/USB_RAW/debug/STM32F7xx-USB_RAW (OpenOCD, Flash and Run).launch4
-rw-r--r--testhal/STM32/STM32F7xx/USB_RAW/debug/STM32F7xx-USB_RAW (OpenOCD, Just Run).launch2
4 files changed, 44 insertions, 16 deletions
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);
diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c
index 2075cd7a2..b6813c381 100644
--- a/os/hal/src/usb.c
+++ b/os/hal/src/usb.c
@@ -380,6 +380,19 @@ void usbDisableEndpointsI(USBDriver *usbp) {
usbp->transmitting &= ~1U;
usbp->receiving &= ~1U;
for (i = 1; i <= (unsigned)USB_MAX_ENDPOINTS; i++) {
+#if USB_USE_WAIT == TRUE
+ /* Signaling the event to threads waiting on endpoints.*/
+ if (usbp->epc[i] != NULL) {
+ osalSysLockFromISR();
+ if (usbp->epc[i]->in_state != NULL) {
+ osalThreadResumeI(&usbp->epc[i]->in_state->thread, MSG_RESET);
+ }
+ if (usbp->epc[i]->out_state != NULL) {
+ osalThreadResumeI(&usbp->epc[i]->out_state->thread, MSG_RESET);
+ }
+ osalSysUnlockFromISR();
+ }
+#endif
usbp->epc[i] = NULL;
}
@@ -638,12 +651,14 @@ void _usb_reset(USBDriver *usbp) {
#if USB_USE_WAIT == TRUE
/* Signaling the event to threads waiting on endpoints.*/
if (usbp->epc[i] != NULL) {
+ osalSysLockFromISR();
if (usbp->epc[i]->in_state != NULL) {
osalThreadResumeI(&usbp->epc[i]->in_state->thread, MSG_RESET);
}
if (usbp->epc[i]->out_state != NULL) {
osalThreadResumeI(&usbp->epc[i]->out_state->thread, MSG_RESET);
}
+ osalSysUnlockFromISR();
}
#endif
usbp->epc[i] = NULL;
@@ -671,7 +686,7 @@ void _usb_reset(USBDriver *usbp) {
void _usb_suspend(USBDriver *usbp) {
/* State transition.*/
- usbp->state = USB_SUSPENDED;
+ usbp->state = USB_SUSPENDED;
/* Notification of suspend event.*/
_usb_isr_invoke_event_cb(usbp, USB_EVENT_SUSPEND);
@@ -683,12 +698,14 @@ void _usb_suspend(USBDriver *usbp) {
for (i = 0; i <= (unsigned)USB_MAX_ENDPOINTS; i++) {
if (usbp->epc[i] != NULL) {
+ osalSysLockFromISR();
if (usbp->epc[i]->in_state != NULL) {
osalThreadResumeI(&usbp->epc[i]->in_state->thread, MSG_TIMEOUT);
}
if (usbp->epc[i]->out_state != NULL) {
osalThreadResumeI(&usbp->epc[i]->out_state->thread, MSG_TIMEOUT);
}
+ osalSysUnlockFromISR();
}
}
}
diff --git a/testhal/STM32/STM32F7xx/USB_RAW/debug/STM32F7xx-USB_RAW (OpenOCD, Flash and Run).launch b/testhal/STM32/STM32F7xx/USB_RAW/debug/STM32F7xx-USB_RAW (OpenOCD, Flash and Run).launch
index 29bc3e81d..efae86141 100644
--- a/testhal/STM32/STM32F7xx/USB_RAW/debug/STM32F7xx-USB_RAW (OpenOCD, Flash and Run).launch
+++ b/testhal/STM32/STM32F7xx/USB_RAW/debug/STM32F7xx-USB_RAW (OpenOCD, Flash and Run).launch
@@ -33,9 +33,9 @@
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
-<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList/&gt;"/>
+<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;DAINTMSK-otgp-usb_lld_pump-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;globalVariableList/&gt;&#13;&#10;"/>
-<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList/&gt;&#13;&#10;"/>
+<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList&gt;&#13;&#10;&lt;memoryBlockExpressionItem&gt;&#13;&#10;&lt;expression text=&quot;0x20000f88&quot;/&gt;&#13;&#10;&lt;/memoryBlockExpressionItem&gt;&#13;&#10;&lt;/memoryBlockExpressionList&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="STM32F7xx-USB_RAW"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true"/>
diff --git a/testhal/STM32/STM32F7xx/USB_RAW/debug/STM32F7xx-USB_RAW (OpenOCD, Just Run).launch b/testhal/STM32/STM32F7xx/USB_RAW/debug/STM32F7xx-USB_RAW (OpenOCD, Just Run).launch
index 505471d29..c709f492b 100644
--- a/testhal/STM32/STM32F7xx/USB_RAW/debug/STM32F7xx-USB_RAW (OpenOCD, Just Run).launch
+++ b/testhal/STM32/STM32F7xx/USB_RAW/debug/STM32F7xx-USB_RAW (OpenOCD, Just Run).launch
@@ -33,7 +33,7 @@
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
-<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;vt_delta-null-chVTDoSetI-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;r3-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/>
+<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;r3-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;vt_delta-null-chVTDoSetI-(format)&quot; val=&quot;4&quot;/&gt;&lt;/contentList&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;globalVariableList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList&gt;&#13;&#10;&lt;memoryBlockExpressionItem&gt;&#13;&#10;&lt;expression text=&quot;0x20010744&quot;/&gt;&#13;&#10;&lt;/memoryBlockExpressionItem&gt;&#13;&#10;&lt;/memoryBlockExpressionList&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>