ESP32 development [2]: Linux environment (ubuntu) construction and engineering use

table of Contents

1. Installation steps

1. Tool download and installation

2. Obtain ESP-IDF

3. Setting tools

4. Set environment variables

2. Project configuration and compilation

1. Create a project

2. Connect the device

3. Configuration

4. Compile the project

5. Burn to the device

6. Add a monitor


1. Installation steps

1. Tool download and installation

Download the installation package:

sudo apt-get install git wget libncurses-dev flex bison gperf python python-pip python-setuptools cmake ninja-build ccache libffi-dev libssl-dev

Set Ubuntu to use Python 3 by default:

sudo apt-get install python3 python3-pip python3-setuptools

Set Python 3 as the default compiler:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

2. Obtain ESP-IDF

Open the terminal, create a new esp folder, and clone ESP-IDF to this directory:

mkdir esp
git clone -b release/v4.0 --recursive https://github.com/espressif/esp-idf.git

3. Setting tools

cd ~/esp/esp-idf
./install.sh

4. Set environment variables

Execute the following command, there should be a space between the "." at the beginning of the command and the path! But this has to be reset every time after restarting the system

. $HOME/esp/esp-idf/export.sh

You can also add this line of code to the .profile or .bash_profile script, so that you can use the ESP-IDF tool in any command window

cd ~ //进入跟目录下
geidt .profile //编辑 .profile文件
export IDF_PATH=/home/denghengli/esp/esp-idf  //在文件最后一行添加此命令。需要根据自己的安装目录修改路径!!!!

2. Project configuration and compilation

1. Create a project

You can start from  the get-started/hello_world  project in the examples directory of  ESP-IDF  . Copy  get-started/hello_world  to the local ~/esp directory:

cd ~/esp
cp -r $IDF_PATH/examples/get-started/hello_world .

Or use the project in the example directory directly without copying

2. Connect the device

Connect the ESP32 development board to the PC and check the serial port used by the development board (start with /dev/tty under Linux)

3. Configuration

1. Set the target chip (no need, the default will be esp32)

ESP-IDF supports a variety of chips, which are distinguished by using different "target" names in the software. The specific corresponding relationships are as follows:

  • esp32 — applicable to ESP32-D0WD, ESP32-D2WD, ESP32-S0WD (ESP-SOLO), ESP32-U4WDH, ESP32-PICO-D4
  • esp32s2—for ESP32-S2

So before building the project, you need to set the target chip. Reference link

idf.py set-target {IDF_TARGET} 例如:idf.py set-target esp32

2. Configuration engineering

The first step: Enter the example directory to be compiled, enter "hello_world"

第二步:输入 idf.py menuconfig

4. Compile the project

输入 idf.py build

5. Burn to the device

(1) Enter idf.py -p PORT [-b BAUD] PORT and replace it with the serial port name of the ESP32 development board. or

(2) Input idf.py -p PORT [-b BAUD] flash PORT Replace serial name ESP32 development board, to complete the project to compile and burn, will not need to perform idf.py build up

6. Add a monitor

Enter the   idf.py -p PORT monitor  command to monitor the running status of "hello_world" and use the shortcut key  Ctrl+] to exit the IDF monitor. You can also run the following commands to execute the build, burn and monitor processes at once

idf.py -p PORT flash monitor

【Permissions issue】:

The Failed to open port /dev/ttyUSB0 error message appears. At this time, you can add the current user to: ref:Linux Dialout group <linux-dialout-group>.

Method 1: Execute the following instructions to add users to the dialout group, which will take effect permanently. If unsuccessful, you can try the second method

sudo usermod -aG dialout denghengli

Method 2: Add permissions to /dev/tty/USB0, but it will be invalid after closing, and need to be added again next time

sudo chmod 777 /dev/ttyUSB0 

 

Guess you like

Origin blog.csdn.net/m0_37845735/article/details/107095243