7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ESP-IDF の環境をWindows10につくる

Last updated at Posted at 2017-06-11

ESP32-WROOM-32 ?

技適取得済みのWiFiとBLEが載ってるSoCを乗せた開発キットが1480円という、
ESP32-DevKitC ESP-WROOM-32開発ボード
というなんだか信じられない製品、を使うための環境をWindowsでせってアップしました。

ESP-IDF環境セットアップ

ESP-WROOM32は、ArduinoIDEからも使えるのですが、BLE周りはまだ対応していないようなので、本記事は、開発元が提供している環境であるESP-IDFをセットアップする内容になります。

基本的には、Get Started に従って実行すればできるはずと思って、作業したのですが、なぜかはまったのでその辺を中心に書きます。

ToolChainのダウンロード

zipを展開して、"C:\msys32" とかに置きます。
"C:\msys32\msys2_shell.cmd" をダブルクリック。
gitでESD-IDF環境を取得。

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

早速、サンプルのhello_worldをビルドしてみましょう。そのまえに、gitで取得した
esp-idfへのパスと通しましょう。~/.bashrcに下記を追加します。

export IDF_PATH="C:/msys32/home/shin/work/esp/esp-idf"

設定の更新。

$source ~/.bashrc

では、改めてhello_worldをビルド。

$ cd ~/esp
$ cp -r $IDF_PATH/examples/get-started/hello_world .
$ make menuconfig
$ make

make失敗。pythonがインストールされていないと怒られる。

...中略
AR libmain.a
LD bootloader.elf
/bin/sh: python: コマンドが見つかりません
make[1]: *** [/home/shin/work/esp/esp-idf/components/esptool_py/Makefile.projbuild:49: /home/shin/work/esp/hello_world/build/bootloader/bootloader.bin] エラー 127
make: *** [/home/shin/work/esp/esp-idf/components/bootloader/Makefile.projbuild:31: /home/shin/work/esp/hello_world/build/bootloader/bootloader.bin] エラー 2

pythonインストール

$ which python
which: no python in (/usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/opt/xtensa-esp32-elf/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)

確かにインストールされていないので、python2をインストールする。pacman はパッケージマネージャらしい。

$ pacman -S python2
$ which python2
/usr/bin/python2

コマンド名が python2 で気持ち悪いのでシンボリックリンクを貼っておく。

$ ln -s /usr/bin/python2 /usr/bin/python

再度、make。

$ make
Traceback (most recent call last):
  File "/home/shin/work/esp/esp-idf/components/esptool_py/esptool/esptool.py", line 25, in <module>
    import serial
ImportError: No module named serial
make[1]: *** [/home/shin/work/esp/esp-idf/components/esptool_py/Makefile.projbuild:49: /home/shin/work/esp/hello_world/build/bootloader/bootloader.bin] エラー 1
make: *** [/home/shin/work/esp/esp-idf/components/bootloader/Makefile.projbuild:31: /home/shin/work/esp/hello_world/build/bootloader/bootloader.bin] エラー 2

今度は、pythonのシリアル通信ライブラリ serial がないと怒られる。
python のパッケージツール pipを先にインストールしてから、
pip で pyserial をインストールする。

ESP32 Windows Setup Guide - Correction #200

$ wget https://bootstrap.pypa.io/get-pip.py
$ pip install pyserial

再度、make。通った。

$ make
...中略
To flash all build output, run 'make flash' or:
python /home/shin/work/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 /home/shin/work/esp/hello_world/build/bootloader/bootloader.bin 0x10000 /home/shin/work/esp/hello_world/build/hello-world.bin 0x8000 /home/shin/work/esp/hello_world/build/partitions_singleapp.bin

書き込み先のシリアルポート設定

make flash(ESP-WROOM-32のflashへの書き込み)。失敗。

$ make flash
Flashing binaries to serial port /dev/ttyUSB0 (app at offset 0x10000)...
esptool.py v2.0-beta3
Traceback (most recent call last):
  File "/home/shin/work/esp/esp-idf/components/esptool_py/esptool/esptool.py", l               ine 2349, in <module>
    _main()
  File "/home/shin/work/esp/esp-idf/components/esptool_py/esptool/esptool.py", l               ine 2342, in _main
    main()
  File "/home/shin/work/esp/esp-idf/components/esptool_py/esptool/esptool.py", l               ine 2072, in main
    esp = chip_class(args.port, initial_baud)
  File "/home/shin/work/esp/esp-idf/components/esptool_py/esptool/esptool.py", l               ine 166, in __init__
    self._port = serial.serial_for_url(port)
  File "/usr/lib/python2.7/site-packages/serial/__init__.py", line 88, in serial               _for_url
    instance.open()
  File "/usr/lib/python2.7/site-packages/serial/serialposix.py", line 268, in op               en
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._p               ort, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyUSB0: [               Errno 2] No such file or directory: '/dev/ttyUSB0'
make: *** [/home/shin/work/esp/esp-idf/components/esptool_py/Makefile.projbuild:               53: flash] エラー 1

シリアルポートの設定が正しくないので修正する。
(Establish Serial Connection with ESP32 に書いてありそうで書いていない?)

ESP-WROOM-32の接続先をデバイスマネージャーで確認。自分の場合はCOM3でした。
よくわからなければ、ESP-WROOM-32からUSBケーブルを抜き差しして変化があるデバイスです。
image.png

make menuconfig でシリアルポートの設定を行います。
デバイスマネージャーで確認したポートが"COM3"なら、"/dev/ttyS2" を設定します。"ttyS3"ではなく, "ttyS2"です。

$ make menuconfig

Serial flasher config ---> (/dev/ttyUSB0) Default serial port
image.png
認識されているシリアルポートは下記でも確認できます。

$ ls /dev/tty*
/dev/tty  /dev/ttyS0  /dev/ttyS13  /dev/ttyS2  /dev/ttyS7

フラッシュに焼く

flashに焼けました。

$ make flash
...中略
LD hello-world.elf
esptool.py v2.0-beta3
Flashing binaries to serial port /dev/ttyS2 (app at offset 0x10000)...
esptool.py v2.0-beta3
Connecting........_
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0220
Compressed 15792 bytes to 9198...
Wrote 15792 bytes (9198 compressed) at 0x00001000 in 0.8 seconds (effective 152.9 kbit/s)...
Hash of data verified.
Compressed 355216 bytes to 167647...
Wrote 355216 bytes (167647 compressed) at 0x00010000 in 14.9 seconds (effective 190.8 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 82...
Wrote 3072 bytes (82 compressed) at 0x00008000 in 0.0 seconds (effective 1486.4 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting...

Hello world!

PuTTyなどのシリアルコンソールをつないでみてみましょう。
Hello world!

image.png

7
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?