My goal is to write a MIDI music instrument with the Jetson Orin Nano and plug it into a PC to connect it to a synth using MIDI signals.
the USB gadget is there, but it’s used by the L4T, presumably to allow the PC to see it when you want to connect it using the SDK manager for example.
How I can I prevent the l4t gadget from being setup?
ls /sys/kernel/config/usb_gadget/
l4t midi_gadget
I setup the midi_gadget using a script like so (called by a service)
#!/bin/bash
Check if the script is run as root
if [[ $EUID -ne 0 ]]; then
echo “This script must be run as root”
exit 1
fiLoad USB gadget modules
modprobe libcomposite
Remove any existing USB gadget (to prevent conflicts)
GADGET_PATH=“/sys/kernel/config/usb_gadget/midi_gadget”
if [ -d “$GADGET_PATH” ]; then
echo “Removing existing gadget…”
echo “” > “$GADGET_PATH/UDC” 2>/dev/null
rm -rf “$GADGET_PATH”
sleep 1
fiCreate a new gadget
mkdir -p “$GADGET_PATH”
cd “$GADGET_PATH”Set USB device attributes
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite GadgetSet device description strings
mkdir -p strings/0x409
echo “001” > strings/0x409/serialnumber
echo “manufacturer” > strings/0x409/manufacturer
echo “aproduct” > strings/0x409/productCreate configuration
mkdir -p configs/c.1/strings/0x409
echo “Config 1: MIDI” > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPowerCreate MIDI function
mkdir -p functions/midi.usb0
echo “0” > functions/midi.usb0/in_jack_id
echo “1” > functions/midi.usb0/out_jack_idBind the configuration to the function
ln -s functions/midi.usb0 configs/c.1
Enable the USB gadget
UDC=$(ls /sys/class/udc | head -n 1)
if [ -z “$UDC” ]; then
echo “Error: No available UDC found!”
exit 1
fi
but I get this when I start the service:
Feb 06 20:18:33 hp-proto2a sudo[2282]: rm: cannot remove ‘/sys/kernel/config/usb_gadget/midi_gadget/bDeviceProtocol’: Operation not permitted
Feb 06 20:18:33 hp-proto2a sudo[2282]: rm: cannot remove ‘/sys/kernel/config/usb_gadget/midi_gadget/bDeviceSubClass’: Operation not permitted
Feb 06 20:18:33 hp-proto2a sudo[2282]: rm: cannot remove ‘/sys/kernel/config/usb_gadget/midi_gadget/bDeviceClass’: Operation not permitted
Feb 06 20:18:34 hp-proto2a sudo[2287]: mkdir: cannot create directory ‘functions/midi.usb0’: No such file or directory
Feb 06 20:18:34 hp-proto2a sudo[2277]: /usr/local/bin/setup_usb_midi.sh: line 62: functions/midi.usb0/in_jack_id: No such file or directory
Feb 06 20:18:34 hp-proto2a sudo[2277]: /usr/local/bin/setup_usb_midi.sh: line 63: functions/midi.usb0/out_jack_id: No such file or directory
Feb 06 20:18:34 hp-proto2a sudo[2289]: ln: failed to create symbolic link ‘configs/c.1/midi.usb0’: No such file or directory
Feb 06 20:18:34 hp-proto2a sudo[2277]: /usr/local/bin/setup_usb_midi.sh: line 75: echo: write error: Invalid argument
Feb 06 20:18:34 hp-proto2a sudo[2277]: USB MIDI gadget setup complete.
Feb 06 20:18:34 hp-proto2a sudo[2276]: pam_unix(sudo:session): session closed for user root
which I’m wondering if it’s due to the fact that there is already a gadget in place.
any suggestions?