MCU: stm32L476RC
OS: Chibios v16.1.5, RT kernel
USB: only D+ and D- connected
Generally, it seems that USB OTG in L476 is more like one in F7xx MCU, but HAL uses something like F4xx.
1) Max Endpoints count set to 3; ref man says 5 (usb_lld.h line 153; ref man p.1504)
2) usb_lld_connect_bus (usb_lld.h line 506) sets GCCFG_VBUSBSEN; there is no such bit in GCCFG (ref man p. 1551) => no connection occurs.
Same with usb_lld_disconnect_bus (usb_lld.h line 517)
When I clear DCTL_SDIS bit (like in F7xx MCU), - connection occurs.
But still no good after that: after several good-looking IRQs (Suspend, Reset, EnumerationDone, RxFifoLvl) I have ep0 out irq, with no STUP bit in DOEPINT register (strange 0x8001 value in it). After that _usb_ep0out called, which results in "EP0 state machine error", as ep0 is in USB_EP0_WAITING_SETUP state.
STM32L476 USB HAL errors Topic is solved
- RoccoMarco
- Posts: 655
- Joined: Wed Apr 24, 2013 4:11 pm
- Location: Munich (Germany)
- Has thanked: 83 times
- Been thanked: 67 times
- Contact:
Re: STM32L476 USB HAL errors
Hi,
thanks for the feedback.We are working on it. A more recent version of code is on trunk but I am currently unable to make OTG working.
I have found some issues on clock init so I had to fix it before to proceed with OTG fixes.
Ciao,
RM
thanks for the feedback.We are working on it. A more recent version of code is on trunk but I am currently unable to make OTG working.
I have found some issues on clock init so I had to fix it before to proceed with OTG fixes.
Ciao,
RM
Re: STM32L476 USB HAL errors
Here is what I found this morning.
USB OTG module of L476 generates extra IRQs when SETUP packet is received.
First is RXFLVL with "SETUP data packet received" in pkt status.
Then OEP INT for EP0, saying there is OUT data (and here HAL halts, as EP0 is waiting SETUP data).
After that again RXFLVL - saying zero bytes received, with "SETUP transaction completed" in pkt status.
After that again OEP INT for EP0, saying there is SETUP data, finally.
All started to work when I disabled halting and stalling on EP0 state machine error at line 954 of usb.c. Therefore state machine just ignores state errors and, consequently, extra irqs.
Not a good method, though But I need a working prototype by monday, and have to use dirty solutions.
Hope this helps. Thank you!
USB OTG module of L476 generates extra IRQs when SETUP packet is received.
First is RXFLVL with "SETUP data packet received" in pkt status.
Then OEP INT for EP0, saying there is OUT data (and here HAL halts, as EP0 is waiting SETUP data).
After that again RXFLVL - saying zero bytes received, with "SETUP transaction completed" in pkt status.
After that again OEP INT for EP0, saying there is SETUP data, finally.
All started to work when I disabled halting and stalling on EP0 state machine error at line 954 of usb.c. Therefore state machine just ignores state errors and, consequently, extra irqs.
Not a good method, though But I need a working prototype by monday, and have to use dirty solutions.
Hope this helps. Thank you!
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: STM32L476 USB HAL errors
Thanks for hints but we need to understand the root of the problem too.
At least we have a base to work on now.
Giovanni
At least we have a base to work on now.
Giovanni
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: STM32L476 USB HAL errors
Hi,
Finally fixed (bug #786).
It was caused by a different order in interrupts servicing on the L4, the transfer interrupt is triggered before the setup interrupt and this caused the problem.
The driver code has been modified to not depend on IRQ order, now it should be OK.
Thanks for the analysis, it helped a lot.
Giovanni
Finally fixed (bug #786).
It was caused by a different order in interrupts servicing on the L4, the transfer interrupt is triggered before the setup interrupt and this caused the problem.
The driver code has been modified to not depend on IRQ order, now it should be OK.
Thanks for the analysis, it helped a lot.
Giovanni
Re: STM32L476 USB HAL errors
Hi Giovanni,
it seems i am hitting a similar issue but on the fixed version: svn://svn.code.sf.net/p/chibios/svn/bra ... 6.1.x@9890
_usb_ep0out() panics with "EP0 state machine error" while usbp->ep0state being USB_EP0_TX.
Commenting out the error handling "fixes" it for me as well.
Wireshark trace up to the panic looks like this:
Kernel messages from host:
What information is required to further trace that issue down?
Cheers
Vinz
PS: STM32L476 on custom board, gcc arm embedded 5.4 2016q3
it seems i am hitting a similar issue but on the fixed version: svn://svn.code.sf.net/p/chibios/svn/bra ... 6.1.x@9890
_usb_ep0out() panics with "EP0 state machine error" while usbp->ep0state being USB_EP0_TX.
Commenting out the error handling "fixes" it for me as well.
Wireshark trace up to the panic looks like this:
Code: Select all
663 5.370454 host 2.0.0 USB 64 SET ADDRESS Request
664 5.370702 2.0.0 host USB 64 SET ADDRESS Response
665 5.390448 host 2.117.0 USB 64 GET DESCRIPTOR Request DEVICE
666 5.390696 2.117.0 host USB 82 GET DESCRIPTOR Response DEVICE
667 5.390724 host 2.117.0 USB 64 GET DESCRIPTOR Request DEVICE QUALIFIER
668 5.390970 2.117.0 host USB 64 GET DESCRIPTOR Response DEVICE QUALIFIER[Malformed Packet]
669 5.390996 host 2.117.0 USB 64 GET DESCRIPTOR Request DEVICE QUALIFIER
670 5.391442 2.117.0 host USB 64 GET DESCRIPTOR Response DEVICE QUALIFIER[Malformed Packet]
671 5.391460 host 2.117.0 USB 64 GET DESCRIPTOR Request DEVICE QUALIFIER
672 5.391815 2.117.0 host USB 64 GET DESCRIPTOR Response DEVICE QUALIFIER[Malformed Packet]
673 5.391845 host 2.117.0 USB 64 GET DESCRIPTOR Request CONFIGURATION
674 5.392190 2.117.0 host USB 64 GET DESCRIPTOR Response CONFIGURATION[Malformed Packet]
675 5.392204 host 2.117.0 USB 64 GET DESCRIPTOR Request CONFIGURATION
Kernel messages from host:
Code: Select all
[4660715.323138] usb 2-1.7.3.1: new full-speed USB device number 117 using ehci-pci
[4660720.415568] usb 2-1.7.3.1: unable to read config index 0 descriptor/start: -110
[4660720.415577] usb 2-1.7.3.1: can't read configurations, error -110
[4660720.491333] usb 2-1.7.3.1: new full-speed USB device number 118 using ehci-pci
[4660725.563534] usb 2-1.7.3.1: device descriptor read/64, error -110
What information is required to further trace that issue down?
Cheers
Vinz
PS: STM32L476 on custom board, gcc arm embedded 5.4 2016q3
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: STM32L476 USB HAL errors
hi,
I need to be able to debug, a list of steps in order to reproduce the issue.
Giovanni
I need to be able to debug, a list of steps in order to reproduce the issue.
Giovanni
Re: STM32L476 USB HAL errors
Hi Giovanni,
finally i found some time to reproduce the issue using a demo.
Apply the following patch to svn://svn.code.sf.net/p/chibios/svn/trunk@9991 which basically adds usb serial device to the stm32l476 demo and enables debug asserts:
Load the resulting image to a discoveryl476 board and connect the user usb to a host.
After the usb handshake has finished, the target will hang like this:
osalDbgAssert(false, "EP0 state machine error"); in _usb_ep0out triggers.
I hope this is sufficient for you to reproduce the issue.
Cheers
Vinz
finally i found some time to reproduce the issue using a demo.
Apply the following patch to svn://svn.code.sf.net/p/chibios/svn/trunk@9991 which basically adds usb serial device to the stm32l476 demo and enables debug asserts:
Code: Select all
diff --git a/demos/STM32/RT-STM32L476-DISCOVERY/Makefile b/demos/STM32/RT-STM32L476-DISCOVERY/Makefile
index 7b092d0..9354336 100644
--- a/demos/STM32/RT-STM32L476-DISCOVERY/Makefile
+++ b/demos/STM32/RT-STM32L476-DISCOVERY/Makefile
@@ -113,7 +113,7 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \
$(BOARDSRC) \
$(TESTSRC) \
- main.c
+ main.c usbcfg.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
diff --git a/demos/STM32/RT-STM32L476-DISCOVERY/chconf.h b/demos/STM32/RT-STM32L476-DISCOVERY/chconf.h
index ad6b53a..4e64ef1 100644
--- a/demos/STM32/RT-STM32L476-DISCOVERY/chconf.h
+++ b/demos/STM32/RT-STM32L476-DISCOVERY/chconf.h
@@ -347,7 +347,7 @@
*
* @note The default is @p FALSE.
*/
-#define CH_DBG_ENABLE_ASSERTS FALSE
+#define CH_DBG_ENABLE_ASSERTS TRUE
/**
* @brief Debug option, trace buffer.
diff --git a/demos/STM32/RT-STM32L476-DISCOVERY/halconf.h b/demos/STM32/RT-STM32L476-DISCOVERY/halconf.h
index 82602b4..c843cbb 100644
--- a/demos/STM32/RT-STM32L476-DISCOVERY/halconf.h
+++ b/demos/STM32/RT-STM32L476-DISCOVERY/halconf.h
@@ -146,7 +146,7 @@
* @brief Enables the SERIAL over USB subsystem.
*/
#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL_USB FALSE
+#define HAL_USE_SERIAL_USB TRUE
#endif
/**
@@ -167,7 +167,7 @@
* @brief Enables the USB subsystem.
*/
#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
-#define HAL_USE_USB FALSE
+#define HAL_USE_USB TRUE
#endif
/**
diff --git a/demos/STM32/RT-STM32L476-DISCOVERY/main.c b/demos/STM32/RT-STM32L476-DISCOVERY/main.c
index 50fb1dc..520700a 100644
--- a/demos/STM32/RT-STM32L476-DISCOVERY/main.c
+++ b/demos/STM32/RT-STM32L476-DISCOVERY/main.c
@@ -18,6 +18,8 @@
#include "hal.h"
#include "ch_test.h"
+#include "usbcfg.h"
+
/*
* LEDs blinker thread, times are in milliseconds.
*/
@@ -54,6 +56,22 @@ int main(void) {
chSysInit();
/*
+ * Initializes a serial-over-USB CDC driver.
+ */
+ sduObjectInit(&SDU1);
+ sduStart(&SDU1, &serusbcfg);
+
+ /*
+ * Activates the USB driver and then the USB bus pull-up on D+.
+ * Note, a delay is inserted in order to not have to disconnect the cable
+ * after a reset.
+ */
+ usbDisconnectBus(serusbcfg.usbp);
+ chThdSleepMilliseconds(1500);
+ usbStart(serusbcfg.usbp, &usbcfg);
+ usbConnectBus(serusbcfg.usbp);
+
+ /*
* Activates the serial driver 2 using the driver default configuration.
*/
sdStart(&SD2, NULL);
@@ -69,7 +87,7 @@ int main(void) {
*/
while (true) {
if (palReadLine(LINE_JOY_CENTER))
- test_execute((BaseSequentialStream *)&SD2);
+ test_execute((BaseSequentialStream *)&SDU1);
chThdSleepMilliseconds(500);
}
}
diff --git a/demos/STM32/RT-STM32L476-DISCOVERY/mcuconf.h b/demos/STM32/RT-STM32L476-DISCOVERY/mcuconf.h
index 82560bc..f7774df 100644
--- a/demos/STM32/RT-STM32L476-DISCOVERY/mcuconf.h
+++ b/demos/STM32/RT-STM32L476-DISCOVERY/mcuconf.h
@@ -321,7 +321,7 @@
/*
* USB driver system settings.
*/
-#define STM32_USB_USE_OTG1 FALSE
+#define STM32_USB_USE_OTG1 TRUE
#define STM32_USB_OTG1_IRQ_PRIORITY 14
#define STM32_USB_OTG1_RX_FIFO_SIZE 512
#define STM32_USB_OTG_THREAD_PRIO LOWPRIO
diff --git a/demos/STM32/RT-STM32L476-DISCOVERY/patch b/demos/STM32/RT-STM32L476-DISCOVERY/patch
new file mode 100644
index 0000000..e69de29
diff --git a/demos/STM32/RT-STM32L476-DISCOVERY/usbcfg.c b/demos/STM32/RT-STM32L476-DISCOVERY/usbcfg.c
new file mode 100644
index 0000000..15a88ad
--- /dev/null
+++ b/demos/STM32/RT-STM32L476-DISCOVERY/usbcfg.c
@@ -0,0 +1,373 @@
+/*
+ ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "hal.h"
+
+/* Virtual serial port over USB.*/
+SerialUSBDriver SDU1;
+
+/*
+ * Endpoints to be used for USBD1.
+ */
+#define USBD1_DATA_REQUEST_EP 1
+#define USBD1_DATA_AVAILABLE_EP 1
+#define USBD1_INTERRUPT_REQUEST_EP 2
+
+/*
+ * USB Device Descriptor.
+ */
+static const uint8_t vcom_device_descriptor_data[18] = {
+ USB_DESC_DEVICE (0x0110, /* bcdUSB (1.1). */
+ 0x02, /* bDeviceClass (CDC). */
+ 0x00, /* bDeviceSubClass. */
+ 0x00, /* bDeviceProtocol. */
+ 0x40, /* bMaxPacketSize. */
+ 0x0483, /* idVendor (ST). */
+ 0x5740, /* idProduct. */
+ 0x0200, /* bcdDevice. */
+ 1, /* iManufacturer. */
+ 2, /* iProduct. */
+ 3, /* iSerialNumber. */
+ 1) /* bNumConfigurations. */
+};
+
+/*
+ * Device Descriptor wrapper.
+ */
+static const USBDescriptor vcom_device_descriptor = {
+ sizeof vcom_device_descriptor_data,
+ vcom_device_descriptor_data
+};
+
+/* Configuration Descriptor tree for a CDC.*/
+static const uint8_t vcom_configuration_descriptor_data[67] = {
+ /* Configuration Descriptor.*/
+ USB_DESC_CONFIGURATION(67, /* wTotalLength. */
+ 0x02, /* bNumInterfaces. */
+ 0x01, /* bConfigurationValue. */
+ 0, /* iConfiguration. */
+ 0xC0, /* bmAttributes (self powered). */
+ 50), /* bMaxPower (100mA). */
+ /* Interface Descriptor.*/
+ USB_DESC_INTERFACE (0x00, /* bInterfaceNumber. */
+ 0x00, /* bAlternateSetting. */
+ 0x01, /* bNumEndpoints. */
+ 0x02, /* bInterfaceClass (Communications
+ Interface Class, CDC section
+ 4.2). */
+ 0x02, /* bInterfaceSubClass (Abstract
+ Control Model, CDC section 4.3). */
+ 0x01, /* bInterfaceProtocol (AT commands,
+ CDC section 4.4). */
+ 0), /* iInterface. */
+ /* Header Functional Descriptor (CDC section 5.2.3).*/
+ USB_DESC_BYTE (5), /* bLength. */
+ USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
+ USB_DESC_BYTE (0x00), /* bDescriptorSubtype (Header
+ Functional Descriptor. */
+ USB_DESC_BCD (0x0110), /* bcdCDC. */
+ /* Call Management Functional Descriptor. */
+ USB_DESC_BYTE (5), /* bFunctionLength. */
+ USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
+ USB_DESC_BYTE (0x01), /* bDescriptorSubtype (Call Management
+ Functional Descriptor). */
+ USB_DESC_BYTE (0x00), /* bmCapabilities (D0+D1). */
+ USB_DESC_BYTE (0x01), /* bDataInterface. */
+ /* ACM Functional Descriptor.*/
+ USB_DESC_BYTE (4), /* bFunctionLength. */
+ USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
+ USB_DESC_BYTE (0x02), /* bDescriptorSubtype (Abstract
+ Control Management Descriptor). */
+ USB_DESC_BYTE (0x02), /* bmCapabilities. */
+ /* Union Functional Descriptor.*/
+ USB_DESC_BYTE (5), /* bFunctionLength. */
+ USB_DESC_BYTE (0x24), /* bDescriptorType (CS_INTERFACE). */
+ USB_DESC_BYTE (0x06), /* bDescriptorSubtype (Union
+ Functional Descriptor). */
+ USB_DESC_BYTE (0x00), /* bMasterInterface (Communication
+ Class Interface). */
+ USB_DESC_BYTE (0x01), /* bSlaveInterface0 (Data Class
+ Interface). */
+ /* Endpoint 2 Descriptor.*/
+ USB_DESC_ENDPOINT (USBD1_INTERRUPT_REQUEST_EP|0x80,
+ 0x03, /* bmAttributes (Interrupt). */
+ 0x0008, /* wMaxPacketSize. */
+ 0xFF), /* bInterval. */
+ /* Interface Descriptor.*/
+ USB_DESC_INTERFACE (0x01, /* bInterfaceNumber. */
+ 0x00, /* bAlternateSetting. */
+ 0x02, /* bNumEndpoints. */
+ 0x0A, /* bInterfaceClass (Data Class
+ Interface, CDC section 4.5). */
+ 0x00, /* bInterfaceSubClass (CDC section
+ 4.6). */
+ 0x00, /* bInterfaceProtocol (CDC section
+ 4.7). */
+ 0x00), /* iInterface. */
+ /* Endpoint 3 Descriptor.*/
+ USB_DESC_ENDPOINT (USBD1_DATA_AVAILABLE_EP, /* bEndpointAddress.*/
+ 0x02, /* bmAttributes (Bulk). */
+ 0x0040, /* wMaxPacketSize. */
+ 0x00), /* bInterval. */
+ /* Endpoint 1 Descriptor.*/
+ USB_DESC_ENDPOINT (USBD1_DATA_REQUEST_EP|0x80, /* bEndpointAddress.*/
+ 0x02, /* bmAttributes (Bulk). */
+ 0x0040, /* wMaxPacketSize. */
+ 0x00) /* bInterval. */
+};
+
+/*
+ * Configuration Descriptor wrapper.
+ */
+static const USBDescriptor vcom_configuration_descriptor = {
+ sizeof vcom_configuration_descriptor_data,
+ vcom_configuration_descriptor_data
+};
+
+/*
+ * U.S. English language identifier.
+ */
+static const uint8_t vcom_string0[] = {
+ USB_DESC_BYTE(4), /* bLength. */
+ USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
+ USB_DESC_WORD(0x0409) /* wLANGID (U.S. English). */
+};
+
+/*
+ * Vendor string.
+ */
+static const uint8_t vcom_string1[] = {
+ USB_DESC_BYTE(38), /* bLength. */
+ USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
+ 'S', 0, 'T', 0, 'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'e', 0,
+ 'l', 0, 'e', 0, 'c', 0, 't', 0, 'r', 0, 'o', 0, 'n', 0, 'i', 0,
+ 'c', 0, 's', 0
+};
+
+/*
+ * Device Description string.
+ */
+static const uint8_t vcom_string2[] = {
+ USB_DESC_BYTE(56), /* bLength. */
+ USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
+ 'C', 0, 'h', 0, 'i', 0, 'b', 0, 'i', 0, 'O', 0, 'S', 0, '/', 0,
+ 'R', 0, 'T', 0, ' ', 0, 'V', 0, 'i', 0, 'r', 0, 't', 0, 'u', 0,
+ 'a', 0, 'l', 0, ' ', 0, 'C', 0, 'O', 0, 'M', 0, ' ', 0, 'P', 0,
+ 'o', 0, 'r', 0, 't', 0
+};
+
+/*
+ * Serial Number string.
+ */
+static const uint8_t vcom_string3[] = {
+ USB_DESC_BYTE(8), /* bLength. */
+ USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
+ '0' + CH_KERNEL_MAJOR, 0,
+ '0' + CH_KERNEL_MINOR, 0,
+ '0' + CH_KERNEL_PATCH, 0
+};
+
+/*
+ * Strings wrappers array.
+ */
+static const USBDescriptor vcom_strings[] = {
+ {sizeof vcom_string0, vcom_string0},
+ {sizeof vcom_string1, vcom_string1},
+ {sizeof vcom_string2, vcom_string2},
+ {sizeof vcom_string3, vcom_string3}
+};
+
+/*
+ * Handles the GET_DESCRIPTOR callback. All required descriptors must be
+ * handled here.
+ */
+static const USBDescriptor *get_descriptor(USBDriver *usbp,
+ uint8_t dtype,
+ uint8_t dindex,
+ uint16_t lang) {
+
+ (void)usbp;
+ (void)lang;
+ switch (dtype) {
+ case USB_DESCRIPTOR_DEVICE:
+ return &vcom_device_descriptor;
+ case USB_DESCRIPTOR_CONFIGURATION:
+ return &vcom_configuration_descriptor;
+ case USB_DESCRIPTOR_STRING:
+ if (dindex < 4)
+ return &vcom_strings[dindex];
+ }
+ return NULL;
+}
+
+/**
+ * @brief IN EP1 state.
+ */
+static USBInEndpointState ep1instate;
+
+/**
+ * @brief OUT EP1 state.
+ */
+static USBOutEndpointState ep1outstate;
+
+/**
+ * @brief EP1 initialization structure (both IN and OUT).
+ */
+static const USBEndpointConfig ep1config = {
+ USB_EP_MODE_TYPE_BULK,
+ NULL,
+ sduDataTransmitted,
+ sduDataReceived,
+ 0x0040,
+ 0x0040,
+ &ep1instate,
+ &ep1outstate,
+ 2,
+ NULL
+};
+
+/**
+ * @brief IN EP2 state.
+ */
+static USBInEndpointState ep2instate;
+
+/**
+ * @brief EP2 initialization structure (IN only).
+ */
+static const USBEndpointConfig ep2config = {
+ USB_EP_MODE_TYPE_INTR,
+ NULL,
+ sduInterruptTransmitted,
+ NULL,
+ 0x0010,
+ 0x0000,
+ &ep2instate,
+ NULL,
+ 1,
+ NULL
+};
+
+/*
+ * Handles the USB driver global events.
+ */
+static void usb_event(USBDriver *usbp, usbevent_t event) {
+ extern SerialUSBDriver SDU1;
+
+ switch (event) {
+ case USB_EVENT_ADDRESS:
+ return;
+ case USB_EVENT_CONFIGURED:
+ chSysLockFromISR();
+
+ /* Enables the endpoints specified into the configuration.
+ Note, this callback is invoked from an ISR so I-Class functions
+ must be used.*/
+ usbInitEndpointI(usbp, USBD1_DATA_REQUEST_EP, &ep1config);
+ usbInitEndpointI(usbp, USBD1_INTERRUPT_REQUEST_EP, &ep2config);
+
+ /* Resetting the state of the CDC subsystem.*/
+ sduConfigureHookI(&SDU1);
+
+ chSysUnlockFromISR();
+ return;
+ case USB_EVENT_RESET:
+ /* Falls into.*/
+ case USB_EVENT_UNCONFIGURED:
+ /* Falls into.*/
+ case USB_EVENT_SUSPEND:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduSuspendHookI(&SDU1);
+
+ chSysUnlockFromISR();
+ return;
+ case USB_EVENT_WAKEUP:
+ chSysLockFromISR();
+
+ /* Disconnection event on suspend.*/
+ sduWakeupHookI(&SDU1);
+
+ chSysUnlockFromISR();
+ return;
+ case USB_EVENT_STALLED:
+ return;
+ }
+ return;
+
+ switch (event)
+ {
+ case USB_EVENT_RESET:
+ return;
+ case USB_EVENT_ADDRESS:
+ return;
+ case USB_EVENT_CONFIGURED:
+ chSysLockFromISR();
+
+ /* Enables the endpoints specified into the configuration.
+ Note, this callback is invoked from an ISR so I-Class functions
+ must be used.*/
+ usbInitEndpointI(usbp, USBD1_DATA_REQUEST_EP, &ep1config);
+ usbInitEndpointI(usbp, USBD1_INTERRUPT_REQUEST_EP, &ep2config);
+
+ /* Resetting the state of the CDC subsystem.*/
+ sduConfigureHookI(&SDU1);
+
+ chSysUnlockFromISR();
+ return;
+ case USB_EVENT_UNCONFIGURED:
+ return;
+ case USB_EVENT_SUSPEND:
+ return;
+ case USB_EVENT_WAKEUP:
+ return;
+ case USB_EVENT_STALLED:
+ return;
+ }
+ return;
+}
+
+/*
+ * Handles the USB driver global events.
+ */
+static void sof_handler(USBDriver *usbp) {
+
+ (void)usbp;
+
+ osalSysLockFromISR();
+ sduSOFHookI(&SDU1);
+ osalSysUnlockFromISR();
+}
+
+/*
+ * USB driver configuration.
+ */
+const USBConfig usbcfg = {
+ usb_event,
+ get_descriptor,
+ sduRequestsHook,
+ sof_handler
+};
+
+/*
+ * Serial over USB driver configuration.
+ */
+const SerialUSBConfig serusbcfg = {
+ &USBD1,
+ USBD1_DATA_REQUEST_EP,
+ USBD1_DATA_AVAILABLE_EP,
+ USBD1_INTERRUPT_REQUEST_EP
+};
diff --git a/demos/STM32/RT-STM32L476-DISCOVERY/usbcfg.h b/demos/STM32/RT-STM32L476-DISCOVERY/usbcfg.h
new file mode 100644
index 0000000..b62a028
--- /dev/null
+++ b/demos/STM32/RT-STM32L476-DISCOVERY/usbcfg.h
@@ -0,0 +1,26 @@
+/*
+ ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#ifndef USBCFG_H
+#define USBCFG_H
+
+extern const USBConfig usbcfg;
+extern SerialUSBConfig serusbcfg;
+extern SerialUSBDriver SDU1;
+
+#endif /* USBCFG_H */
+
+/** @} */
Load the resulting image to a discoveryl476 board and connect the user usb to a host.
After the usb handshake has finished, the target will hang like this:
Code: Select all
#0 0x08008890 in chSysHalt (reason=<synthetic pointer>) at ../../../os/rt/src/chsys.c:200
#1 _usb_ep0out (usbp=0x20001238 <USBD1>, ep=0 '\000') at ../../../os/hal/src/hal_usb.c:951
#2 0x080084ca in usb_lld_serve_interrupt (usbp=<optimized out>) at ../../../os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c:621
#3 Vector14C () at ../../../os/hal/ports/STM32/LLD/OTGv1/hal_usb_lld.c:651
osalDbgAssert(false, "EP0 state machine error"); in _usb_ep0out triggers.
Code: Select all
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496]
I hope this is sufficient for you to reproduce the issue.
Cheers
Vinz
Who is online
Users browsing this forum: No registered users and 37 guests