Showing results for 
Search instead for 
Did you mean: 

STM32F4 HAL USB CDC - Occasional re-enumeration when I2C is also enabled


This is a super super weird one.

My device (STM32F401RC) uses the latest HAL libs vs STM32CubeIDE. USB is configured as device-only, CDC.

It works *perfectly* until i also enable one of the I2C peripherals (HAL, config'ed as I2C slave) and send/recv I2C data.

When i do so the OS (happens with Win10/11, Linux and OS-X) occasionally (every 5-20 sec) drops and re-connects the USB connection to my device.

What's stranger again, it'll only happen when connected via a USB hub. When connected directly to the PC it works ok.

I've also tried different hubs, it happens with all of them.

I've also tried connecting my device though a Total Phase USB analyzer. When its connected to the analyzer and the hub, the error no longer occurs (sigh).

Any ideas??

Thanks in advance!


Sounds more like hardware issue to me, i.e. I'd investigate power source/drop, crosstalk between I2C and the USB lines, observe using oscilloscope USB lines maybe even unconnected (maybe loaded by a 15k pulldown mimicking the hub) with and without I2C.