Construction of esp8266 Linux subsystem (WSL)-VSCode compilation environment

Posted by Nymphetamine on Tue, 21 Dec 2021 06:27:14 +0100

Construction of esp8266 Linux subsystem (WSL)-VSCode compilation environment

Install and configure wsl (I use Debian)

  • Install wsl

  • View system version

cat /etc/os-release

sudo nano /etc/apt/sources.list

So far, the wsl installation has been completed and the ESP8266 development environment has been built

  • Install common software
sudo apt-get install gcc git wget make libncurses-dev flex bison gperf python python-serial
  • report errors
Note, selecting 'python-is-python2' instead of 'python'
  • For the time being, don't install python3 here. The SDK building tool is based on python2!! Remove Python serial before installing
sudo apt-get install gcc git wget make libncurses-dev flex bison gperf python
  • This version of python does not have its own pip. Please install it manually here
# Install pip for python2
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
sudo python ez_setup.py --insecure
wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
# The * here is a wildcard
tar -xvf *.tar.gz
cd pip*
# install
sudo python setup.py install
ln -s /usr/local/python27/bin/pip /usr/bin/pip
  • The attempt to run pip --version failed because it did not contain the path where pip was installed
export PATH=$PATH:/usr/local/bin
  • Update pip after installation
pip install --upgrade pip
  • Download the cross compilation tool (put it on the physical machine, because even if the wsl crashes, the code is gone)

https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/get-started/linux-setup.html

  • Download the SDK (also on the physical machine, and the clone takes a long time)
git clone --recursive https://github.com/espressif/ESP8266_RTOS_SDK.git
  • git clone if there is a problem

Since github has strengthened its security strategy since August 2021, we can't just clone

  • Here, configure the personal information of github
git config --global user.name  "name"
git config --global user.email "mailbox"
# Take a look at the configuration information
git config -l
  • Then happy clone
  • After downloading, it looks like this

  • In wsl, enter the SDK directory and install the python dependent tools
# Installation dependency
python -m pip install --user -r ./requirements.txt
  • Include path
# Configure the SDK directory and cross compilation tool directory I downloaded (in the physical machine)
# / mnt/f / under wsl Is f: /
# Execute the following two lines
export IDF_PATH="/mnt/f/MyEnv/ESP8266/ESP8266_RTOS_SDK"
export PATH=$PATH:/mnt/f/MyEnv/ESP8266/xtensa-lx106-elf/bin
# Some tutorials install the SDK in the ~ / esp8266 directory
# export IDF_PATH="$HOME/esp8266/ESP8266_RTOS_SDK"
# export PATH=$PATH:$HOME/esp8266/xtensa-lx106-elf/bin
# pip
export PATH=$PATH:/usr/local/bin

# Add export and path to the shell environment
# IDF_ Add path to ~ / bashrc or ~ / zshrc (zsh yyds !!) in
export IDF_PATH="/mnt/f/MyEnv/ESP8266/ESP8266_RTOS_SDK"
# Add PATH to the Windows physical machine environment variable (user variable only needs to log off)
export PATH=$PATH:/mnt/f/MyEnv/ESP8266/xtensa-lx106-elf/bin
  • Windows physical environment variables

  • Enter the SDK routine and try compiling it

  • Configure serial port

cd $IDF_PATH/examples/get-started/hello_world
make menuconfig

To open the configuration interface, the console needs to be large enough!! Otherwise it won't run

  • Configure the serial port and baud rate (the higher the temperature, the faster the recording)

  • The serial port number of my computer is COM27, so the serial port in wsl configuration is / dev/ttyS27, and the baud rate is set to 921600, because it is fast!!

  • Compile it
make -j8 all
  • Burn after successful compilation
make flash

  • In order to compile a project anytime and anywhere (that is, those folders with SDK config files), write a powershell script to help compile
    • pwd_build.ps1
# Take absolute path parent path
$path_abs = Split-Path -Parent $MyInvocation.MyCommand.Definition

# Collate path
$path_abs = $path_abs -replace "\\", "/"
$path_abs = $path_abs -replace "C:", "c"
$path_abs = $path_abs -replace "D:", "d"
$path_abs = $path_abs -replace "E:", "e"
$path_abs = $path_abs -replace "F:", "f"
$path_abs = $path_abs -replace "G:", "g"
$path_abs = $path_abs -replace "H:", "h"
$path_abs = $path_abs -replace "I:", "i"
$path_abs = $path_abs -replace "J:", "j"
$path_abs = $path_abs -replace "K:", "k"
$path_abs = "/mnt/" + $path_abs
# Run build. In the absolute path under the current working directory sh
wsl "$path_abs/build.sh"

  • build.sh
export IDF_PATH="/mnt/f/MyEnv/ESP8266/ESP8266_RTOS_SDK"
export PATH=$PATH:/mnt/f/MyEnv/ESP8266/xtensa-lx106-elf/bin

# make menuconfig
make -j8 all
make flash
  • Put the two files together (you can open them in an environment variable and call them anywhere in powershell)

  • Run it and try it

  • make menuconfig OK

  • make flash OK

  • In this way, you can happily write code with VSCode and compile it with this script

  • Configure the tasks of VSCode json

  • settings. Set powershell as the default terminal in JSON

"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
  • Ctrl+Shift+B run compilation task

  • The compilation is normal and you can write code happily

Topics: C github Visual Studio Code debian MCU