ESP8266 MAC(OSX)开发环境搭建

ESP8266 MAC(OSX)开发环境搭建

资料

ESP8266官网
NodeMcu官网
ESP8266 linux环境编译工具链
ESP8266开源编译工具链源码
OSX搭建ESP8266开发环境
OSX搭建ESP8266开发环境2

安装MAC编译工具链

  1. 安装brew
  2. 安装命令行工具前安装最新版本Xcode(>=8.3)
  3. 安装相关工具
$ brew tap homebrew/dupes
$ brew install binutils coreutils automake wget gawk libtool help2man gperf gnu-sed --with-default-names grep
$ export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
  1. 安装MacPort下载地址与gsed
export PATH=/opt/local/bin:$PATH
export PATH=/opt/local/sbin:$PATH
sudo port -v selfupdate
port install gsed
  1. 创建大小写敏感的文件系统,MAC默认文件名不区分大小写
$ sudo hdiutil create ~/Development/esp-open-sdk.dmg -volname "esp-open-sdk" -size 5g -fs "Case-sensitive HFS+"
$ sudo hdiutil mount ~/Development/esp-open-sdk.dmg
$ cd /Volumes/esp-open-sdk
  1. 下载esp-open-sdk编译工具源码
git clone https://github.com/pfalcon/esp-open-sdk.git --recursive
  1. Linux切Mac的一些修改
    (==注意这里用的sed命令是Mac下的,不是gsed,如果执行失败把sed替换成/usr/bin/sed==)
cd esp-open-sdk
sed -i.bak '1s/^/gettext=\'$'\n/' crosstool-NG/kconfig/Makefile
sed -i.bak -e 's/[[:<:]]sed[[:>:]]/gsed/' Makefile
sed -i.bak -e 's/[[:<:]]awk[[:>:]]/\$(AWK)/' lx106-hal/src/Makefile.am
sed -i.bak 's/AM_PROG_AS/AM_PROG_AS\'$'\nAM_PROG_AR/' lx106-hal/configure.ac
  1. 开始编译
make STANDALONE=n

==编译出错1:==

./ct-ng build
[INFO ]  Performing some trivial sanity checks
[INFO ]  Build started 20170408.174558
[INFO ]  Building environment variables
[INFO ]  =================================================================
[INFO ]  Retrieving needed toolchain components' tarballs
[ERROR]   
[ERROR]  >>
[ERROR]  >>  Build failed in step 'Retrieving needed toolchain components' tarballs'
[ERROR]  >>        called in step '(top-level)'
[ERROR]  >>
[ERROR]  >>  Error happened in: do_libc_get[scripts/build/libc/newlib.sh@12]
[ERROR]  >>        called from: main[scripts/crosstool-NG.sh@594]
[ERROR]  >>
[ERROR]  >>  For more info on this error, look at the file: 'build.log'
[ERROR]  >>  There is a list of known issues, some with workarounds, in:
[ERROR]  >>      'share/doc/crosstool-ng/crosstool-ng-1.22.0-60-g37b07f6f-dirty/B - Known issues.txt'
[ERROR]   
[ERROR]  (elapsed: 5:08.00)
[05:10] / make[2]: *** [build] Error 1
make[1]: *** [_toolchain] Error 2
make: *** [/Volumes/esp-open-sdk/esp-open-sdk/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc] Error 2

分析/Volumes/esp-open-sdk/esp-open-sdk/crosstool-NG/build.log定位源码newlib.sh 12行,原因为下载失败

do_libc_get() {
    local libc_src="{http://mirrors.kernel.org/sourceware/newlib,
                     ftp://sourceware.org/pub/newlib}"

    if [ "${CT_LIBC_NEWLIB_CUSTOM}" = "y" ]; then
        CT_GetCustom "newlib" "${CT_LIBC_VERSION}"      \
                     "${CT_LIBC_NEWLIB_CUSTOM_LOCATION}"
    else # ! custom location
        if echo ${CT_LIBC_VERSION} |${grep} -q linaro; then
            YYMM=`echo ${CT_LIBC_VERSION} |cut -d- -f3 |${sed} -e 's,^..,,'`
            CT_GetFile "newlib-${CT_LIBC_VERSION}" ${libc_src} \
                       https://releases.linaro.org/${YYMM}/components/toolchain/newlib-linaro \
                       http://cbuild.validation.linaro.org/snapshots
        else
            CT_GetFile "newlib-${CT_LIBC_VERSION}" ${libc_src} \
                       http://mirrors.kernel.org/sources.redhat.com/newlib
        fi
    fi # ! custom location
}

解决方法:去http://mirrors.kernel.org/sourceware/newlib手动下载newlib-2.0.0.tar.gz,放至 /Volumes/esp-open-sdk/esp-open-sdk/crosstool-NG/.build/tarballs目录,再重新执行编译

  1. 将生成的交叉编译工具xtensa-lx106-elf加到环境变量
vim $HOME/.bash_profile
export PATH=$PATH:/esptools/esp-open-sdk/xtensa-lx106-elf/bin
source $HOME/.bash_profile

编译

  1. 进入esp8266代码目录,执行下面命令开始编译
make COMPILE=gcc

烧录

安装usb转串口驱动(比如PL2303)

  1. 下载驱动
  2. 安装
  3. 安装完成,重启电脑之后我们在“网络偏好设置”中,发现多了一项USB-SerialController
  4. 终端执行下面命令查看,tty.usbserial就是我们的设备
192:dev shenhaibo$ cd /dev
192:dev shenhaibo$ ll tty.*
crw-rw-rw-  1 root  wheel   20,   0  4  9 11:02 tty.Bluetooth-Incoming-Port
crw-rw-rw-  1 root  wheel   20,   2  4  9 11:04 tty.usbserial

固件下载工具配置

  1. 下载源码
git clone https://github.com/themadinventor/esptool.git
  1. 配置环境变量
vim $HOME/.bash_profile
export PATH=$PATH:/Users/shenhaibo/Development/ESP6288/esptool
source $HOME/.bash_profile
  1. 安装PySerial下载地址
tar xfvz pyserial-2.7.tar.gz
cd pyserial-2.7
sudo python setup.py install

固件下载工具使用

  1. 擦除芯片
sudo esptool.py --port /dev/tty.usbserial erase_flash
  1. 下载固件
sudo esptool.py --port /dev/tty.usbserial write_flash -fm dio -fs 32m -ff 40m 0x00000 ~/Desktop/nodemcu_float_0.9.6-dev_20150704.bin

烧录说明

==Gokit3.0 ESP8266是:Flash size 32Mbit-C1: 1024KB+1024KB==

***********************BOOT MODE***********************
download:
Flash size 8Mbit: 512KB+512KB
boot_v1.2+.bin          0x00000
user1.1024.new.2.bin    0x01000
esp_init_data_default.bin   0xfc000 (optional)
blank.bin               0x7e000 & 0xfe000

Flash size 16Mbit: 512KB+512KB
boot_v1.2+.bin          0x00000
user1.1024.new.2.bin    0x01000
esp_init_data_default.bin   0x1fc000 (optional)
blank.bin               0x7e000 & 0x1fe000

Flash size 16Mbit-C1: 1024KB+1024KB
boot_v1.2+.bin          0x00000
user1.2048.new.5.bin    0x01000
esp_init_data_default.bin   0x1fc000 (optional)
blank.bin               0xfe000 & 0x1fe000

Flash size 32Mbit: 512KB+512KB
boot_v1.2+.bin          0x00000
user1.1024.new.2.bin    0x01000
esp_init_data_default.bin   0x3fc000 (optional)
blank.bin               0x7e000 & 0x3fe000

Flash size 32Mbit-C1: 1024KB+1024KB
boot_v1.2+.bin          0x00000
user1.2048.new.5.bin    0x01000
esp_init_data_default.bin   0x3fc000 (optional)
blank.bin               0xfe000 & 0x3fe000

***********************NON-BOOT MODE***********************
download
eagle.flash.bin     0x00000
eagle.irom0text.bin 0x40000
blank.bin
    Flash size 4Mbit:       not supported
    Flash size 8Mbit:   0x7e000 & 0xfe000
    Flash size 16Mbit:      0x7e000 & 0x1fe000
    Flash size 16Mbit-C1:   0xfe000 & 0x1fe000
    Flash size 32Mbit:      0x7e000 & 0x3fe000
    Flash size 32Mbit-C1:   0xfe000 & 0x3fe000
esp_init_data_default.bin    (optional) 
        Flash size 8Mbit:   0xfc000
    Flash size 16Mbit:      0x1fc000
    Flash size 16Mbit-C1:   0x1fc000
    Flash size 32Mbit:      0x3fc000
    Flash size 32Mbit-C1:   0x3fc000

*NOTICE*:
UPDATE is not supported in non-boot mode

***********************************************************

Update steps
1.Make sure TE(terminal equipment) is in sta or sta+ap mode
ex. AT+CWMODE=3
    OK

2.Make sure TE got ip address
ex. AT+CWJAP="ssid","12345678"
    OK

    AT+CIFSR
    192.168.1.134

3.Let's update
ex. AT+CIUPDATE
    +CIPUPDATE:1    found server
    +CIPUPDATE:2    connect server
    +CIPUPDATE:3    got edition
    +CIPUPDATE:4    start start

    OK

note. If there are mistakes in the updating, then break update and print ERROR.

烧录示例

==如:gokit3_SoC_ESP8266_03000003_2016120711项目==

sudo esptool.py --port /dev/tty.usbserial write_flash -fm dio -fs 32m -ff 40m 0x00000 boot_v1.6.bin 
sudo esptool.py --port /dev/tty.usbserial write_flash -fm dio -fs 32m -ff 40m 0x01000 gokit3_SoC_ESP8266_03000003_2016120711
.bin 
sudo esptool.py --port /dev/tty.usbserial write_flash -fm dio -fs 32m -ff 40m 0x3fc000 esp_init_data_default.bin 
sudo esptool.py --port /dev/tty.usbserial write_flash -fm dio -fs 32m -ff 40m 0x3fe000 blank.bin 

你可能感兴趣的:(物联网)