Skip to content

Instantly share code, notes, and snippets.

@Cdaprod
Last active March 29, 2024 21:02
Show Gist options
  • Save Cdaprod/7b774b2e22f817d0c50fe5eb04840ba6 to your computer and use it in GitHub Desktop.
Save Cdaprod/7b774b2e22f817d0c50fe5eb04840ba6 to your computer and use it in GitHub Desktop.
This is a basic setup for an ad-hoc network. Adjust the ssid, frequency, and security settings (key_mgmt) as needed for your network.Additional ModulesYour interest in exploring other USB gadget modules like MIDI, HID, Audio, and Composite devices opens a wide range of possibilities. The CONFIG_USB_CONFIGFS_F_* settings in the kernel configurati…

To refine your Raspberry Pi Zero W’s config.txt to include USB Mass Storage, Ethernet over USB, HDMI, and set up an ad-hoc WiFi network, based on your requirements and the provided configurations, here’s an updated version of config.txt and additional steps for cmdline.txt and networking:

Refined config.txt

[all]
kernel=vmlinuz
cmdline=cmdline.txt
initramfs initrd.img followkernel
dtoverlay=dwc2,dr_mode=peripheral
dtparam=audio=on
dtparam=i2c_arm=on
dtparam=spi=on
disable_overscan=1
hdmi_drive=2
enable_uart=1
camera_auto_detect=1
display_auto_detect=1
arm_64bit=1

[pi4]
max_framebuffers=2
arm_boost=1

This configuration enables the basics for USB gadget mode with dwc2 in peripheral mode and other peripherals (I2C, SPI, audio, HDMI). The [pi4] section is kept for potential Raspberry Pi 4 specific settings but won’t affect the Pi Zero W.

Ethernet and Mass Storage via USB

To achieve Ethernet over USB alongside USB mass storage, the g_multi module is preferable as it can combine multiple functionalities. The setup for g_multi requires specifying the file for mass storage and setting up network options. Here’s an approach for cmdline.txt:

console=serial0,115200 multipath=off dwc_otg.lpm_enable=0 console=tty1 root=LABEL=writable rootfstype=ext4 rootwait modules-load=dwc2,g_multi g_multi.file=/piusb.bin g_multi.stall=0 g_multi.removable=1 g_multi.cdrom=0 g_multi.ro=0 g_multi.dev_addr=12:22:33:44:55:66 g_multi.host_addr=16:22:33:44:55:66 fixrtc cfg80211.ieee80211_regdom=US

This cmdline.txt configuration attempts to load the g_multi module with options for Ethernet and mass storage, where /piusb.bin is the file you prepared for mass storage. Modify the g_multi.file path as needed.

Fixed IP Address for Ethernet over USB

To assign a fixed IP address to the Ethernet gadget interface (usb0), edit /etc/dhcpcd.conf to prevent dhcpcd from configuring usb0, and set a static IP in /etc/network/interfaces or equivalent networking configuration file depending on your OS version:

interface usb0
static ip_address=192.168.7.2/24
static routers=192.168.7.1
static domain_name_servers=192.168.7.1

This setup assigns a fixed IP to the Pi, making it easier to connect without needing to discover the IP dynamically.

Ad-hoc WiFi Network

For setting up an ad-hoc WiFi network, you will need to edit /etc/wpa_supplicant/wpa_supplicant.conf to configure a network block for ad-hoc mode. Note that this configuration will vary based on your specific requirements for the network:

network={
    ssid="YourAdHocSSID"
    mode=1
    frequency=2412
    key_mgmt=NONE
}

This is a basic setup for an ad-hoc network. Adjust the ssid, frequency, and security settings (key_mgmt) as needed for your network.

Additional Modules

Your interest in exploring other USB gadget modules like MIDI, HID, Audio, and Composite devices opens a wide range of possibilities. The CONFIG_USB_CONFIGFS_F_* settings in the kernel configuration enable these functionalities. Use modprobe to load these modules as needed, potentially adjusting /etc/modules and creating /etc/modprobe.d/usbgadget.conf for module options. Exploring the USB gadget API framework page and resources like Sunxi’s gadget page can provide more detailed guidance on these advanced configurations.

Ensure you test each component of your setup thoroughly. Adjustments may be needed based on the devices you’re connecting to and the specific versions of the operating system and firmware on your Raspberry Pi Zero W.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment