|
| 1 | +--- |
| 2 | +title: "Working with Espressif's devkits using WSL2" |
| 3 | +date: 2024-10-10 |
| 4 | +showAuthor: false |
| 5 | +tags: ["ESP-IDF", "Windows", "WSL2"] |
| 6 | +authors: |
| 7 | + - "jakub-kocka" |
| 8 | +--- |
| 9 | + |
| 10 | +## Introduction |
| 11 | + |
| 12 | +[WSL](https://learn.microsoft.com/en-us/windows/wsl/) (Windows Subsystem for Linux) is a great way to run Linux alongside Windows. However, when there is a need to use it with Espressif's devkits, it can be a bit tricky due to the required serial port forwarding. In this short article, a step-by-step guide is provided to help you work with Espressif's devkits using WSL. |
| 13 | + |
| 14 | +### Alternatives |
| 15 | + |
| 16 | +Many common operations (e.g., flashing, monitoring, etc. ) can be handled by the [esp_rfc2217_server](https://docs.espressif.com/projects/esptool/en/latest/esp32/esptool/remote-serial-ports.html?highlight=rfc) (Telnet) where the host Windows machine acts as the server and the WSL terminal acts as the client. However, tools like OpenOCD (Open On-Chip Debugger) cannot be used with this approach. |
| 17 | + |
| 18 | +## Step-by-step Guide |
| 19 | + |
| 20 | +The following steps describe a serial port forwarding method for WSL using [usbipd-win](https://github.com/dorssel/usbipd-win). |
| 21 | +It is assumed that the latest version of WSL is already installed. A detailed guide and troubleshooting can be found in [Microsoft documentation](https://learn.microsoft.com/en-us/windows/wsl/connect-usb). |
| 22 | + |
| 23 | +(*tested with:* Windows 11 (23H2), usbipd-win 4.3.0) |
| 24 | + |
| 25 | +### 1. Install the USBIPD-WIN |
| 26 | + |
| 27 | +Using package manager in the host terminal |
| 28 | + |
| 29 | + winget install usbipd |
| 30 | + |
| 31 | +Or download the .msi file from the [latest releases](https://github.com/dorssel/usbipd-win/releases). |
| 32 | + |
| 33 | +### 2. Attach a devkit |
| 34 | + |
| 35 | +In the host terminal run |
| 36 | + |
| 37 | + usbipd list |
| 38 | + |
| 39 | +For example the used devkit is ESP32-C6 (**1-1 is the BUSID** which will be needed in the following commands) |
| 40 | + |
| 41 | + BUSID VID:PID DEVICE STATE |
| 42 | + 1-1 303a:1001 USB Serial Device (COM4), USB JTAG/serial debug unit Not shared |
| 43 | + |
| 44 | + |
| 45 | +Bind the listed devkit with following command in host terminal |
| 46 | + |
| 47 | + usbipd bind --busid 1-1 |
| 48 | + |
| 49 | +Attach the device in the host terminal |
| 50 | + |
| 51 | + usbipd attach --wsl --busid 1-1 |
| 52 | + |
| 53 | +Now you should be able to see the devkit in the WSL terminal (run *lsusb* to check) and that should be everything needed. You can start using the attached serial port directly in the WSL. |
| 54 | + |
| 55 | +### 3. Detach a devkit |
| 56 | + |
| 57 | +When working with the devkit is completed, you can detach the devkit with the command in the host terminal |
| 58 | + |
| 59 | + usbipd detach --busid 1-1 |
| 60 | + |
| 61 | +## Conclusion |
| 62 | + |
| 63 | +Working with WSL and Espressif's devkits for certain use cases may not be that simple. While for basic operations, using the esp_rfc2217_server might be enough (where the host machine acts as the server and the WSL terminal as the client) this method may not be always sufficient. In some cases, direct interaction with the devkit from within WSL becomes necessary. When that happens, serial port forwarding can be employed. With the help of this guide, we hope the process is now clearer, making it easier for you to work with Espressif's devkits in a WSL. |
| 64 | + |
| 65 | +## Resources |
| 66 | + |
| 67 | +- [Download Embedded Wizard](https://www.embedded-wizard.de/download/) |
| 68 | +- [Embedded Wizard Website](https://www.embedded-wizard.de/) |
| 69 | +- [Embedded Wizard YouTube Channel](https://www.youtube.com/@EmbeddedWizard) |
| 70 | +- [Getting Started with ESP32](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/) |
| 71 | +- [Overview: Embedded Wizard Integration with ESP32](https://www.embedded-wizard.de/platforms/espressif-esp32) |
0 commit comments