From: Quentin Schulz <quentin.schulz@cherry.de>
To: "Marek Behún" <kabel@kernel.org>, u-boot@lists.denx.de
Subject: Re: device that supports both usb host & usb device modes?
Date: Mon, 14 Oct 2024 18:09:49 +0200 [thread overview]
Message-ID: <5e6139d0-e064-4097-926a-82d2dd374bcf@cherry.de> (raw)
In-Reply-To: <up3oe2ackjkjzugqypzcjzmqs4lgktbhn677lorwmztfwqkki6@s4z5orfn5ca7>
Hi Marek,
On 10/10/24 9:31 AM, Marek Behún wrote:
> Hi all,
>
> I am searching for HW that supports both USB host & USB device/gadget
> mode, on the same USB port, capable of switching between these modes
> at runtime.
>
> Preferably supported in upstream kernel.
>
I'm doing a very simple test on our (formerly known as Theobroma
Systems) RK3399 Puma with Haikou devkit and it seems to work fine
(insert USB stick into microUSB, detect the stick was connected, remove
USB stick, loop microUSB to USB, configure as ACM, send
test123test123test one way and then the other) as I have not commented
out the test for our internal releases :)
I believe that our RK3588 Tiger with Haikou devkit also supports it
(same test) but I am not the one who upstreamed nor tested that part
(and it doesn't work on our devices in peripheral mode on Rockchip BSP
kernel 5.10/6.1).
I don't think we do anything crazy here on the HW level, so I would say
anything based on RK3399 and RK3588(S) which advertises an USB OTG port
should be able to work. For RK3588(S) maybe check if it's on USB-C, as I
am not entirely sure whether we (upstream kernel) support FUSB302 (used
in the reference design from Rockchip I believe, so most manufacturers
do use them to limit risks) USB-C connector for OTG just yet (about to
though if I remember correctly). Maybe have a look on the side of RK356x
(RK3566/RK3568) as well, I've seen a few with ROCKUSB enabled in U-Boot,
which means OTG (at least in peripheral mode) is supported in U-Boot.
For reference, this is the test I run:
"""
#!/bin/sh
# Change UDC environment variable according to USB controller connected
to USB OTG port
set -eu
UDC=${UDC:-"fc000000.usb"}
cleanup_usb_otg() {
echo "" > "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/UDC"
rm "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/configs/conf.1/acm.1"
rmdir "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/configs/conf.1/strings/0x409/"
rmdir "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/configs/conf.1/"
rmdir "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/functions/acm.1/"
rmdir "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/strings/0x409/"
rmdir "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/"
}
run_cmd() {
set -x
"$@"
set +x
}
test_serial() {
TX=$1
RX=$2
RXPROOF=$(mktemp)
ORIG=$(mktemp)
(cat "$RX" > "$RXPROOF")&
PID=$!
printf "test123test123test\n" > "$ORIG"
# NOTE: \r instead of \n
# The message is sent only if \r or \n is passed, however the receiving
# end adds an additional newline. Therefore, to check data integrity the
# last character is different in the reference file and the message
# being sent.
printf "test123test123test\r" > "$TX"
# Give some time for the message to make it to the other side of the
# communication before killing the process.
sleep 1
kill $PID
wait $PID || true
diff "$ORIG" "$RXPROOF"
rm -rf "$ORIG" "$RXPROOF"
}
CONFIGFS_HOME=$(findmnt --noheadings --types configfs -o target)
if [ -z "$CONFIGFS_HOME" ]; then
CONFIGFS_HOME=$(mktemp --directory)
run_cmd mount none -t configfs "$CONFIGFS_HOME"
fi
if [ -e "$CONFIGFS_HOME/usb_gadget/q7-usb-p2" ]; then
set +e
run_cmd cleanup_usb_otg
set -e
fi
run_cmd mkdir "$CONFIGFS_HOME/usb_gadget/q7-usb-p2"
run_cmd echo 0xabcd > "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/idVendor"
run_cmd echo 0xef01 > "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/idProduct"
run_cmd mkdir "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/strings/0x409"
run_cmd echo SN1234567890 >
"$CONFIGFS_HOME/usb_gadget/q7-usb-p2/strings/0x409/serialnumber"
run_cmd echo Theobroma >
"$CONFIGFS_HOME/usb_gadget/q7-usb-p2/strings/0x409/manufacturer"
run_cmd echo Tiger-Haikou >
"$CONFIGFS_HOME/usb_gadget/q7-usb-p2/strings/0x409/product"
run_cmd mkdir "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/configs/conf.1/"
run_cmd mkdir
"$CONFIGFS_HOME/usb_gadget/q7-usb-p2/configs/conf.1/strings/0x409"
run_cmd echo "USB ACM test" >
"$CONFIGFS_HOME/usb_gadget/q7-usb-p2/configs/conf.1/strings/0x409/configuration"
run_cmd mkdir "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/functions/acm.1"
run_cmd ln -s "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/functions/acm.1"
"$CONFIGFS_HOME/usb_gadget/q7-usb-p2/configs/conf.1"
run_cmd echo "$UDC" > "$CONFIGFS_HOME/usb_gadget/q7-usb-p2/UDC"
# Give some time for the ACM device to be probed by the kernel
sleep 2
ACM="/dev/ttyACM0"
GS="/dev/ttyGS$(cat
"$CONFIGFS_HOME/usb_gadget/q7-usb-p2/functions/acm.1/port_num")"
run_cmd test_serial "$ACM" "$GS"
run_cmd test_serial "$GS" "$ACM"
echo "All good!"
"""
Once run, connect a USB stick to the port, it should be detected.
Cheers,
Quentin
next prev parent reply other threads:[~2024-10-14 16:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-10 7:31 device that supports both usb host & usb device modes? Marek Behún
2024-10-14 16:09 ` Quentin Schulz [this message]
2024-10-14 16:20 ` neil.armstrong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5e6139d0-e064-4097-926a-82d2dd374bcf@cherry.de \
--to=quentin.schulz@cherry.de \
--cc=kabel@kernel.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.