esp32官方esp-idf SDK环境搭建
esp-idf SDK 环境配置(LINUX)
下载ESP-IDF
mkdir -p ~/esp cd ~/esp git clone -b v4.3 --recursive https://github.com/espressif/esp-idf.git
ESP-IDF下载至~/esp
安装 ESP-IDF
下载时优先选择Espressif下载服务器,并运行./install.sh安装:
cd ~/esp/esp-idf export IDF_GITHUB_ASSETS="dl.espressif.com/github_assets" ./install.sh
安装遇到问题:
解决办法:
python3 -m pip install --user virtualenv
这个是没有安装pip,解决办法如下:
sudo apt-get install python3-pip wget https://bootstrap.pypa.io/get-pip.py python3 -m pip install --user virtualenv
创建工程
将 get-started/hello_world 工程复制至您本地的 ~/esp 目录下:
cd ~/esp cp -r $IDF_PATH/examples/get-started/hello_world .
连接设备
现在,请将您的 ESP32 开发板连接到 PC,并查看开发板使用的串口。
通常,串口在不同操作系统下显示的名称有所不同
-
Windows 操作系统: COM1 等 Linux 操作系统: 以 /dev/tty 开始 macOS 操作系统: 以 /dev/cu. 开始
配置
进入hello_world目录,并运行工程配置工具menuconfig
cd ~/esp/hello_world idf.py set-target esp32 idf.py menuconfig
如果之前的步骤都正确,则会显示下面的菜单:
编译工程
编译工程:
idf.py build
运行以上命令可以编译应用程序和所有 ESP-IDF 组件,接着生成 bootloader、分区表和应用程序二进制文件。
$ idf.py build Running cmake in directory /path/to/hello_world/build Executing "cmake -G Ninja --warn-uninitialized /path/to/hello_world"... Warn about uninitialized values. -- Found Git:/usr/bin/git (found version "2.17.0") -- Building empty aws_iot component due to configuration -- Component names: ... -- Component paths: ... ... (more lines of build system output) [527/527] Generating hello-world.bin esptool.py v2.3.1 Project build complete. To flash, run this command: ../../../components/esptool_py/esptool/esptool.py -p (PORT) -b 921600 write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x10000 build/hello-world.bin build 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin or run idf.py -p PORT flash
如果一切正常,编译完成后将生成 .bin 文件。
烧录到设备
请使用以下命令,将刚刚生成的二进制文件 (bootloader.bin, partition-table.bin 和 hello-world.bin) 烧录至您的 ESP32 开发板:
df.py -p PORT [-b BAUD] flash
