since 2017-05-13
micropython で使った ESP 32 開発ボード。
$ cat setup.sh export PATH=$PATH:/home/nishimotz/esp/xtensa-esp32-elf/bin export IDF_PATH=/home/nishimotz/esp/mruby/esp-idf
$ cat picocom.sh echo Press Ctrl+A Ctrl+X to quit sudo picocom --baud 115200 /dev/ttyUSB0
http://dsas.blog.klab.org/archives/mruby-on-esp32
https://github.com/mruby-esp32/mruby-esp32
https://github.com/mruby-esp32/mruby-esp32-app-mirb
https://github.com/iij/mruby-pack
https://github.com/mruby-esp32/mruby-io → make できない
https://github.com/mruby-esp32/mruby-socket → increase stack size の説明あり 書いてある通りに 32768 にする
diff --git a/components/mruby/build_config.rb b/components/mruby/build_config.rb index 2c3d17c..1b65d34 100644 --- a/components/mruby/build_config.rb +++ b/components/mruby/build_config.rb @@ -77,5 +77,8 @@ MRuby::CrossBuild.new('esp32') do |conf| conf.gem :core => "mruby-compiler" conf.gem :core => "mruby-kernel-ext" conf.gem :core => "mruby-class-ext" + conf.gem :github => 'iij/mruby-pack' + conf.gem :path => "/home/nishimotz/esp/mruby/mruby-esp32/components/mruby_component/mruby-esp32-system" + conf.gem :path => "/home/nishimotz/esp/mruby/mruby-esp32/components/mruby_component/mruby-esp32-wifi" end diff --git a/main/main.c b/main/main.c index 86fbf3e..a27abbb 100644 --- a/main/main.c +++ b/main/main.c @@ -137,5 +137,5 @@ mirb_task(void *pvParameter) void app_main() { - xTaskCreate(&mirb_task, "mirb_task", 8192, NULL, 5, NULL); + xTaskCreate(&mirb_task, "mirb_task", 32768, NULL, 5, NULL); }
# スタックを増やす前 > ESP32::System.available_memory => 123928 # スタックを増やした後 > ESP32::System.available_memory => 41088
Terminal ready => nil > wifi = ESP32::WiFi.new => #<ESP32::WiFi:0x3ffe3dcc> > wifi.on_connected do |ip| puts "Connected #{ip}" end => #<ESP32::WiFi:0x3ffe3dcc @on_connected_blk=#<Proc:0x3ffe3de4@(mirb):3>> > wifi.on_disconnected do |ip| puts "Disconnected #{ip}" end => #<ESP32::WiFi:0x3ffe3dcc @on_connected_blk=#<Proc:0x3ffe3de4@(mirb):3>, @on_disconnected_blk=#<Proc:0x3ffe3db4@(mirb):4>> > wifi.connect('(acccess point name)', '(passphrase)') I (389995) wifi: wifi firmware version: 6c86a1c I (389995) wifi: config NVS flash: enabled I (389995) wifi: config nano formating: disabled I (389995) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE I (390005) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE I (390025) wifi: Init dynamic tx buffer num: 32 I (390025) wifi: Init dynamic rx buffer num: 64 I (390025) wifi: wifi driver task: 3ffed880, prio:23, stack:4096 I (390035) wifi: Init static rx buffer num: 10 I (390035) wifi: Init dynamic rx buffer num: 0 I (390035) wifi: Init rx ampdu len mblock:7 I (390045) wifi: Init lldesc rx ampdu entry mblock:4 I (390045) wifi: wifi power manager task: 0x3fff108c prio: 21 stack: 2560 I (390055) wifi: wifi timer task: 3fff11f4, prio:22, stack:3584 W (390065) phy_init: failed to load RF calibration data (0xffffffff), falling back to full calibration I (390275) phy: phy_version: 350, Mar 22 2017, 15:02:06, 0, 2 I (390275) wifi: mode : sta (**:**:**:**:**:**) => #<ESP32::WiFi:0x3ffe3dcc @on_connected_blk=#<Proc:0x3ffe3de4@(mirb):3>, @on_disconnected_blk=#<Proc:0x3ffe3db4@(mirb):4>> > I (391005) wifi: n:6 0, o:1 0, ap:255 255, sta:6 0, prof:1 I (391655) wifi: state: init -> auth (b0) I (391665) wifi: state: auth -> assoc (0) I (391665) wifi: state: assoc -> run (10) I (391765) wifi: connected with (acccess point name), channel 6 I (394145) event: ip: 172.20.10.6, mask: 255.255.255.240, gw: 172.20.10.1 Connected 172.20.10.6 I (401665) wifi: pm start, type:0
since 2017-11-16
mruby-esp32-app-mirb に再挑戦する。
ssh git@github.com できないと後で git clone mruby-esp32-app-mirb が面倒。
$ ssh -v -T git@github.com
https://github.com/mruby-esp32/mruby-esp32-app-mirb
$ sudo apt-get install build-essentials $ sudo apt-get install git wget make libncurses-dev flex bison gperf python python-serial $ sudo apt-get install ruby $ cd $ mkdir esp32-setup $ cd esp32-setup $ wget --no-check-certificate https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-73-ge28a011-5.2.0.tar.gz $ cd .. $ mkdir esp $ cd esp $ tar -xzf ../esp32-setup/xtensa-esp32-elf-linux64-1.22.0-73-ge28a011-5.2.0.tar.gz $ export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH $ git clone --recursive https://github.com/espressif/esp-idf.git $ export IDF_PATH=$HOME/esp/esp-idf $ git clone --recursive https://github.com/mruby-esp32/mruby-esp32-app-mirb.git $ cd mruby-esp32-app-mirb
上述の "mirb_task", 8192 は 81920 に増やしておく。(必要)
$ tail main/main.c mirb_main(1, argv); esp_restart(); } void app_main() { xTaskCreate(&mirb_task, "mirb_task", 81920, NULL, 5, NULL); }
$ make menuconfig # Serial flasher config > Default serial port => /dev/ttyS4 (COM4の場合) # Component config ---> ESP32-specific # > Initialize Task Watchdog Timer on startup => unchecked (なんだか不安定だったので切った) # > Event loop task stack size => 40960 (後ろに0をつけて10倍にしたが、こっちは効果不明)
$ make $ sudo chmod 777 /dev/ttyS4 $ make flash $ picocom -b 115200 /dev/ttyS4
こんな感じに動く
I (75) boot: Detected ESP32 I (34) boot: ESP-IDF 2nd stage bootloader I (35) boot: compile time 16:38:48 I (35) boot: Enabling RNG early entropy source... I (39) boot: SPI Speed : 40MHz I (43) boot: SPI Mode : DIO I (47) boot: SPI Flash Size : 4MB I (51) boot: Partition Table: I (54) boot: ## Label Usage Type ST Offset Length I (62) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (69) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (77) boot: 2 factory factory app 00 00 00010000 00100000 I (84) boot: End of partition table I (88) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x2ac00 (175104) map I (132) esp_image: segment 1: paddr=0x0003ac28 vaddr=0x3ffb0000 size=0x01684 ( 5764) load I (133) esp_image: segment 2: paddr=0x0003c2b4 vaddr=0x40080000 size=0x00400 ( 1024) load I (138) esp_image: segment 3: paddr=0x0003c6bc vaddr=0x40080400 size=0x03954 ( 14676) load I (150) esp_image: segment 4: paddr=0x00040018 vaddr=0x400d0018 size=0x559b8 (350648) map I (225) esp_image: segment 5: paddr=0x000959d8 vaddr=0x40083d54 size=0x03f3c ( 16188) load I (229) esp_image: segment 6: paddr=0x0009991c vaddr=0x400c0000 size=0x00000 ( 0) load I (233) boot: Loaded app from partition at offset 0x10000 I (238) boot: Disabling RNG early entropy source... I (243) cpu_start: Pro cpu up. I (247) cpu_start: Single core mode I (251) heap_init: Initializing. RAM available for dynamic allocation: I (258) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (264) heap_init: At 3FFB21F8 len 0002DE08 (183 KiB): DRAM I (271) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM I (277) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (283) heap_init: At 40087C90 len 00018370 (96 KiB): IRAM I (290) cpu_start: Pro cpu start user code I (9) cpu_start: Starting scheduler on PRO CPU. mirb - Embeddable Interactive Ruby Shell
ESP32::GPIO
https://github.com/mruby-esp32/mruby-esp32-gpio
ESP32::System
https://github.com/mruby-esp32/mruby-esp32-system
組み込み方
diff --git a/components/mruby/build_config.rb b/components/mruby/build_config.rb index 2c3d17c..8fb3816 100644 --- a/components/mruby/build_config.rb +++ b/components/mruby/build_config.rb @@ -77,5 +77,6 @@ MRuby::CrossBuild.new('esp32') do |conf| conf.gem :core => "mruby-compiler" conf.gem :core => "mruby-kernel-ext" conf.gem :core => "mruby-class-ext" - + conf.gem :github => 'mruby-esp32/mruby-esp32-gpio' + conf.gem :github => 'mruby-esp32/mruby-esp32-system' end
include ESP32::GPIO led = GPIO_NUM_2 pinMode(led, OUTPUT) loop { digitalWrite(led, HIGH) ESP32::System.delay(1000) digitalWrite(led, LOW) ESP32::System.delay(1000) }