急行はまなす 青森行き

札幌駅22:00発 増結12両編成

ESP32を始めてみる dockerでESP-IDF編

わーい!ESP32ってたのしー

 

Arduino IDEではなくメーカー提供のESP-IDFで開発してみたいと思います。

が手順*1を見るとツールのセットアップ等めんどくさいですよねー

 

なんか簡単にできないかなとdockerhubを検索してみるとあるじゃないですか。

ほーいいじゃないか、こういうのでいいんだよ、こういうので。

 

https://hub.docker.com/r/vowstar/esp8266/

 

どうやらESP32とESP8266どっちもいけるようですね。

すっごーい!

 

でイメージを落とします。

なお以降の手順はubuntu 16.04、Docker version 1.10.3, build 20f81ddで行いました。

 # docker pull vowstar/esp8266

 

使い方は↑のイメージのURLのUsageをそのままをなぞっていきます。

開発はコンテナ内ではなくホスト側で行うのでESP-IDFとテンプレートを持ってきます。

作業フォルダを作りそのなかにESP-IDFとテンプレ(Lチカ)を配置します。

 # mkdir idf

 # cd idf

 

 ESP-IDFを取得します。

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

 # cd esp-idf/

 # git submodule update --init

 

テンプレ(Lチカ)を取得してmyapp内のmain.cのピン番号を適当なのに変えます。

 

ESP32をFlashモードで起動させPCにつなぎコンテナを作業フォルダで起動します。

-v オプションでコンテナが起動すると/buildにホスト側の作業フォルダがマウントされます。

# docker run -it --name ESP32 -e IDF_PATH=/build/esp-idf --device /dev/ttyUSB0:dev/ttyUSB0 -v `pwd`:/build vowstar/esp8266 /bin/bash

 

コンテナに入ります。

root@672a8f22f3a6:/# cd build/
root@672a8f22f3a6:/build# ls
esp-idf  myapp
root@672a8f22f3a6:/build# cd myapp/
root@672a8f22f3a6:/build/myapp# ls
LICENSE  Makefile  README.rst  main  sdkconfig
root@672a8f22f3a6:/build/myapp# make menuconfig

 

f:id:ken5owata:20170216025123p:plain

 

初回なのでとくにconfigはいじらずmake→make flashでESP32にプログラムを書き込めました。

リセットするとLEDが点滅しLチカプログラムが実行します。

 

こうしてdockerを使うことで公式のセットアップ手順のStep0とStep1をすっ飛ばすことができました。

いやーありがたや、ありがたや。

 

しかしCompilerとToolchainのVersionでWARNINGが出ているようですね。

Dockerfileで取得してるのが古いのかな?、なので公式のセットアップ手順のVerに置き換えればよいでしょう。

dockerってすっごーい!

 

さーて他のテンプレも動かしてみっぺかー

 

※ makeとmake flashを貼り付けときます。

root@672a8f22f3a6:/build/myapp# make
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/components/coap/libcoap
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/components/esp32/lib
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/components/micro-ecc/micro-ecc
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/components/esptool_py/esptool
WARNING: Toolchain version is not supported: crosstool-NG 8d95cad
Expected to see version: crosstool-NG crosstool-ng-1.22.0-61-gab8375a
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
WARNING: Compiler version is not supported: 4.8.5
Expected to see version(s): 5.2.0
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
GENCONFIG
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/components/coap/libcoap
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/components/esp32/lib
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/components/micro-ecc/micro-ecc
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/components/esptool_py/esptool
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/components/micro-ecc/micro-ecc
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/components/esptool_py/esptool
WARNING: Toolchain version is not supported: crosstool-NG 8d95cad
Expected to see version: crosstool-NG crosstool-ng-1.22.0-61-gab8375a
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
WARNING: Compiler version is not supported: 4.8.5
Expected to see version(s): 5.2.0
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
CC src/bootloader_flash.o
CC src/secure_boot_signatures.o
CC src/secure_boot.o
CC src/flash_partitions.o
CC src/esp_image_format.o
CC src/flash_encrypt.o
CC src/bootloader_random.o
AR libbootloader_support.a
CC log.o
AR liblog.a
CC bootloader_start.o
AR libmain.a
LD bootloader.elf
esptool.py v2.0-beta1
Building partitions from /build/esp-idf/components/partition_table/partitions_singleapp.csv...
CC esp_ota_ops.o
AR libapp_update.a
CC src/bootloader_flash.o
CC src/secure_boot_signatures.o
CC src/secure_boot.o
CC src/flash_partitions.o
CC src/esp_image_format.o
CC src/flash_encrypt.o
CC src/bootloader_random.o
AR libbootloader_support.a
CC bt.o
AR libbt.a
CC libcoap/src/address.o
CC libcoap/src/async.o
CC libcoap/src/block.o
CC libcoap/src/coap_time.o
CC libcoap/src/debug.o
CC libcoap/src/encode.o
CC libcoap/src/mem.o
CC libcoap/src/net.o
CC libcoap/src/option.o
CC libcoap/src/pdu.o
CC libcoap/src/resource.o
CC libcoap/src/str.o
CC libcoap/src/subscribe.o
CC libcoap/src/uri.o
CC port/coap_io_socket.o
AR libcoap.a
CXX cxx_guards.o
AR libcxx.a
CC spi_master.o
CC sigmadelta.o
CC uart.o
CC i2c.o
CC periph_ctrl.o
CC ledc.o
CC gpio.o
CC pcnt.o
CC rmt.o
CC sdmmc_transaction.o
CC timer.o
CC sdmmc_host.o
CC i2s.o
CC rtc_module.o
AR libdriver.a
CC panic.o
CC event_default_handlers.o
CC task_wdt.o
CC system_api.o
CC lib_printf.o
CC cpu_util.o
CC int_wdt.o
CC phy_init.o
CC deep_sleep.o
CC cpu_start.o
CC heap_alloc_caps.o
CC crosscore_int.o
CC ipc.o
CC intr_alloc.o
CC core_dump.o
CC event_loop.o
CC cpu_freq.o
CC hw_random.o
CC brownout.o
AR libesp32.a
CC emac_dev.o
CC emac_main.o
AR libethernet.a
CC src/option/syscall.o
CC src/option/unicode.o
CC src/ff.o
CC src/vfs_fat_sdmmc.o
CC src/vfs_fat.o
CC src/diskio.o
AR libfatfs.a
CC ringbuf.o
CC heap_regions_debug.o
CC xtensa_intr.o
CC queue.o
CC croutine.o
CC list.o
CC xtensa_init.o
CC port.o
CC heap_regions.o
CC event_groups.o
CC tasks.o
CC timers.o
CC FreeRTOS-openocd.o
CC xtensa_overlay_os_hook.o
AS xtensa_context.o
AS portasm.o
AS xtensa_vectors.o
AS xtensa_intr_asm.o
AR libfreertos.a
CC log.o
AR liblog.a
CC api/pppapi.o
CC api/netbuf.o
CC api/api_lib.o
CC api/netifapi.o
CC api/tcpip.o
CC api/netdb.o
CC api/err.o
CC api/api_msg.o
CC api/sockets.o
CC api/lwip_debug.o
CC apps/sntp/sntp.o
CC apps/ping/ping.o
CC apps/ping/esp_ping.o
CC apps/dhcpserver.o
CC core/ipv4/ip_frag.o
CC core/ipv4/dhcp.o
CC core/ipv4/ip4_addr.o
CC core/ipv4/igmp.o
CC core/ipv4/ip4.o
CC core/ipv4/autoip.o
CC core/ipv4/icmp.o
CC core/ipv6/ip6_frag.o
CC core/ipv6/dhcp6.o
CC core/ipv6/inet6.o
CC core/ipv6/ip6_addr.o
CC core/ipv6/ip6.o
CC core/ipv6/nd6.o
CC core/ipv6/mld6.o
CC core/ipv6/ethip6.o
CC core/ipv6/icmp6.o
CC core/mem.o
CC core/inet_chksum.o
CC core/init.o
CC core/memp.o
CC core/sys.o
CC core/tcp.o
CC core/dns.o
CC core/ip.o
CC core/raw.o
CC core/tcp_in.o
CC core/pbuf.o
CC core/netif.o
CC core/stats.o
CC core/timers.o
CC core/def.o
CC core/udp.o
CC core/tcp_out.o
CC netif/slipif.o
CC netif/etharp.o
CC netif/ethernet.o
CC netif/lowpan6.o
CC netif/ethernetif.o
CC port/freertos/sys_arch.o
CC port/netif/wlanif.o
CC port/netif/ethernetif.o
AR liblwip.a
CC library/entropy.o
CC library/md4.o
CC library/pkcs12.o
CC library/ccm.o
CC library/sha1.o
CC library/x509_csr.o
CC library/ssl_cli.o
CC library/camellia.o
CC library/blowfish.o
CC library/x509.o
CC library/ssl_ticket.o
CC library/ecp_curves.o
CC library/cipher.o
CC library/error.o
CC library/pem.o
CC library/entropy_poll.o
CC library/x509write_csr.o
CC library/version_features.o
CC library/ripemd160.o
CC library/rsa.o
CC library/md.o
CC library/md_wrap.o
CC library/sha256.o
CC library/dhm.o
CC library/pkwrite.o
CC library/base64.o
CC library/timing.o
CC library/asn1parse.o
CC library/ssl_tls.o
CC library/version.o
CC library/memory_buffer_alloc.o
CC library/cipher_wrap.o
CC library/md2.o
CC library/ssl_cache.o
CC library/ssl_srv.o
CC library/x509_crt.o
CC library/ecdh.o
CC library/asn1write.o
CC library/net.o
CC library/debug.o
CC library/x509_create.o
CC library/ecjpake.o
CC library/oid.o
CC library/md5.o
CC library/ecdsa.o
CC library/pkcs11.o
CC library/sha512.o
CC library/xtea.o
CC library/ecp.o
CC library/aes.o
CC library/x509write_crt.o
CC library/arc4.o
CC library/bignum.o
CC library/pkparse.o
CC library/padlock.o
CC library/threading.o
CC library/x509_crl.o
CC library/gcm.o
CC library/havege.o
CC library/ssl_ciphersuites.o
CC library/certs.o
CC library/pkcs5.o
CC library/ssl_cookie.o
CC library/aesni.o
CC library/hmac_drbg.o
CC library/des.o
CC library/pk.o
CC library/platform.o
CC library/ctr_drbg.o
CC library/pk_wrap.o
CC port/esp_sha1.o
CC port/net.o
CC port/esp_sha256.o
CC port/esp_bignum.o
CC port/esp_hardware.o
CC port/esp_sha512.o
AR libmbedtls.a
CC mdns.o
AR libmdns.a
CC time.o
CC syscalls.o
CC syscall_table.o
CC locks.o
AR libnewlib.a
CXX src/nvs_page.o
CXX src/nvs_pagemanager.o
CXX src/nvs_storage.o
CXX src/nvs_api.o
AR libnvs_flash.a
CC library/ssl_cert.o
CC library/ssl_methods.o
CC library/ssl_pkey.o
CC library/ssl_x509.o
CC library/ssl_lib.o
CC library/ssl_stack.o
CC platform/ssl_pm.o
CC platform/ssl_port.o
AR libopenssl.a
CC sdmmc_cmd.o
AR libsdmmc.a
CC flash_mmap.o
CC partition.o
CC cache_utils.o
CC flash_ops.o
AR libspi_flash.a
CC tcpip_adapter_lwip.o
AR libtcpip_adapter.a
CC ulp.o
AR libulp.a
CC vfs_uart.o
CC vfs.o
AR libvfs.a
CC src/crypto/aes-internal-enc.o
CC src/crypto/sha256-internal.o
CC src/crypto/md5-internal.o
CC src/crypto/aes-internal.o
CC src/crypto/sha1.o
CC src/crypto/aes-internal-dec.o
CC src/crypto/crypto_internal.o
CC src/crypto/aes-unwrap.o
CC src/crypto/crypto_internal-rsa.o
CC src/crypto/des-internal.o
CC src/crypto/dh_group5.o
CC src/crypto/ms_funcs.o
CC src/crypto/aes-wrap.o
CC src/crypto/sha1-internal.o
CC src/crypto/md4-internal.o
CC src/crypto/dh_groups.o
CC src/crypto/sha256.o
CC src/crypto/rc4.o
CC src/crypto/md5.o
CC src/crypto/aes-cbc.o
CC src/crypto/sha1-pbkdf2.o
CC src/crypto/bignum.o
CC src/crypto/crypto_internal-modexp.o
CC src/crypto/crypto_internal-cipher.o
CC port/os_xtensa.o
AR libwpa_supplicant.a
CC trax.o
AR libxtensa-debug-module.a
CC main.o
AR libmain.a
LD app-template.elf
esptool.py v2.0-beta1
To flash all build output, run 'make flash' or:
python /build/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -u --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 /build/myapp/build/bootloader/bootloader.bin 0x10000 /build/myapp/build/app-template.bin 0x8000 /build/myapp/build/partitions_singleapp.bin
root@672a8f22f3a6:/build/myapp#
root@672a8f22f3a6:/build/myapp# make flash
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/c
omponents/coap/libcoap
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/$
omponents/esp32/lib
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/$
omponents/micro-ecc/micro-ecc
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/$
omponents/esptool_py/esptool
WARNING: Toolchain version is not supported: crosstool-NG 8d95cad
Expected to see version: crosstool-NG crosstool-ng-1.22.0-61-gab8375a
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
WARNING: Compiler version is not supported: 4.8.5
Expected to see version(s): 5.2.0
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/$
omponents/micro-ecc/micro-ecc
fatal: Not a git repository: /home/hoge/デスクトップ/work/sketch/ESP32/idf/esp-idf/.git/modules/$
omponents/esptool_py/esptool
WARNING: Toolchain version is not supported: crosstool-NG 8d95cad
Expected to see version: crosstool-NG crosstool-ng-1.22.0-61-gab8375a
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
WARNING: Compiler version is not supported: 4.8.5
Expected to see version(s): 5.2.0
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
Flashing binaries to serial port /dev/ttyUSB0 (app at offset 0x10000)...
esptool.py v2.0-beta1
Connecting..........
Uploading stub...
Running stub...
Stub running...
Attaching SPI flash...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0220
Wrote 16384 bytes at 0x00001000 in 1.5 seconds (90.3 kbit/s)...
Hash of data verified.
Wrote 491520 bytes at 0x00010000 in 43.4 seconds (90.6 kbit/s)...
Hash of data verified.
Wrote 16384 bytes at 0x00008000 in 1.4 seconds (91.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting...
root@672a8f22f3a6:/build/myapp#