ESP8266 RTOS开发之路(1)— 搭建在Ubuntu下的开发环境

ESP8266 RTOS开发之路(1)— 搭建在Ubuntu下的开发环境

一、前言

本次基于虚拟机下的Ubuntu18系统,搭建ESP8266的编译环境,使用的模块是ESP8266-NodeMcu,其板载模组为ESP12E,flash大小为32Mbit,图片如下:
在这里插入图片描述

安信可官方的模组介绍为:https://docs.ai-thinker.com/esp8266
国内开源地址为:https://gitee.com/EspressifSystems/ESP8266_RTOS_SDK.git
Ubuntu虚拟机的安装参考:虚拟机VMware和Ubuntu18.04的安装
Ubuntu文件传输设置参考:Ubuntu下的各种文件传输设置
另外开发环境的搭建也可以参照这个大佬的博客:https://xuhong.blog.csdn.net/article/details/104736261
乐鑫官方的参考链接为:https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/index.html

二、工具链的安装

我们需要在Ubuntu18上安装一些软件包依赖,使用如下命令即可

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

然后下载交叉编译工具链:
64位Linux:https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
32位Linux:https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-i686.tar.gz
我们可以直接使用wget工具

wget https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz

下载好后解压

tar -xzf xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz

然后将xtensa-lx106-elf/bin目录导出到环境变量中,在.bashrc添加如下一行即可

export PATH=$PATH:/home/william/esp/esp8266/tools/xtensa-lx106-elf/bin

然后使之生效

source ~/.bashrc

接着运行xtensa-lx106-elf-gcc -v命令查看一下版本号
在这里插入图片描述

三、源码SDK包的下载和编译

乐鑫的源码是放在github上的,因为是国外的网站,所以拉去经常会失败,最近我发现在国内的gitee平台上也存放了代码,所以拉取gitee上的代码,这里我们拉取v3.4版本的SDK包。其中需要注意的一点是,在git拉取代码的时候,不要加sudo,因为加了sudo后以后编译都要管理员权限

git clone -b v3.4-rc https://gitee.com/EspressifSystems/ESP8266_RTOS_SDK.git

然后将.gitmodules文件修改为如下所示

[submodule "components/json/cJSON"]
        path = components/json/cJSON
        url = ../../william_william/cJSON.git

[submodule "components/mbedtls/mbedtls"]
        path = components/mbedtls/mbedtls
        url = ../../william_william/mbedtls.git

[submodule "components/lwip/lwip"]
        path = components/lwip/lwip
        url = ../../william_william/esp-lwip.git

[submodule "components/mqtt/esp-mqtt"]
        path = components/mqtt/esp-mqtt
        url = ../../william_william/esp-mqtt.git

[submodule "components/coap/libcoap"]
        path = components/coap/libcoap
        url = ../../william_william/libcoap.git

然后使用如下命令更新子模块

 git submodule update --init --recursive

接着需要安装需要使用的一下python包,先导出IDF_PATH环境变量

export IDF_PATH=/home/william/esp/esp8266/ESP8266_RTOS_SDK

然后使用如下命令安装Python包

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

建议使用国内源的python包

python -m pip install --user -r $IDF_PATH/requirements.txt -i https://pypi.douban.com/simple

如果安装失败,建议更新pip版本

pip install --upgrade pip

安装完后进入ESP8266_RTOS_SDK/examples/get-started/hello_world目录,执行make menuconfig
在这里插入图片描述

可以保持默认配置,按【s】会Save,然后回车,按【Esc】或【q】退出即可,然后使用make all编译,可以使用多线程编译,比如我8线程的电脑使用make all -j8编译,编译成功如下
在这里插入图片描述

四、烧录程序到开发板

我们需要将当前用户增加至 dialout 组,使用命令格式为sudo usermod -aG dialout 用户名,如下所示

sudo usermod -aG dialout william

然后重启系统

通过dmesg | grep ttyS*命令查看串口

dmesg | grep ttyS*

然后烧录

make flash

或者指定端口

make flash ESPPORT=/dev/ttyUSB0

等到出现Connecting.......按住开发板上的BOOT按键
在这里插入图片描述
下载成功
在这里插入图片描述
然后使用make monitor命令查看串口输出

make monitor

可以看到,Hello world!已经打印出来了,大功告成
在这里插入图片描述

五、使用VSCode开发项目

VSCode的下载参考:Visual Studio Code的安装和使用
VSCode远程开发参考:在Win10上使用SSH远程连接Linux搭建VSCode开发环境

esp8266下新建文件夹MyProject,把ESP8266_RTOS_SDK里面的\examples\get-started的整个文件夹hello_world拷贝到MyProject里面;
在这里插入图片描述
在VSCode下打开MyProject/hello_world下的Makefile,修改为如下所示

#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := hello-world

IDF_PATH=/home/william/esp/esp8266/ESP8266_RTOS_SDK

include $(IDF_PATH)/make/project.mk

然后打开MyProject/hello_world下的,将app_mian()修改为:

void app_main()
{
    printf("Hello world!\n");

    /* Print chip information */
    esp_chip_info_t chip_info;
    esp_chip_info(&chip_info);
    printf("This is ESP8266 chip with %d CPU cores, WiFi, ",
            chip_info.cores);

    printf("silicon revision %d, ", chip_info.revision);

    printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
            (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

    while (1) 
    {
        printf("Hello world!\n");
        printf("SDK version:%s\n", esp_get_idf_version());  
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

接下来在终端中执行make all,编译成功
在这里插入图片描述

然后使用make flash下载:
在这里插入图片描述

然后可以用make monitor命令监听串口
在这里插入图片描述

六、发送到Windows下载

将build文件夹下的bootloader/bootloader.binhello-world.binpartitions_singleapp.bin文件复制到windows下
在这里插入图片描述
下载安信可烧录工具
在这里插入图片描述
然后按如下设置进行下载
在这里插入图片描述
下载完成后可以在串口助手看到成功打印输出
在这里插入图片描述

七、通过samba服务器在Windows下载

samba服务器搭建参考:使用samba服务器在windows下访问linux的文件
然后同样的通过安信可烧录工具下载
在这里插入图片描述

八、附录

下一篇:ESP8266 RTOS开发之路(3)— 点亮第一个LED灯及按键输入

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值