ESP8266开发板相关开源项目使用介绍
这里介绍的esp8266是使用了ESP-12E型号的NodeMCU开发板;
该模组采用的是容量为4MB, 封装为 SOP-210 mil 的 SPI Flash。
ESP8266EX 内置 Tensilica L106 超低功耗 32 位微型 MCU,带有 16 位精简模式,主频支持 80MHz 和 160 MHz,支持RTOS。目前 WiFi 协议栈只用了 20%的 MIPS,其他的都可以用来做应用开发。
NodeMCU开发板自带了两个LED,分别是ESP-12E自带的LED,以及在开发板上的LED,分别对应GPIO为2/16.
这里针对ESP8266的相关开源第三方源码编译和烧录使用固件做相关的介绍和说明。
特别的需要注意一点:NodeMCU-firmware源码编译固件,在烧录时需要在esptool.py的参数中加入:
“-fm dio -fs 32m -ff 40m”
否则会出现无法启动的情况,这里详细请看Makefile部分修改。
对源码编译烧录使用过程中发现烧录了noduino-sdk和AT固件后,没有添加使用特定参数烧录NodeMCU固件后出现了开发板GPIO2的LED一直处于快速闪烁状态,使用参数后正常启动,且从串口调试反馈参数看到:
Formatting file module or continue…
NodeMCU 1.5.4.1 build unspecified powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32)
lua: cannot open init.lua
本文中介绍的相关内容实际操作环境为Ubuntu-16.04
(一)NodeMCU
首先是开发板自带的NodeMCU固件,其源码的下载地址为:
https://github.com/nodemcu/nodemcu-firmware
当前的版本为1.5.4.1
在放置编译项目的文件下创建NodeMCU文件夹:
mkdir NodeMCU
之后使用git工具从源码地址下载源码:
git clone https://github.com/nodemcu/nodemcu-firmware.git
由于NodeMCU在编译时app/user下需要使用到ESP8266_RTOS_SDK中的xtensa 头文件,
fatal error: xtensa/corebits.h: No such file or directory
xtensa-toolchain/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: cannot find -lhal
collect2: error: ld returned 1 exit status
因此需要同步该代码:
git clone https://github.com/espressif/ESP8266_RTOS_SDK.git
同时,NodeMCU编译中会出现报错提示缺少文件libhal.a,这里通过以下命令:
wget -c https://github.com/esp8266/esp8266-wiki/raw/master/libs/libhal.a
mv libhal.a nodemcu-firmware/libhal.a
将该文件放置到NodeMCU的源码目录下面,接下来通过修改使用它。
修改Makefile文件(添加:cp libhal.a $(SDK_DIR)/lib/libhal.a)到下面的位置
$(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER): $(TOP_DIR)/cache/esp_iot_sdk_v$(SDK_FILE_VER).zip
mkdir -p "$(dir $@)"
(cd "$(dir $@)" && rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK && unzip $(TOP_DIR)/cache/esp_iot_sdk_v$(SDK_FILE_VER).zip ESP8266_NONOS_SDK/lib/* ESP8266_NONOS_SDK/ld/eagle.rom.addr.v6.ld ESP8266_NONOS_SDK/include/* )
mv $(dir $@)/ESP8266_NONOS_SDK $(dir $@)/esp_iot_sdk_v$(SDK_VER)
rm -f $(SDK_DIR)/lib/liblwip.a
cp libhal.a $(SDK_DIR)/lib/libhal.a
touch $@
注意:在官方的编译环境下生成的两个固件文件大小是通过ld/nodemcu.ld该文件下的参数自动生成的;
做个对比:
未修改的文件部分:
/* This linker script generated from xt-genldscripts.tpp for LSP . */
/* Linker Script for ld -N */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40210000, len = 0x80000
}
修改的部分
/* This linker script generated from xt-genldscripts.tpp for LSP . */
/* Linker Script for ld -N */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40240000, len = 0xC0000
}
这里的修改会导致最后的生成第二个文件产生差异,如果做了修改我们同时需要相应的修改
.travis.yml
- srec_cat -output ${file_name_float} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x40000 0x40000.bin -binary -offset 0x40000
- cd ../
- make clean
- make EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL -DBUILD_DATE='\"'$BUILD_DATE'\"'"
- cd bin/
- file_name_integer="nodemcu_integer_${TRAVIS_TAG}.bin"
- srec_cat -output ${file_name_integer} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x40000 0x40000.bin -binary -offset 0x40000
Makefile文件修改:
spiffs-image: bin/0x40000.bin
$(MAKE) -C tools
-----------------------
flash:
ifndef PDIR
$(MAKE) -C ./app flash
else
$(ESPTOOL) --port $(ESPPORT) write_flash -fm dio -fs 32m -ff 40m 0x00000 $(FIRMWAREDIR)0x00000.bin 0x40000 $(FIRMWAREDIR)0x40000.bin
endif
修改完成后,到源码目录下执行
make && make flash
注意:
这里如果没有对当前用户进行串口的用户组设置,会出现权限不足的提示;处理方法:
关于在Ubuntu下使用串口的root权限
执行命令
dmesg | tail
可以看到带有:“ to ttyUSB0”的字样
ls-l /dev/ttyUSB0 //这个0就是上面检测到的
看到如下
crw-rw----1 root dialout 188, 0 5 AUG ttyUSB0
这里的dialout用户组
可以使用以下命令将用户加入root用户组
sudo usermod -aG dialout username
再键入:
ls-ld /run/lock
或
ls-ld /var/lock
然后出现以下字样:
drwxrwxrwt5 root root 4096 9 dic 21.39 /var/lock
运行root下的
chmodo+rwx /run/lock
或
chmodo+rwx /var/lock
系统登出然后再登入,
运行与系统串口相关的应用即可正常使用了。
(二)noduino-sdk
源码地址:
https://github.com/icamgo/noduino-sdk
官方的简单操作方法:
clone the whole sdk
$ git clone --recursive git://github.com/icamgo/noduino-sdk.git noduino-sdk
generate the toolchain (you need Python 2.7)
$ cd noduino-sdk/toolchain
$ ./gen.py
try the first example
$ cd ../example/noduino/blink
upload the example to dev board through serial
$ make flash
(三)Arduino-ESP8266
关于在arduino上加入esp8266支持的方法,
官方社区提供的方法:
https://github.com/esp8266/Arduino
http://arduino.esp8266.com/stable/package_esp8266com_index.json
从Arduino官网下载ArduinoIDE,解压压缩包到用户目录,然后进入目录下
cd hardware
mkdir esp8266com
cd esp8266com
git clone git://github.com/icamgo/Noduino.git esp8266
cd esp8266
git submodule init
git submodule update
cd tools/xtensa-toolchain
./gen.py
之后使用install.sh安装arduino到dash栏或者桌面,
打开Arduino进入后在tool中找到esp项目,
使用对应的example测试代码编译工程烧录到开发板即可。
(四)espwebframework
这个开源第三方项目地址:
https://github.com/fdivitto/ESPWebFramework
本人对其做了一些修改,附带地址:
https://github.com/23171580/espwebframework
编译烧录方法:
Ubuntu-16.04 Build espwebframework
git clone https://github.com/23171580/espwebframework.git
cd espwebframework
./make.sh
set up esp8266 board into flash mode then,
sudo make flash
finally,reset esp8266 board.