Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Difference between revisions of "Rockpi4/dev/usbnet"

< Rockpi4‎ | dev
(Setup USB Network)
(Load kernel module)
Line 19: Line 19:
  
 
=== Load kernel module===
 
=== Load kernel module===
* insert kernel module
 
On ROCK Pi 4
 
  
    sudo modprobe g_ether
+
* Connect the ROCK Pi 4 to PC with the USB A to A cable, make sure the OTG switch is turned at the '''device''' side.
 +
 
 +
* Install kernel module on ROCK Pi 4
 +
 
 +
<pre>
 +
root@rockpi4:~# modprobe g_ether
 +
</pre>
  
 
dmesg shoule output the folowing:
 
dmesg shoule output the folowing:
 
<pre>
 
<pre>
 +
root@rockpi4:~# dmesg -c
 
[  388.650909] using random self ethernet address
 
[  388.650909] using random self ethernet address
 
[  388.651332] using random host ethernet address
 
[  388.651332] using random host ethernet address
Line 38: Line 43:
 
Bring up the usb0 device
 
Bring up the usb0 device
  
    sudo ifconfig usb0 up
+
<pre>
 +
root@rockpi4:~# ifconfig usb0 up
 +
</pre>
  
 
Now you should have usb0 on ROCK Pi 4 enabled.
 
Now you should have usb0 on ROCK Pi 4 enabled.
  
* Connect the ROCK Pi 4 to PC with the USB A to A cable, make sure the OTG switch is turned at the '''device''' side.
 
 
On the host PC ubuntu 16.04, the '''dmesg''' gives something like below:
 
On the host PC ubuntu 16.04, the '''dmesg''' gives something like below:
  
 
<pre>
 
<pre>
 +
radxa@x86_64_pc:~$ sudo dmesg -c
 
[714332.981224] usb 1-2: USB disconnect, device number 4
 
[714332.981224] usb 1-2: USB disconnect, device number 4
 
[714332.981402] cdc_ether 1-2:1.0 enp0s20f0u2: unregister 'cdc_ether' usb-0000:00:14.0-2, CDC Ethernet Device
 
[714332.981402] cdc_ether 1-2:1.0 enp0s20f0u2: unregister 'cdc_ether' usb-0000:00:14.0-2, CDC Ethernet Device

Revision as of 10:11, 14 April 2020

    ROCK Pi 4 >  Development >  USB Device Network

ROCK Pi 4 has one USB OTG port, which can be configured as USB devices with the Linux USB gadget driver, supporting multiple functions as a USB device such as Massive Storage Device and USB networking. We describe how to configure USBNET with a HOST PC.

Requirements

  • ROCK Pi 4
  • USB 3.0 or 2.0 male type A to male type A cable
  • Host PC running Linux OS

Kernel version

USB gadget driver must be enabled to configure usb net. kernel should be newer than 5e70f1495c248cf6ffa62d974ada7fc2172912cd. For Debian Stretch or Ubuntu, you can install the latest kernel from apt.radxa.com. For how to setup Radxa Apt, refer rockpi4/radxa-apt.

Load kernel module

  • Connect the ROCK Pi 4 to PC with the USB A to A cable, make sure the OTG switch is turned at the device side.
  • Install kernel module on ROCK Pi 4
root@rockpi4:~# modprobe g_ether

dmesg shoule output the folowing:

root@rockpi4:~# dmesg -c
[  388.650909] using random self ethernet address
[  388.651332] using random host ethernet address
[  388.653303] usb0: HOST MAC 7a:db:87:57:94:30
[  388.654077] usb0: MAC 12:d4:c3:ea:d1:31
[  388.654490] using random self ethernet address
[  388.654899] using random host ethernet address
[  388.655425] g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
[  388.656016] g_ether gadget: g_ether ready

Bring up the usb0 device

root@rockpi4:~# ifconfig usb0 up

Now you should have usb0 on ROCK Pi 4 enabled.

On the host PC ubuntu 16.04, the dmesg gives something like below:

radxa@x86_64_pc:~$ sudo dmesg -c
[714332.981224] usb 1-2: USB disconnect, device number 4
[714332.981402] cdc_ether 1-2:1.0 enp0s20f0u2: unregister 'cdc_ether' usb-0000:00:14.0-2, CDC Ethernet Device
[714344.746165] usb 1-2: new high-speed USB device number 5 using xhci_hcd
[714344.906872] usb 1-2: New USB device found, idVendor=0525, idProduct=a4a2
[714344.906878] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[714344.906882] usb 1-2: Product: RNDIS/Ethernet Gadget
[714344.906887] usb 1-2: Manufacturer: Linux 4.4.154-ge855bba-dirty with dwc3-gadget
[714344.910058] cdc_subset: probe of 1-2:1.0 failed with error -22
[714344.912272] cdc_ether 1-2:1.0 usb0: register 'cdc_ether' at usb-0000:00:14.0-2, CDC Ethernet Device, 76:2d:db:75:e9:68
[714344.920359] cdc_ether 1-2:1.0 enp0s20f0u2: renamed from usb0
[714344.958391] IPv6: ADDRCONF(NETDEV_UP): enp0s20f0u2: link is not ready
[714362.107471] usb 1-2: USB disconnect, device number 5
[714362.107601] cdc_ether 1-2:1.0 enp0s20f0u2: unregister 'cdc_ether' usb-0000:00:14.0-2, CDC Ethernet Device

enp0s20f0u2 is the "USB network card" for ROCK Pi 4. Ifconfig enp0s20f0u2 gives us the info about it.

Setup USB Network

On ROCK Pi 4.

   IP=10.0.1.1
   HOST_IP=10.0.1.2
   sudo ifconfig usb0 $IP netmask 255.255.255.0
   route

On host PC

   HOST_IP=10.0.1.2
   sudo ifconfig enp0s20f0u2 $HOST_IP netmask 255.255.255.0

Test the network, on ROCK Pi 4

   ping $HOST_IP

Test network traffic, on host PC

   iperf -s

on ROCK Pi 4:

   iperf -c $HOST_IP