2024-06-15 10:30 AM
STM32F4 is working in USB Device MSC mode successfully.
I need to detect the USB connection state. I put the HAL_PCD_ConnectCallback function in main.c but on compiling I received warning.
Debug/../USB_DEVICE/Target/usbd_conf.c:307: multiple definition of `HAL_PCD_ConnectCallback';
I see it is weak in HAL_PCB_IRQHandler. Please suggest what I am missing.
2024-06-15 01:03 PM
Maybe not change the ConnectCallback ...try:
USBD_Get_USB_Status() -> until : usb_status = USBD_OK;
2024-06-16 08:15 AM
I just realized.. i can simply use PA9 to detect.
2024-06-16 12:28 PM
>I received warning
Read the compiler messages carefully, there must be reference to previous definition.
2024-06-19 11:55 AM
STM32F4 is set in USB DEVICE MSC mode.
I am seeing LED is glowing even when USB is not connected to HOST laptop. Intensity of LED glowing is low. Anyway, on connection to HOST laptop, the LED glow at high intensity which makes sense.
I am not using PA9 for VBUS detection. I set PA9 in reset condition and also rise/fall edge detection with PD but still LED2 is glowing.
Does USB hardware in STM32 always provide some power to PA9 pin ?
2024-06-19 12:10 PM
If you have usb-device active, there is a pullup (1,5k) on DP , so host can check: there is something...
and you have the diode-array , so the "+" pullup comes to the LED.
Thats the side-effect of your circuit with protection , just check voltage at VBUS, when not connected - and you see.
2024-06-19 12:25 PM
ok.. now it is clear to me why led is glowing.. thanks..
Now I am not sure how to detect USB connect & disconnect host, so I can interrupt my main application program.
I can not use PA9 as EXTI trigger as it is always high.
Should I poll continuously USBD_Get_USB_Status() in main while loop as you advised earlier?
I prefer call back interrupt function.
2024-06-19 12:55 PM - edited 2024-06-19 12:56 PM
Depends on, what you want:
just check, is host cable connected ? Then use PA9 (and put resistor 1k at vusb-> GND, to pull it low enough)
or check logical "connect" to host ? Then check USB_Status, maybe every 500ms (nobody can connect or disconnect the cable faster...), or every 1000ms ; this will not keep your cpu "busy"...(maybe 0.1% cpu load ) :)