STM32F4 USB & I2C... this is quite a whacky issue - Page 1
Forum section: electronics / general

author: MWP
author_rank: Contributor
timestamp: April 17, 2023, 07:20:44 am
content: Hi folks,I've been trying to fix this one for 5 days now... its driving me a bit crazyMy device (STM32F401RC) uses the latest ST libs developed inside STM32CubeIDE. USB is configured as device-only, full-speed, CDC (tried both ST's HAL USB libs and TinyUSB CDC).USB coms works *perfectly* until i also enable one of the I2C peripherals (LL, config'ed as I2C slave) and send/recv I2C data.The master I2C device im testing with is a Seeeduino 4.2 (3.3V arduino clone).When I do enable the I2C peripheral, and send/recv I2C data, the OS occasionally reports USB device failure and disables then re-enables the USB device.This happens with all OS's (have tried Win10/11, Linux and OS-X).What's stranger again, it'll only happen when connected via a USB hub (pc -> hub -> my-device). I've also tried different hubs, it happens with all of them.If I use a USB isolator (so pc -> hub -> usb-iso -> my-device), the problem doesn't happen.So this suggests it's an electrical issue. Viewing USB & I2C signals the best I can on a DSO shows no obvious signs of a problem.The USB signaling looks clean when I2C is not in use, and looks identical when I2C is enabled and USB has issues.I've also tried not using the I2C peripheral, but just setting the SDA/SCL pins as push-pull outputs and toggling the pins quickly with the same attached I2C master device.I thought maybe the I2C peripheral pulling the I2C bus pull-up's down may be inducing some kind of power noise.Nope, USB continues working correctly.I've also tried different power supplies for the STM32 and Seeeduino, and scoped out all of it (cant see anything obvious).The STM32 has all the correct decoupling caps around it as per the reference manual.Anyone have any suggestions as to what may be the cause of this, or other things i can look for?Thanks in advance!

author: wek
author_rank: Frequent Contributor
timestamp: April 17, 2023, 08:00:19 am
content: Do you draw power from USB?JW

author: langwadt
author_rank: Super Contributor
timestamp: April 17, 2023, 08:52:20 am
content: interrupt priorities?

author: Jope
author_rank: Regular Contributor
timestamp: April 17, 2023, 03:54:52 pm
content: >the OS occasionally reports USB device failureHave you looked at the Linux kernel messages after the error occurs? You can usedmesgto view them. What exactly is reported regarding your device?

author: MWP
author_rank: Contributor
timestamp: April 18, 2023, 02:37:55 am
content: >> Do you draw power from USB?Normally, yes. But ive also tried powering the STM32 (close to the micro) from a Tek bench power supply.No change.>> Interrupt prioritiesI had this thought also, and double checked.Setup as 4 bits prio, 0 bits sub. Systick is at 0, USB is 1, others (incl I2C) are higher.>> Have you looked at the Linux kernel messages after the error occurs? You can use dmesg to view them. What exactly is reported regarding your device?Yes, i dev on a Linux PC and have been watching dmesg while trying to find the issue.It shows as:Code:[Apr17 14:22] usb 5-1.3: new full-speed USB device number 9 using xhci_hcd[ +0.138305] usb 5-1.3: New USB device found, idVendor=Cafe, idProduct=4001, bcdDevice= 1.00[ +0.000012] usb 5-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3[ +0.000004] usb 5-1.3: Product: TinyUSB Device[ +0.000003] usb 5-1.3: Manufacturer: TinyUSB[ +0.000003] usb 5-1.3: SerialNumber: -----SERIAL_NUMBER_NOT_SET-----[ +0.015897] cdc_acm 5-1.3:1.0: ttyACM1: USB ACM device[Apr17 15:28] usb 5-1-port3: disabled by hub (EMI?), re-enabling...[ +0.000762] usb 5-1.3: USB disconnect, device number 9[ +0.254509] usb 5-1.3: new full-speed USB device number 10 using xhci_hcd[ +0.142354] usb 5-1.3: New USB device found, idVendor=Cafe, idProduct=4001, bcdDevice= 1.00[ +0.000010] usb 5-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3[ +0.000004] usb 5-1.3: Product: TinyUSB Device[ +0.000003] usb 5-1.3: Manufacturer: TinyUSB[ +0.000002] usb 5-1.3: SerialNumber: -----SERIAL_NUMBER_NOT_SET-----[ +0.019818] cdc_acm 5-1.3:1.0: ttyACM2: USB ACM device[Apr17 15:29] usb 5-1-port3: disabled by hub (EMI?), re-enabling...[ +0.000333] usb 5-1.3: USB disconnect, device number 10[ +0.258059] usb 5-1.3: new full-speed USB device number 11 using xhci_hcd[ +0.138301] usb 5-1.3: New USB device found, idVendor=Cafe, idProduct=4001, bcdDevice= 1.00[ +0.000013] usb 5-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3[ +0.000004] usb 5-1.3: Product: TinyUSB Device[ +0.000003] usb 5-1.3: Manufacturer: TinyUSB[ +0.000003] usb 5-1.3: SerialNumber: -----SERIAL_NUMBER_NOT_SET-----[ +0.013130] cdc_acm 5-1.3:1.0: ttyACM2: USB ACM device.... and on it goes

author: tabemann
author_rank: Contributor
timestamp: April 18, 2023, 03:00:15 am
content: Quote from: MWP on April 18, 2023, 02:37:55 amIt cannot be interrupt priorities, because if it were then whether the F4 is connected to a hub or an isolator would make no difference.

author: rteodor
author_rank: Frequent Contributor
timestamp: April 18, 2023, 04:10:01 am
content: Quote from: MWP on April 17, 2023, 07:20:44 amTry powering from batteries and/or use a laptop without mains...I'll revise that: try to get rid of all mains connected SMPS.