esp-idf安装,及环境变量导入

众所周知,乐鑫科技是一家很牛逼的国际企业,所以其开发框架在国内很难下载到,这是非常符合逻辑的。

环境的安装

首先需要下载到打包的"esp-idf"和"espressif"。
esp-idf是乐鑫的开发框架,其中包含各种库函数。
espressif是乐鑫全系列产品对应的编译器。

选择好自己的工作目录,笔者的目录为:

#乐鑫开发环境主目录
C:\Users\$USER\Environment\ESP
#esp-idf目录,存放多个版本,示例为v4.4
C:\Users\$USER\Environment\ESP\esp-idf\v4.4
#编译器存放目录
C:\Users\$USER\Environment\ESP\.espressif

将打包好的文件包解压到指定目录

#idf解压目录
C:\Users\$USER\Environment\ESP\esp-idf\v4.4
#编译器压缩包文件解压目录
C:\Users\$USER\Environment\ESP\.espressif\dist

安装好python,版本为3.9及以下,并将pip镜像源更改至国内。
pip镜像源配置文件,地址栏搜索%APPDATA%,在弹出的目录下创建\pip\pip.in,
然后在其内写入

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

在"C:\Users$USER\Environment\ESP\esp-idf\v4.4"下打开powershell,导入IDF_TOOLS_PATH环境变量,并运行脚本install.bat

C:\Users\$USER\Environment\ESP\esp-idf\v4.4> $env:IDF_TOOLS_PATH="C:\Users\$USER\Environment\ESP\.espressif"
C:\Users\$USER\Environment\ESP\esp-idf\v4.4> .\install.bat

安装成功后,在"C:\Users$USER\Environment\ESP\esp-idf\v4.4"下打开powershell,并运行脚本export.ps1

C:\Users\$USER\Environment\ESP\esp-idf\v4.4> .\export.ps1

如执行该脚本时遇到权限问题,则以管理员权限打开powershell,并输入以下内容

set-executionpolicy remotesigned

环境的导入

编写powershell配置文件,在文件内创建导入上述环境的函数,供开发时调用。

#查看配置文件是否存在
Test-Path -Path $PROFILE
#如配置文件尚不存在,则输入以下命令创建文件
New-Item -ItemType File -Path $PROFILE -Force
#编辑该文件
notepad $PROFILE
#在文件内创建函数
function get_idf_v44 {
    $env:IDF_TOOLS_PATH="C:\Users\$USER\Environment\ESP\.espressif"
    . C:\Users\$USER\Environment\ESP\esp-idf\v4.4\export.ps1
}

使用该开发环境


PS C:\Users\$USER> get_idf_v44     
Setting IDF_PATH: C:\Users\$USER\Environment\ESP\esp-idf\v4.4
Adding ESP-IDF tools to PATH...
No directories added to PATH:
C:\Users\$USER\Environment\ESP\esp-idf\v4.4\components\esptool_py\esptool
C:\Users\$USER\Environment\ESP\esp-idf\v4.4\components\app_update
C:\Users\$USER\Environment\ESP\esp-idf\v4.4\components\espcoredump
C:\Users\$USER\Environment\ESP\esp-idf\v4.4\components\partition_table
C:\Users\$USER\Environment\ESP\.espressif\tools\xtensa-esp32-elf\esp-2021r2-8.4.0\xtensa-esp32-elf\bin
C:\Users\$USER\Environment\ESP\.espressif\tools\xtensa-esp32s2-elf\esp-2021r2-8.4.0\xtensa-esp32s2-elf\bin
C:\Users\$USER\Environment\ESP\.espressif\tools\xtensa-esp32s3-elf\esp-2021r2-8.4.0\xtensa-esp32s3-elf\bin
C:\Users\$USER\Environment\ESP\.espressif\tools\riscv32-esp-elf\esp-2021r2-8.4.0\riscv32-esp-elf\bin
C:\Users\$USER\Environment\ESP\.espressif\tools\esp32ulp-elf\2.28.51-esp-20191205\esp32ulp-elf-binutils\bin
C:\Users\$USER\Environment\ESP\.espressif\tools\esp32s2ulp-elf\2.28.51-esp-20191205\esp32s2ulp-elf-binutils\bin
C:\Users\$USER\Environment\ESP\.espressif\tools\cmake\3.20.3\bin
C:\Users\$USER\Environment\ESP\.espressif\tools\openocd-esp32\v0.10.0-esp32-20210902\openocd-esp32\bin
C:\Users\$USER\Environment\ESP\.espressif\tools\ninja\1.10.2\
C:\Users\$USER\Environment\ESP\.espressif\tools\idf-exe\1.0.2\
C:\Users\$USER\Environment\ESP\.espressif\tools\ccache\4.3\ccache-4.3-windows-64
C:\Users\$USER\Environment\ESP\.espressif\tools\dfu-util\0.9\dfu-util-0.9-win64
C:\Users\$USER\Environment\ESP\.espressif\python_env\idf5.0_py3.9_env\Scripts
C:\Users\$USER\Environment\ESP\esp-idf\v4.4\tools
%PATH%
C:\Program Files (x86)\VMware\VMware Workstation\bin\
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Windows\System32\OpenSSH\
C:\Program Files\Git\cmd
C:\Users\$USER\AppData\Local\Programs\Python\Python39\Scripts\
C:\Users\$USER\AppData\Local\Programs\Python\Python39\
C:\Users\$USER\AppData\Local\Microsoft\WindowsApps

Checking if Python packages are up to date...
Python requirements from C:\Users\$USER\Environment\ESP\esp-idf\v4.4\requirements.txt are satisfied.

Done! You can now compile ESP-IDF projects.
Go to the project directory and run:
    idf.py build

你可能感兴趣的:(esp-idf安装,及环境变量导入)