ubuntu 搭建ESP32开发环境 VSCODE配置

原文链接:https://blog.csdn.net/weixin_42133260/article/details/90600041

前提:
在电脑上已安装好ubutnu系统 (我是直接安装的Ubuntu18.04,不是虚拟机)
VS code 软件下载并安装好
准备工作:
1.在用户目录的下创建 esp目录,方便统一 工具链、ESP-IDF ESP-ADF 和 开发程序 . 如果创建的目录不同后续的命令也需要相应的修改

~$ mkdir ~/esp
~$ cd esp/

2.安装基础工具:

sudo  apt-get install gcc git wget make libncurses-dev flex bison gperf  python python-pip python-setuptools python-serial python-cryptography  python-future

3.下载ESP32 工具链,大家可以windows上下载,在复制到虚拟下的~/esp/目录下

64-bit Linux:https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz
32-bit Linux:https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-80-g6c4433a-5.2.0.tar.gz

4.将工具链解压到 ~/esp/xtensa-esp32-elf/ 目录

~/esp$ tar -xzf xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz

5.增加环境变量,需要在 ~/.profile 文件中更新环境变量 PATH

~/esp$ sudo vim ~/.profile

然后在打开的文件里添加 export PATH="$HOME/esp/xtensa-esp32-elf/bin:$PATH"
修改后的文件大概像下面这样

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
#esp32-tools
export PATH="$HOME/esp/xtensa-esp32-elf/bin:$PATH"

# if running bash
if [ -n "$BASH_VERSION" ]; then
	# include .bashrc if it exists
	if [ -f "$HOME/.bashrc" ]; then
		."$HOME/.bashrc"
	fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
	PATH="$HOME/bin:$PATH"
fi

重启执行下面指令测试是否设置成功

~$ printenv PATH

如果成功,则会在显示的字符串中出现 $HOME/esp/xtensa-esp32-elf/bin 其中$HOME=/home/用户名

安装ESP32 IDF

1.下载IDF仓库

~/esp$ git clone --recursive https://github.com/espressif/esp-idf.git

2.设置环境变量(和上面一样,完成后重启检查一下)

export IDF_PATH=~/esp/esp-idf

如果需要开发音频也可以安装ESP32 ADF

~/esp$  git clone --recursive https://github.com/espressif/esp-adf.git
export ADF_PATH=~/esp/esp-adf

安装 Python 软件包

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

设置VScode 和 工具链关联

新建一个 project 文件夹,用于存放自己编写的工程文件

mkdir ~/esp/project

VS Code 任务配置 tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build app", // f5
            "type": "shell",
            "command": "cd ${fileDirname} && cd ../ && make -j8",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "flash app", // f6
            "type": "shell",
            "command": "cd ${fileDirname} && cd ../ && make -j8 flash"
        },
        {
            "label": "monitor", // f7
            "type": "shell",
            "command": "cd ${fileDirname} && cd ../ && make monitor"
        },
        {
            "label": "clean app", // f8
            "type": "shell",
            "command": "cd ${fileDirname} && cd ../ && make clean",
        },
        {
            "label": "erase flash", // f9
            "type": "shell",
            "command": "cd ${fileDirname} && cd ../ && make erase_flash",
        },
        {
            "label": "menuconfig", // f10
            "type": "shell",
            "command": "cd ${fileDirname} && cd ../ && make menuconfig"
        },
    ]
}

配置添加头文件索引路径 c_cpp_properties.json, 不然一直有黄灯警告

(具体路径按实际路径填写)

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/esp32/sources/esp-idf/**",
                "/esp32/crossTools/xtensa-esp32-elf/xtensa-esp32-elf/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

最后尝试编译一下IDF中提供的例程 hello-world
如果报关于工具链相关的错误,根据提示重新安装对应的工具链.

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值