1. December 2021

How to connect ESP32 as USB serial device to Linux in WSL2 on Windows 11

There is a nice article and video explaining how to connect USB serial to Linux in WSL2.

Just few details are missing. Here is the full list of steps necessary to flash ESP32 with FTDI from WSL2:

  • Install Windows 11, open Windows Update – join Windows Insider Program (Beta channel) – install updates, reboot machine
  • Windows Update – Advanced Options – check the option “Receive updates for other Microsoft products” – Back – Check for updates
  • Reboot or shutdown WSL2 images
  • start a new WSL2 image e.g. with Ubuntu 20 LTS, check that you have kernel 5.10: uname -a. It does not work on 4.x kernel from normal WSL2
  • install https://github.com/dorssel/usbipd-win/releases on Windows
  • in Linux – sudo apt install linux-tools-5.4.0-77-generic hwdata
  • in Linux – visudo
  • in Linux – prepend path Defaults secure_path=”/usr/lib/linux-tools/5.4.0-77-generic:
  • connect ESP device with FTDI in Windows PowerShell (administrator) type: usbipd wsl list
  • search for 5-3 USB Serial Converter A, USB Serial Converter B Not attached
  • type in Windows: usbipd wsl attach -b 5-3 -d Ubuntu
  • type in Linux:cd examples/get-started/blink; idf.py build flash monitor

Result:

I (263) example: Example configured to blink addressable LED!
I (263) example: Turning the LED OFF!
I (1273) example: Turning the LED ON!

3. September 2021

How to flash ESP32 from WSL

WSL (Windows Subsystems for Linux) is a great way how to build projects based on ESP-IDF. The problem is how to flash the image from WSL Linux to a real chip?

Right now only WSL1 supports mapping of Windows COM ports to Linux /dev/ttyS*.

First of all, make sure that your image is running WSL1 (which is slower than WSL2):

wsl -l -v

In the case of WSL2 image, you can convert it by the following command (let assume the image of Ubuntu):

wsl -t Ubuntu
wsl --set-version Ubuntu 1

Use Windows Device Manager to determine COM ports of your ESP chip. Similar could be achieved by command:

mode

The number of COM.. device will be mapped to the /dev/ttyS.. in Linux.

Start the Linux terminal (e.g. using Windows Terminal). Grant permission so that your user can read write /dev/ttyS* or add your user to dialout group if supported by distribution. Note: on Linux, the device is often mapped to /dev/ttyUSB*, notice the difference on Windows /dev/ttyS*.

chmod a+rw /dev/ttyS*

Build and flash the project. It’s necessary to specify the device name, because autodetection in idf.py is not able to find /dev/ttyS. The second important part is to set the communication speed by “-b” option.

idf.py flash --port /dev/ttyS11 -b 115200
idf.py monitor --port /dev/ttyS11

The last command should launch idf monitor, which you can terminate by CTRL+].

If you’re WSL2 user, you can try alternative approach using idfx tool.

7. May 2021

How to speed up Linux on WSL2? Common mistake when upgrading from WSL1

According to Microsoft WSL2 is way faster than WSL1 for running Linux images. So, why even after upgrade to WSL2 is Linux running slow and with the same IO inefficiency like it was on WSL1?

The reason is simple. Even though the WSL2 was added to the operating system, the old images are running on WSL1. You can verify it by command:

wsl -l -v

Output:

  NAME                   STATE           VERSION
* openSUSE-Leap-15.2     Stopped         1
  Ubuntu                 Stopped         1
  docker-desktop-data    Stopped         2

As you can see both Ubuntu and openSUSE has set version to 1 which means that these images runs on WSL1. It’s necessary to explicitly change the version by following commands:

wsl --shutdown
wsl --set-version "Ubuntu" 2
wsl --set-version "openSUSE-Leap-15.2" 2 

The conversion will take some time. Output:

Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion complete.

Now you can verify the version of WSL for the image:

wsl -l -v
  NAME                   STATE           VERSION
* openSUSE-Leap-15.2     Stopped         2
  Ubuntu                 Stopped         2
  docker-desktop-data    Stopped         2

Simply start the shell of the distribution and you’ll experience better performance.

It’s also possible to set version for future images by command:

wsl --set-default-version 2

22. April 2021

How to run Linux GUI application on Windows WSL2 with MobaXterm and Windows Terminal

MobaXterm is a great software that allows running applications from Linux on Windows in a nice integrated way without the need of installing extra XServer.

MobaXterm has also support for WSL2 which makes it easy to launch Linux GUI applications from Linux on Windows.

After installation of Linux distribution like Ubuntu or openSUSE on WSL2, you will find new sessions with the prefix WSL in MobaXterm. Simply click the session label and a new terminal will be automatically configured to talk to the local XServer.

Now you can start any GUI command, e.g. xeyes.

The same XServer from MobaXterm can be used also from other terminals and shells like Windows Terminal. It’s sufficient to export environment variable DISPLAY in the Linux WSL2 session:

export DISPLAY=127.0.0.1:0.0
xeyes

Note: xeyes are part of x11-apps, you can install them by command

sudo apt install x11-apps