In this tutorial will show you how to develop your projects based on Visual Studio Code + ESP-IDF extension + Remote - WSL to implement all features of this extension in WSL.
you need to install the following tools before starting our projects:
- Ubuntu 20.04 on Windows using WSL
- Visual Studio Code
- usbipd-win
WSL is present starting from Windows 10 OS, so we can check the WSL list with the powershell command prompt, as below
wsl -l -oso to install WSL on windows, please type in the following command:
wsl --install --distribution Ubuntu-20.04where Ubuntu-20.04 is for your information.
To access the USB,serial,JTAG devices which are from the local windows, this tools must be installed, else it is impossible to download,monitor and debug on IDF docker image side. the way to install it, it is also same as windows applications, so it will not be described in detail here.
we still need to do a bit configurations after installing the four tools above:
the default version of WSL is 1 after installing, it needs to upgrade to version2 and then set it as the default distribution with the following steps:
-
check the current WSL version
wsl -l -v
-
please upgrade to version 2, if not
wsl --set-version Ubuntu-20.04 2
-
set the distribution, as below:
wsl -s Ubuntu 20.04
at last, to check if the commands have taken effect with wsl --status command.
Run the following command in WSL for ESP-IDF to work on Linux.
sudo apt-get install git wget flex bison gperf python3-pip python3-venv python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util
From windows side this tool should be already configured. However usbipd still need to be installed on the WSL, that is, open the WSL from Windows menu and then type in the following the commands separately:
apt install linux-tools-5.4.0-77-generic hwdata
update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/5.4.0-77-generic/usbip 20If any errors are found, try updating apt-get packages first.
apt-get updateNOTE: IF you are using a container made with the Dockerfile from this extension
.devcontainergenerated directory (when you create a project using theESP-IDF: New Project,ESP-IDF: Add docker container configurationorESP-IDF: Show Examplescommands).
with this the local Windows and WSL are all installed. To check usbipd tool is working well on both side, please follow the following steps:
-
open PowerShell command prompt with administrator right and then type in the command
usbipd wsl list:
as you can see, all USB devices from Windows have been found and not attached sate.
-
to access the specified device from local Windows on WSL, it needs to bind this device. Open PowerShell command prompt with administrator rights and then type in the command
usbipd bind -b <BUSID>:
Note: this command needs to be used only one time,unless the computer has restarted. 1-1 is the device's bus id I would like to bind.
-
after binding, please attach the specified device to WSL with
usbipd wsl attach --busid 1-1command in the powershell command prompt.
-
At last, let us check if it works well on both side and type in
dmesg | tailcommand on WSL side.
as we can see above, 1-1 device has been attached to
ttyACM0, that means WSL can access the 1-1 USB device now.
To develop in WSL, install the Remote - WSL、Remote Development and ESP-IDF extensions, as below:
After all previous steps have taken effect, the WSL should be ready to use. Here is an example to show you how to utilize these tools.
Using blink and hello_world projects as examples:
as seen from snapshot above, blink and hello_world example projects have been put in the same folder and we only need to open this folder with vscode:
some readers may see that there is a .devcontainer folder in the example_project folder, which is not included by default; this is generated by using the ESP-IDF extension of Visual Studio Code to create and configure the IDF docker image for container development. Check the docker container tutorial for more information.
Start your development by clicking the >< green button at the left bottom of Visual Studio Code and select Open Folder in WSL to start configuring the WSL and open the Blink example project.
at this moment, you can start to use the Blink example project for building, flashing, monitoring, debugging, etc.
Here taking the esp32-c3 as an example, users only need to change the target device from esp32 to esp32-c3, as below:
next, start to build the example project, as below:
after building, we can use the following ways to download the firmware.
Based on the description above, users can follow the instructions usbipd section mentioned. here Silicon Labs CP210x USB to UART Bridge is taken as an example, it has been attached to docker image:
as you can see, this device has attached to ttyUSB0, so idf.port also need to change accordingly.
but, the container doesn't know the configuration has changed yet at this moment.
so users need to reopen the container, that is Reopen Folder Locally and then the new configuration wil be reloaded as well.
at last, click the flash button and start to download the firmware.
Just as the external usb-serial, the only difference is the number attached. where the external usb-serial is ttyUSBx, while the internal usb-serial is ttyACMx.
Same as External USB-Serial and Internal USB-serial, but it needs to configure the following extra parameters:
the interface is the same as Internal USB-serial, that is ttyACMx:
After following USB-JTAG, press F5 to start to debug:
- When the container is created for the first time, it will prompt that the
ESP-IDF extensioncannot be activated because it depends on the MicrosoftC++ toolsextension. You only need to reopen the project in WSL again. This is because the ESP-IDF extension is dependent on the C++ Tools extension being installed first. - If you want to debug on Windows, you need to unplug the USB cable and re-plug in it again, otherwise the corresponding USB port cannot be found in the Windows device manager.


















