2025-11-14 11:18 AM
Hi all,
I'm trying to get a USB Gadget device working in Linux on the STM32MP257F-DK board to expose a Mass Storage device to another system. I'm trying to use CN15 for this function but I can't get the bound gadget to show up on the other side of the USB connection.
I'm using a fork of github.com/STMicroelectronics/linux?branch=v6.6-stm32mp where I've modified the usb3dr node of the dk.dts file with the following things:
1.
836 &usb3dr {
837 status = "okay";
838
839 dwc3: usb@48300000 {
840 phys = <&usb2_phy2>, <&combophy PHY_TYPE_USB3>;
841 phy-names = "usb2-phy", "usb3-phy";
842 usb-role-switch;
843 dr_mode = "peripheral";
844 port {
845 dwc3_ep: endpoint {
846 remote-endpoint = <&typec_ep>;
847 };
848 };
849 };
850 };840 - phys = <&usb2_phy2>, <&combophy PHY_TYPE_USB3>;
841 - phy-names = "usb2-phy", "usb3-phy";
842 840 usb-role-switch;
843 - dr_mode = "peripheral";
841 + role-switch-default-mode = "peripheral";
841 + maximum-speed = "high-speed";3.
843 +
844 + dr_mode = "peripheral";4.
844 - dr_mode = "peripheral";
844 + dr_mode = "otg";I've also validated that my hardware connection works by booting into serial downloader boot mode, in which case I've been able to see the `STMicroelectronics STM Device in DFU Mode`.
I did come across this post: https://community.st.com/t5/stm32-mpus-products-and-hardware/stm32mp257dak3-usb3dr-not-working-in-peripheral-mode-under-linux/m-p/796776
It seems like a similar, if not the same issue, but they don't actually detail what they did to the u-boot device tree to make it work.
Anyway, I'd appreciate any help anyone is willing to give!
Justin
2025-11-17 12:03 AM
Hi @jseely
Have you looked to https://wiki.st.com/stm32mpu/wiki/USB3DR_device_tree_configuration
Any significant message on the board console during boot (dmesg) ?
Regards.
2025-11-17 1:23 PM
Hi Patrick,
Thanks for the reply. Yes I have been looking at that, that has been where most of the things I have tried have come from.
As for the dmesg logs:
root@evb-stm32mp257f-dk:~# dmesg | grep -i "usb\|udc\|48300000"
[ 0.798737] /ahb@1/i2c@2/typec@35/connector: Fixed dependency cycle(s) with /soc@0/bus@42080000/usb@48300000/usb@48300000
[ 0.806632] /ahb@1/i2c@2/typec@35/connector: Fixed dependency cycle(s) with /soc@0/bus@42080000/usb@48300000/usb@48300000
[ 0.953126] usbcore: registered new interface driver usbfs
[ 0.958226] usbcore: registered new interface driver hub
[ 0.963501] usbcore: registered new device driver usb
[ 1.449341] usbcore: registered new interface driver usb-storage
[ 1.453385] usbcore: registered new device driver onboard-usb-hub
[ 1.506124] usbcore: registered new interface driver usbhid
[ 1.511024] usbhid: USB HID core driver
[ 1.734535] scmi-regulator scmi_dev.6: Regulator vdd3v3_usb registered for domain [20]
[ 2.262802] usb-stm32-dwc3 42080000.bus:usb@48300000: configured in usb3 mode
[ 2.265181] /ahb@1/i2c@2/typec@35/connector: Fixed dependency cycle(s) with /soc@0/bus@42080000/usb@48300000/usb@48300000
[ 2.275406] /soc@0/bus@42080000/usb@48300000/usb@48300000: Fixed dependency cycle(s) with /ahb@1/i2c@2/typec@35/connector
[ 2.289522] UDC core: USB initialize gadget.
[ 2.291658] UDC core: USB add gadget.
[ 2.294142] UDC core: USB gadget state set to 0.
[ 2.300571] UDC core: USB gadget state work scheduled.
[ 12.767092] stm32mp_pm_domain power-domain-d1: sync_state() pending due to 42080000.bus:usb@482e0000
[ 3809.622873] UDC core: USB gadget register driver owner requested.
[ 3809.623592] UDC core: USB gadget bind driver requested.
[ 3809.628717] UDC core: UDC set speed to 5.
[ 3809.645393] udc 48300000.usb: failed to start g_mass_storage: -22
[ 3809.657816] UDC core: g_mass_storage: couldn't find an available UDC
[ 3894.290040] UDC core: USB gadget register driver owner requested.
[ 3894.290705] UDC core: USB gadget bind driver requested.
[ 3894.296047] UDC core: UDC set speed to 5.
[ 3894.300783] UDC core: USB gadget enable async callbacks.
[ 3894.305138] UDC core: USB gadget connect control locked.
[ 3894.310917] UDC core: USB gadget connect requested.For context 3809 is where I `modprobe g_mass_storage` and 3894 is where I run the following script:
#!/usr/bin/env bash
set -eux
image=/home/root/usb.img
dd if=/dev/zero of=${image} bs=1MB count=25
usbdev_configfs=/sys/kernel/config/usb_gadget
gadget_dir=${usbdev_configfs}/mass-storage-test
mkdir ${gadget_dir}
cd ${gadget_dir}
echo 0x1d6b > idVendor
echo 0x0104 > idProduct
strings_dir=${gadget_dir}/strings/0x409
mkdir -p ${strings_dir}
echo "OpenBMC" > ${strings_dir}/manufacturer
echo "Virtual Media Device (test)" > ${strings_dir}/product
config_strings_dir="${gadget_dir}/configs/c.1/strings/0x409"
mkdir -p ${config_strings_dir}
echo "config 1" > ${config_strings_dir}/configuration
func_mass_storage_dir="${gadget_dir}/functions/mass_storage.usb0"
lun0="${func_mass_storage_dir}/lun.0"
mkdir -p ${lun0}
echo 1 > ${lun0}/removable
echo 0 > ${lun0}/ro
echo 0 > ${lun0}/cdrom
echo ${image} > ${lun0}/file
ln -s ${func_mass_storage_dir} "${gadget_dir}/configs/c.1/mass_storage.usb0"Most of the UDC core log messages are messages I placed inside `drivers/usb/dwc3/core.c` in the linux kernel to help with debugging.
Is there some way that the earlier boot layers could be restricting access to the memory regions I would need to configure the UDC on this port, specifically some way that linux wouldn't complain about when configured to use them?
Sorry I'm still very new to this chip!
Justin