Skip to content

Latest commit

 

History

History
203 lines (113 loc) · 8.12 KB

File metadata and controls

203 lines (113 loc) · 8.12 KB

Using Windows Subsystem for Linux (WSL)

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.

Required tools

  1. WSL 2
  2. Ubuntu on Windows using WSL
  3. Visual Studio Code
  4. usbipd-win

Ubuntu on Windows

If you don't have WSL installed run

wsl --install

Update the WSL kernel with

wsl --update

Check the WSL available distributions list with the Powershell command prompt, as below

wsl -l -o

so to install WSL on Windows, please type in the following command:

wsl --install --distribution Ubuntu

usbipd-win

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.

Configuration

we still need to do a bit configurations after installing the four tools above:

Ubuntu on Windows

  1. check the current WSL version

    wsl -l -v
  2. please upgrade to version 2, if not

    wsl --set-version Ubuntu 2
  3. set the distribution as default:

    wsl -s Ubuntu

at last, to check if the commands have taken effect with wsl --status command.

Adding the Required Linux Packages in WSL

Install ESP-IDF requirements for 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

usbipd

Install usbipd in Powershell command prompt:

winget install usbipd

Now configure the USB serial device to be able to connect to the WSL with usbipd:

  1. open PowerShell command prompt with administrator rights and then type in the command usbipd list for a list of USB serial devices.

  2. To access the specified device from Windows on WSL locally, the device must be bound with usbipd. Open PowerShell command prompt with administrator rights and then type in the command usbipd bind --busid <BUSID>:

    Note: this command needs to be used only one time,unless the computer has restarted.

  3. after binding, please attach the specified device to WSL with usbipd attach --wsl --busid <BUSID> command in the powershell command prompt.s

  4. At last, let us check if it works well on both side and type in dmesg | tail command 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 <BUSID> now.

Visual Studio Code

To develop in WSL, install the Remote - WSLRemote Development and ESP-IDF extensions, as below:

Configure the ESP-IDF extension as explained in the Install tutorial or in Setup documentation.

NOTE: Running the setup from WSL could override the Windows host machine configuration settings since it is using the User Settings by default. Consider saving settings to a workspace or workspace folder as described in the working with multiple projects document.

Practice

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.

Example Project with WSL

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.

Open Project in WSL

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.

Building the Project

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:

Flashing to your Device

after building, we can use the following ways to download the firmware.

External USB-Serial

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.

Internal USB-serial

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.

USB-JTAG

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:

Additional steps for debugging

Make sure to copy the OpenOCD udev rules files into the /etc/udev/rules.d directory before running OpenOCD and starting a debug session.

Debugging

After following USB-JTAG, press F5 to start to debug:

Precautions

  1. 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.