Page 1 of 1

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

Posted: 2025-05-07 9:30
by errno
I'm building custom camera/DVR solution based on LuckFox Pico Pro Max.
I want my device operate in two modes:
  • powered via VSYS and no USB connected - recording
  • powered via USB-C - emulate mass storage to access recorded files
Thus on boot system have to figure out if USB-C is plugged in and follow one or the other boot sequence.
I've spent a fair amount of time figuring out if this is possible via sysfs, but didn't find distinctive.

I went through schematic and fond that RV1106 has special pin USB_VBUSDET. Is it relevant? Can I access a level of this input?

Any help or ideas appreciated.

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

Posted: 2025-05-07 11:25
by Crocodile
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

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

Posted: 2025-05-08 9:06
by errno
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?

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

Posted: 2025-05-09 1:39
by Crocodile
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.

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

Posted: 2025-05-09 10:09
by errno
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.