Is there a way to determine if USB-C connected?

  • Hello, the USB_VBUSDET pin, which serves as an indicator for both host and peripheral modes, is not exposed by default. Using other pins to detect voltage levels can be quite troublesome.
    If you plan to simulate a UMS (USB Mass Storage) device with the Luckfox Pico, it needs to operate in peripheral mode. You can try reading the dmesg information to determine whether the USB is connected. For example, when the ADB connection is disconnected, it will print:

    Code: Select all

    android_work: sent uevent USB_STATE=DISCONNECTED
    
  • Thank you for reply!
    Crocodile wrote: 2025-05-07 11:25 Hello, the USB_VBUSDET pin, which serves as an indicator for both host and peripheral modes, is not exposed by default. Using other pins to detect voltage levels can be quite troublesome.
    Why it could be troublesome?
    I was thinking about using GPIO connected to USB_DET_IN in parallel with USB_VBUSDET. GPIO input impedance should be high enough to not disturb the voltage divider significantly. As far as I remember USB_DET_IN is exposed as test point. Later I plan to use Core1106 and custom board, so than connection could be made with trace.
    Crocodile wrote: 2025-05-07 11:25 If you plan to simulate a UMS (USB Mass Storage) device with the Luckfox Pico, it needs to operate in peripheral mode. You can try reading the dmesg information to determine whether the USB is connected. For example, when the ADB connection is disconnected, it will print:

    Code: Select all

    android_work: sent uevent USB_STATE=DISCONNECTED
    
    I've tried again and now I get "android_work" messages. It's likely I did connect power to VBUS instead of VSYS and that prevented correct detection.

    Looking into dmesg will do for now. But later I would like to strip adb from the system, so I'll need to figure out another way. Maybe there are clues on how android_work does detection?
  • The Luckfox Pico Pro Max does provide test points, but to utilize the USB_VBUSDET functionality, additional jump wire connections are still required. However, if you plan to design a circuit board based on the Core1106, you can integrate the USB_VBUSDET functionality directly into the design.

    The source code responsible for printing “USB_STATE=DISCONNECTED” during adb connection is located at ${SDK}/sysdrv/source/kernel/drivers/usb/gadget/configfs.c. This code retrieves the complete gadget_info to obtain the USB connection status and then prints it out. If you are interested, you can delve deeper into this topic.
  • Crocodile wrote: 2025-05-09 1:39 The Luckfox Pico Pro Max does provide test points, but to utilize the USB_VBUSDET functionality, additional jump wire connections are still required. However, if you plan to design a circuit board based on the Core1106, you can integrate the USB_VBUSDET functionality directly into the design.
    For early prototype, adding a jumper wire is not a problem. Adding a proper connection on a custom board will be even easier.
    Crocodile wrote: 2025-05-09 1:39 The source code responsible for printing “USB_STATE=DISCONNECTED” during adb connection is located at ${SDK}/sysdrv/source/kernel/drivers/usb/gadget/configfs.c. This code retrieves the complete gadget_info to obtain the USB connection status and then prints it out. If you are interested, you can delve deeper into this topic.
    Thank you for help. Especially, for pointing to code responsible for tracking gadget state.
    That's it for now. I think, I have enough info to figure it out myself.