Developing for ESP32/8266 on Windows using the Linux subsystem(WSL)

A small exploration for creating waveform vizualization on the web, simple and raw

Looking at most tutorials about developing for most microcontroller or embeded systems always ends up easier if you are using Linux. Being more comfortable with using Windows be it tools or just overall having to switch to Linux just to compile something is not really convenient. Most of the times you use MSYS or a virtual machine, all of this requires additional setup more things to learn and adapt to your standard coding workflow.

Recently with Windows 10 the added a Linux subsystem that allows you to choose from a couple of distributions and have the convinience of running Linux using a nice shell command prompt. They even provide a nice guide how to install and use ( https://docs.microsoft.com/en-us/windows/wsl/install-win10 ). The toolchains used xtensa-esp32 and xtensa-lx106 for ESP32 and ESP8266 respectively come with windows binaries but to use ESP-IDF you need to use certain tools available only to Linux. Having the Linux subsystem we can remedy this issue and have a smooth workflow from now on.

After installing everything for the WSL it can be opened like any other executable and greets you with a nice bash terminal. A couple of packages should be installed that are required for running all the tool in the ESP-IDF. After some research here is the list:

make
wget
gcc
python3
python-pip
python
libncurses5-dev
libncurses5
flex
bison
gperf
cu

Most of them are requred by the graphical interface for make menuconfig to render. Now we have to download the ESP-IDF toolkit and the respective compiler toolchain, after that we are good to go. Here you can find more information about installing on Linux and getting the compiler toolchain . We can start by creating our workspace directory where we want to do our develoment. You can access you standard Windows file system that is located in /mnt// . So to go to your folder in your D partition you would just cd /mnt/d/esp-devspace Next thing we should do is download the compiler toolchain and extract it to a directory. The links to the toolchains can be in the link above for ESP32 and https://github.com/espressif/ESP8266_RTOS_SDK for ESP8266. Download and extract the ESP32 toolchain

wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz
tar -xzf xtensa-esp32-elf-linux64–1.22.0–80-g6c4433a-5.2.0.tar.gz -C /xtensa-esp32

Download and extract the ESP8266 toolchain

wget https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-92-g8facf4c-5.2.0.tar.gz
tar -xzf xtensa-lx106-elf-linux64–1.22.0–92-g8facf4c-5.2.0.tar.gz -C /xtensa-esp8266

Download the ESP-IDF SDK

git clone — recursive https://github.com/espressif/esp-idf.git esp32-sdk

Download the ESP8266 SDK

git clone — recursive https://github.com/espressif/ESP8266_RTOS_SDK.git esp8266-sdk

After downloading all the necessary components i created a simple script to setup the environmental variables needed

Place the script in the folder you created for this development environment, its used every time you want to start using the tools for building with the ESP toolkits. First thing to do is replace the paths with the ones you created ( IDF_PATH is the path to the SDK and ESP32/8266_COMPILER_PATH is the path to the respective toolchains ). Running the script requires a single parameter ( esp32 or esp8266 ) that selects which one of the environments should be setup. source setup_environment.sh esp32

Now that we have put everything in place and set the environment variables we should install the python dependencies that are required by running

python -m pip install --user -r $IDF_PATH/requirements.txt

After this we have everything installed copy one of the example projects located in the examples directory in the corresponding SDK folder.

Only thing that couldn’t setup was writing to the COM port but this can easily be remedied by running make print_flash_cmd and getting the command just need to change some of the parameters to suit your setup and run in powershell or cmd.

Happy Coding :)