|
| 1 | +.. _usb_device_networking_setup: |
| 2 | + |
| 3 | +USB Device Networking |
| 4 | +##################### |
| 5 | + |
| 6 | +This page describes how to set up networking between a Linux host |
| 7 | +and a Zephyr application running on USB supported devices. |
| 8 | + |
| 9 | +The board is connected to Linux host using USB cable |
| 10 | +and provides an Ethernet interface to the host. |
| 11 | +The :ref:`echo-server-sample` application from the Zephyr source |
| 12 | +distribution is run on supported board. The board is connected to a |
| 13 | +Linux host using a USB cable providing an Ethernet interface to the host. |
| 14 | + |
| 15 | +Basic Setup |
| 16 | +*********** |
| 17 | + |
| 18 | +To communicate with the Zephyr application over a newly created Ethernet |
| 19 | +interface, we need to assign IP addresses and set up a routing table for |
| 20 | +the Linux host. |
| 21 | +After plugging a USB cable from the board to the Linux host, the |
| 22 | +``cdc_ether`` driver registers a new Ethernet device with a provided MAC |
| 23 | +address. |
| 24 | + |
| 25 | +You can check that network device is created and MAC address assigned by |
| 26 | +running dmesg from the Linux host. |
| 27 | + |
| 28 | +.. code-block:: console |
| 29 | +
|
| 30 | + cdc_ether 1-2.7:1.0 eth0: register 'cdc_ether' at usb-0000:00:01.2-2.7, CDC Ethernet Device, 00:00:5e:00:53:01 |
| 31 | +
|
| 32 | +We need to set it up and assign IP addresses as explained in the following |
| 33 | +section. |
| 34 | + |
| 35 | +Choosing IP addresses |
| 36 | +===================== |
| 37 | + |
| 38 | +To establish network connection to the board we need to choose IP address |
| 39 | +for the interface on the Linux host. |
| 40 | + |
| 41 | +It make sense to choose addresses in the same subnet we have in Zephyr |
| 42 | +application. IP addresses usually set in the project configuration files |
| 43 | +and may be checked also from the shell with following commands. Connect |
| 44 | +a serial console program (such as puTTY) to the board, and enter this |
| 45 | +command to the Zephyr shell: |
| 46 | + |
| 47 | +.. code-block:: console |
| 48 | +
|
| 49 | + shell> net iface |
| 50 | +
|
| 51 | + Interface 0xa800e580 (Ethernet) |
| 52 | + =============================== |
| 53 | + Link addr : 00:00:5E:00:53:00 |
| 54 | + MTU : 1500 |
| 55 | + IPv6 unicast addresses (max 2): |
| 56 | + fe80::200:5eff:fe00:5300 autoconf preferred infinite |
| 57 | + 2001:db8::1 manual preferred infinite |
| 58 | + ... |
| 59 | + IPv4 unicast addresses (max 1): |
| 60 | + 192.0.2.1 manual preferred infinite |
| 61 | +
|
| 62 | +This command shows that one IPv4 address and two IPv6 addresses have |
| 63 | +been assigned to the board. We can use either IPv4 or IPv6 for network |
| 64 | +connection depending on the board network configuration. |
| 65 | + |
| 66 | +Next step is to assign IP addresses to the new Linux host interface, in |
| 67 | +the following steps ``enx00005e005301`` is the name of the interface on my |
| 68 | +Linux system. |
| 69 | + |
| 70 | +Setting IPv4 address and routing |
| 71 | +================================ |
| 72 | + |
| 73 | +.. code-block:: console |
| 74 | +
|
| 75 | + # ip address add dev enx00005e005301 192.0.2.2 |
| 76 | + # ip link set enx00005e005301 up |
| 77 | + # ip route add 192.0.2.0/24 dev enx00005e005301 |
| 78 | +
|
| 79 | +Setting IPv6 address and routing |
| 80 | +================================ |
| 81 | + |
| 82 | +.. code-block:: console |
| 83 | +
|
| 84 | + # ip address add dev enx00005e005301 2001:db8::2 |
| 85 | + # ip link set enx00005e005301 up |
| 86 | + # ip -6 route add 2001:db8::/64 dev enx00005e005301 |
| 87 | +
|
| 88 | +Testing connection |
| 89 | +****************** |
| 90 | + |
| 91 | +From the host we can test the connection by pinging Zephyr IP address of |
| 92 | +the board with: |
| 93 | + |
| 94 | +.. code-block:: console |
| 95 | +
|
| 96 | + $ ping 192.0.2.1 |
| 97 | + PING 192.0.2.1 (192.0.2.1) 56(84) bytes of data. |
| 98 | + 64 bytes from 192.0.2.1: icmp_seq=1 ttl=64 time=2.30 ms |
| 99 | + 64 bytes from 192.0.2.1: icmp_seq=2 ttl=64 time=1.43 ms |
| 100 | + 64 bytes from 192.0.2.1: icmp_seq=3 ttl=64 time=2.45 ms |
| 101 | + ... |
0 commit comments