Author Topic: STM32F4 USB & I2C... this is quite a whacky issue  (Read 987 times)

0 Members and 1 Guest are viewing this topic.

Offline MWPTopic starter

  • Contributor
  • Posts: 26
  • Country: au
STM32F4 USB & I2C... this is quite a whacky issue
« on: April 17, 2023, 07:20:44 am »
Hi folks,

I've been trying to fix this one for 5 days now... its driving me a bit crazy   :wtf:

My 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.

 :scared:

Anyone have any suggestions as to what may be the cause of this, or other things i can look for?

Thanks in advance!
 

Offline wek

  • Frequent Contributor
  • **
  • Posts: 495
  • Country: sk
Re: STM32F4 USB & I2C... this is quite a whacky issue
« Reply #1 on: April 17, 2023, 08:00:19 am »
Do you draw power from USB?

JW
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4427
  • Country: dk
Re: STM32F4 USB & I2C... this is quite a whacky issue
« Reply #2 on: April 17, 2023, 08:52:20 am »
interrupt priorities?
 

Offline Jope

  • Regular Contributor
  • *
  • Posts: 109
  • Country: de
Re: STM32F4 USB & I2C... this is quite a whacky issue
« Reply #3 on: April 17, 2023, 03:54:52 pm »
>the OS occasionally reports USB device failure

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?
 

Offline MWPTopic starter

  • Contributor
  • Posts: 26
  • Country: au
Re: STM32F4 USB & I2C... this is quite a whacky issue
« Reply #4 on: April 18, 2023, 02:37:55 am »
>> 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 priorities

I 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: [Select]
[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


 

Offline tabemann

  • Contributor
  • Posts: 43
  • Country: us
Re: STM32F4 USB & I2C... this is quite a whacky issue
« Reply #5 on: April 18, 2023, 03:00:15 am »
>> Interrupt priorities

I 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.

It cannot be interrupt priorities, because if it were then whether the F4 is connected to a hub or an isolator would make no difference.
 

Offline rteodor

  • Regular Contributor
  • *
  • Posts: 122
  • Country: ro
Re: STM32F4 USB & I2C... this is quite a whacky issue
« Reply #6 on: April 18, 2023, 04:10:01 am »
Hi folks,

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.

 :scared:

Anyone have any suggestions as to what may be the cause of this, or other things i can look for?

Thanks in advance!

Try powering from batteries and/or use a laptop without mains...
I'll revise that: try to get rid of all mains connected SMPS.
« Last Edit: April 18, 2023, 04:14:35 am by rteodor »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf