Does anyone know how I can detect if my USB device is connected to a Host or not?
Thx Steven
> Well if monitoring VBUS is problematic, you can monitor Start Of Frame interrupts, only potential problem is that if host puts your device into suspend mode SOF will not be generated during suspended bus.
Unfortunately, "SOF interrupt" is not an indication of bus connection in many USB MCUs. In such USB engine, "SOF interrupt" is internally generated by counter, synchronized to bus SOF timing (digital PLL). Even while no bus SOF appears, SOF interrupt generation continues. This mechanism is so-called "SOF recovery", to keep track over missing SOF on the bus, which is essential for USB audio/video implementation.
STM32F2xx/4xx is such a device.
Tsuneo
Tsuneo, are correct regarding SOF interrupts on STM32F, I have now tried this on real hardware and SOF were not generated until device was first connected on USB, but from that point on they continued regardless of USB cable being disconnected.
A little feedback from my side: I used the same design with the same diode as the eval board and after I changed the ESD diode to an other with a additional diode on Vusb and voila it works because the problem was that the USB D+ was keept high from the STM32f and was feeding its own detection line PA9.
Thx all for your help and hints
Can you perhaps write in details (regarding board schematic found here http://www.keil.com/mcbstm32f200/mcbstm32f200-schematics.pdf) what needs to be changed on Keil MCBSTM32F400 board so other people having same problem can do it themselves.
sure! IC8 in the schematic is an USBLC6-4 use a WE-TVS instead. As you can see on the datasheet(katalog.we-online.de/.../824014.pdf) they have an extra diode on pin 5 in reverse direction to VDD. If now D+ is high on IC8 pin 3 it doesn't feed back to VBUS_FS which is connected to the USB detection pin PA9.
Cheers!
Great, thanks for detailed explanation I hope somebody having same issue in future will value this :-)
So with mentioned hardware changes + adding definition USBD_VBUS_DETECT=1 for driver solves problem of connect/disconnect detection.