2024-08-02 06:11 AM - edited 2024-08-02 08:19 AM
Custom SMT32MP15 board connected via the micro USB to a host PC. This board has HDMI via an RGB to HDMI chip but here PA10 is only used for USB OTG-ID) (there was another post on this about HDMI). Build kernel from ECO 5.0. The Gadget functions worked fine with ECO 1.
On the host PC lsusb shows : ID 1d6b:0104 Linux Foundation Multifunction Composite Gadget
This would seems the gadget driver is working the board is in device mode. (right ?)
ls /sys/kernel/debug/usb/49000000.usb-otg/
dr_mode ep1in ep2in ep3in ep4in ep5in ep6in ep7in ep8in fifo params state
ep0 ep1out ep2out ep3out ep4out ep5out ep6out ep7out ep8out hw_params regdump testmode
Board dts entries: (based on the board entries form ECO 1.0 and ST Wiki)
Note: only added this in the kerne; dts, not in uboot.
in pinctrl section user code (the board with ECO 1 used this entry for PA10)
usbotg_hs_pins_a: usbotg_hs-0 {
pins {
pinmux = <STM32_PINMUX('A', 10, ANALOG)>; /* OTG_ID */
};
};
ls /sys/class/udc/49000000.usb-otg
a_alt_hnp_support b_hnp_enable device is_a_peripheral is_selfpowered power srp subsystem
a_hnp_support current_speed function is_otg maximum_speed soft_connect state uevent
After creating all the gadget file systems entries
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# echo 0x1235 > idVendor
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# echo 0x800c > idProduct
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# mkdir strings/0x409
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# echo 1234567890 > strings/0x409/serialnumber
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# echo Manufacturer_1 > strings/0x409/manufacturer
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# echo Product > strings/0x409/product
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# mkdir configs/c.1
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# mkdir configs/c.1/strings/0x409
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# echo "Conf 1" > configs/c.1/strings/0x409/configuration
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# echo 120 > configs/c.1/MaxPower
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# ls configs/c.1
MaxPower bmAttributes strings
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# ln -s functions/midi.usb0 configs/c.1
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# ln -s functions/midi.usb1 configs/c.1
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# name="$(ls /sys/class/udc)"
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# echo $name > UDC
[ 288.583969] UDC core: g2: couldn't find an available UDC or it's busy
sh: write error: Device or resource busy
root@stm32mp1:/sys/kernel/config/usb_gadget/g2# ls /sys/class/udc
49000000.usb-otg
in dmesg this was found:
[ 16.422555] dwc2 49000000.usb-otg: bound driver configfs-gadget.g1
moving the the gadget folder
cat UDC
49000000.usb-otg
root@stm32mp1:/sys/kernel/config/usb_gadget/g1# echo "" >UDC
root@stm32mp1:/sys/kernel/config/usb_gadget/g1# echo "49000000.usb-otg" > UDC
[ 1691.036019] stm32mp157-pinctrl soc:pinctrl@50002000: pin PA10 already requested by 49000000.usb-otg; cannot claim for gadget.0
[ 1691.046283] stm32mp157-pinctrl soc:pinctrl@50002000: pin-10 (gadget.0) status -22
[ 1691.053497] stm32mp157-pinctrl soc:pinctrl@50002000: could not request pin 10 (PA10) from group PA10 on device soc:pinctrl@50002000
[ 1691.065508] configfs-gadget.g1 gadget.0: Error applying setting, reverse things back
[ 1691.073372] UDC core: g1: couldn't find an available UDC or it's busy
sh: write error: Device or resource busy
root@stm32mp1:/sys/kernel/config/usb_gadget/g1
Any ideas what/how to debug the root cause ?
Here is some of the dwc2 debug information (enabled in kernel)
[ 424.658497] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: DxEPCTL=0x00498200, ep 1, dir in
[ 424.666702] dwc2 49000000.usb-otg: ureq->length:300 ureq->actual:0
[ 424.672886] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: 1@300/300, 0x2008012c => 0x00000930
[ 424.681299] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: d9003000 pad => 0x00000934
[ 424.688898] dwc2 49000000.usb-otg: ep0 state:0
[ 424.693362] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: DxEPCTL=0x84498200
[ 424.700351] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: DXEPCTL=0x80498200
[ 424.707365] dwc2 49000000.usb-otg: dwc2_hsotg_irq: 04048028 00040000 (d88c3c44) retry 8
[ 424.715288] dwc2 49000000.usb-otg: dwc2_hsotg_irq: daint=00000002
[ 424.721383] dwc2 49000000.usb-otg: dwc2_hsotg_epint: ep1(in) DxEPINT=0x00000001
[ 424.728584] dwc2 49000000.usb-otg: dwc2_hsotg_epint: XferCompl: DxEPCTL=0x00488200, DXEPTSIZ=1da7bb20
[ 424.737807] dwc2 49000000.usb-otg: dwc2_hsotg_complete_in: adjusting size done 0 => 300
[ 424.745817] dwc2 49000000.usb-otg: req->length:300 req->actual:300 req->zero:1
[ 424.753014] dwc2 49000000.usb-otg: complete: ep be8aa6fc ep1in, req 0cb15717, 0 => 932f0458
[ 437.445522] dwc2 49000000.usb-otg: dwc2_hsotg_irq: 04088028 00080000 (d88c3c44) retry 8
[ 437.452161] dwc2 49000000.usb-otg: dwc2_hsotg_irq: daint=00020000
[ 437.458244] dwc2 49000000.usb-otg: dwc2_hsotg_epint: ep1(out) DxEPINT=0x00000001
[ 437.465641] dwc2 49000000.usb-otg: dwc2_hsotg_epint: XferCompl: DxEPCTL=0x00098200, DXEPTSIZ=1bdf4d2e
[ 437.474859] dwc2 49000000.usb-otg: complete: ep 01bd230a ep1out, req ca238c7d, 0 => 65711172
[ 437.483283] dwc2 49000000.usb-otg: dwc2_hsotg_handle_unaligned_buf_complete: ep1out: status=0 actual-length=362
[ 437.493365] dwc2 49000000.usb-otg: ep1out: req ca238c7d: 16384@48778cb0, noi=0, zero=0, snok=0
[ 437.501887] dwc2 49000000.usb-otg: dwc2_hsotg_handle_unaligned_buf_start: ep1out: buf=48778cb0 length=16384
[ 437.511725] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: DxEPCTL=0x00098200, ep 1, dir out
[ 437.519931] dwc2 49000000.usb-otg: ureq->length:16384 ureq->actual:0
[ 437.526215] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: 32@16384/16384, 0x01004000 => 0x00000b30
[ 437.535132] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: d9004000 pad => 0x00000b34
[ 437.542729] dwc2 49000000.usb-otg: ep0 state:0
[ 437.547192] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: DxEPCTL=0x84098200
[ 437.554179] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: DXEPCTL=0x80098200
[ 439.513086] dwc2 49000000.usb-otg: ep1in: req 0cb15717: 300@86d2c43a, noi=0, zero=1, snok=0
[ 439.520049] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: DxEPCTL=0x00488200, ep 1, dir in
[ 439.528253] dwc2 49000000.usb-otg: ureq->length:300 ureq->actual:0
[ 439.534435] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: 1@300/300, 0x2008012c => 0x00000930
[ 439.542849] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: d9003000 pad => 0x00000934
[ 439.550448] dwc2 49000000.usb-otg: ep0 state:0
[ 439.554912] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: DxEPCTL=0x84488200
[ 439.561902] dwc2 49000000.usb-otg: dwc2_hsotg_start_req: DXEPCTL=0x80488200
[ 439.568878] dwc2 49000000.usb-otg: dwc2_hsotg_irq: 04048028 00040000 (d88c3c44) retry 8
[ 439.576799] dwc2 49000000.usb-otg: dwc2_hsotg_irq: daint=00000002
[ 439.582893] dwc2 49000000.usb-otg: dwc2_hsotg_epint: ep1(in) DxEPINT=0x00000001
[ 439.590195] dwc2 49000000.usb-otg: dwc2_hsotg_epint: XferCompl: DxEPCTL=0x00498200, DXEPTSIZ=1d9fb9f4
[ 439.599419] dwc2 49000000.usb-otg: dwc2_hsotg_complete_in: adjusting size done 0 => 300
[ 439.607430] dwc2 49000000.usb-otg: req->length:300 req->actual:300 req->zero:1
Solved! Go to Solution.
2024-08-02 06:09 PM
It works now.
First changed in dts:
1. changed dr_mode to to "peripheral"
2. remove pinctrl-0 = <&usbotg_hs_pins_a>;
This bring the device always in periheral mode , no matter PA10
[B] it seems at boot there is already a gadget running, called g1
This is the usb id 1d6b:0104 and the composite device visible on the host
1. disable the gadget g1 by echo "" > UDC (I once got permission error but later it worked), no idea why
2. Run the script to enable the gadget you want.
The gadget and its descriptors can now been seen on this host with lsusb
What does causes the composite gadget to be loaded at boot ? Can this be disabled ?
2024-08-02 06:09 PM
It works now.
First changed in dts:
1. changed dr_mode to to "peripheral"
2. remove pinctrl-0 = <&usbotg_hs_pins_a>;
This bring the device always in periheral mode , no matter PA10
[B] it seems at boot there is already a gadget running, called g1
This is the usb id 1d6b:0104 and the composite device visible on the host
1. disable the gadget g1 by echo "" > UDC (I once got permission error but later it worked), no idea why
2. Run the script to enable the gadget you want.
The gadget and its descriptors can now been seen on this host with lsusb
What does causes the composite gadget to be loaded at boot ? Can this be disabled ?