I want to use Raspberry Pi 4B as a USB slave and master at the same time. It should connect to a Windows machine via any USB ports OR USB-C port and appear as a Serial device to the Windows machine while be connected to a different USB port to another device and read from it. I have tried it without BalenaOS and works fine using the steps here: Serial Gadget | Turning your Raspberry Pi Zero into a USB Gadget | Adafruit Learning System
Additionally @mpous I also see that the modprobe command cannot be found in my container. I can run it in host and it works fine but cannot run from my container as below
The steps you’re following from the guide are correct. As far as running modprobe in your container, you’ll need to install it before you can use it inside your application. Even though it’s present in the host OS, the container is isolated from that filesystem.
For example, in an Alpine based container image, you’d run apk add --update kmod. This could also be added as a RUN instruction to your Dockerfile.
FROM alpine:latest
# Install the modprobe utility
RUN apk add --no-cache kmod
# Copy the startup script
COPY startup.sh ./startup.sh
RUN chmod +x ./startup.sh
# Run the startup script
CMD ["./startup.sh"]
startup.sh as below:
#!/bin/sh
echo "Setting up USB connection"
# Execute the modprobe command
modprobe -a dwc2 g_serial --first-time
if [ -c "/dev/ttyGS0" ]; then
echo "modprobe command success, /dev/ttyGS0 exists"
else
echo "modprobe failed"
fi
# Exit the container
exit 0
Fails with the errors
modprobe: WARNING: Module dwc2 not found in directory /lib/modules/5.15.92-v8
modprobe: WARNING: Module g_serial not found in directory /lib/modules/5.15.92-v8