0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AtomVM を ESP32S3 向けにビルドして動かす

0
Last updated at Posted at 2026-08-03

Building for ESP32 に沿って進めていきます。

ターゲットマシンは M5STACK CORE S3 です。

前準備

AtomVM を Generic UNIX 向けにビルドして動かす前準備 と同じです。

ビルドする

idf.py を使えるようにし、

$ source "/home/pojiro/.espressif/tools/activate_idf_v5.5.5.sh"
...
$ type idf.py
idf.py は関数です
idf.py ()
{
    "/home/pojiro/.espressif/tools/python/v5.5.5/venv/bin/python" "/home/pojiro/.espressif/v5.5.5/esp-idf/tools/idf.py" "$@"
}

ビルド前準備をして、

$ cd /home/pojiro/Sandbox/AtomVM/
$ cd src/platforms/esp32/
$ idf.py set-target esp32s3
...
-- Build files have been written to: /home/pojiro/Sandbox/AtomVM/src/platforms/esp32/build

ビルドする。

$ idf.py build
Executing action: all (aliases: build)
...
[1143/1143] cd /home/pojiro/Sandbox/AtomVM/src/platforms/...Sandbox/AtomVM/src/platforms/esp32/build/atomvm-esp32.bin
atomvm-esp32.bin binary size 0x188470 bytes. Smallest app partition is 0x1c0000 bytes. 0x37b90 bytes (12%) free.

Project build complete. To flash, run:
 idf.py flash
or
 idf.py -p PORT flash
or
 python -m esptool --chip esp32s3 -b 460800 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m 0x0 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin 0x10000 build/atomvm-esp32.bin 0x1d0000 ../../../build/libs/esp32boot/esp32boot.avm
or from the "/home/pojiro/Sandbox/AtomVM/src/platforms/esp32/build" directory
 python -m esptool --chip esp32s3 -b 460800 --before default_reset --after hard_reset write_flash "@flash_args"

フラッシュする

指示通り書き込んでみます。

$ idf.py -p /dev/ttyACM0 flash
Executing action: flash
Running ninja in directory /home/pojiro/Sandbox/AtomVM/src/platforms/esp32/build
Executing "ninja flash"...
[1/5] cd /home/pojiro/Sandbox/AtomVM/src/platforms/esp32/...Sandbox/AtomVM/src/platforms/esp32/build/atomvm-esp32.bin
atomvm-esp32.bin binary size 0x188470 bytes. Smallest app partition is 0x1c0000 bytes. 0x37b90 bytes (12%) free.
[1/1] cd /home/pojiro/Sandbox/AtomVM/src/platforms/esp32/...tomVM/src/platforms/esp32/build/bootloader/bootloader.bin
Bootloader binary size 0x5120 bytes. 0x2ee0 bytes (37%) free.
[4/5] cd /home/pojiro/.espressif/v5.5.5/esp-idf/component...5.5.5/esp-idf/components/esptool_py/run_serial_tool.cmake
esptool.py --chip esp32s3 -p /dev/ttyACM0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 4MB 0x0 bootloader/bootloader.bin 0x10000 atomvm-esp32.bin 0x8000 partition_table/partition-table.bin 0x1d0000 ../../../../build/libs/esp32boot/esp32boot.avm
esptool.py v4.12.0
Serial port /dev/ttyACM0
Connecting...
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE
Crystal is 40MHz
USB mode: USB-Serial/JTAG
MAC: 48:27:e2:66:d1:10
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00005fff...
Flash will be erased from 0x00010000 to 0x00198fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x001d0000 to 0x00219fff...
SHA digest in image updated
Compressed 20768 bytes to 13306...
Writing at 0x00000000... (100 %)
Wrote 20768 bytes (13306 compressed) at 0x00000000 in 0.4 seconds (effective 446.4 kbit/s)...
Hash of data verified.
Compressed 1606768 bytes to 903507...
Writing at 0x00197198... (100 %)
Wrote 1606768 bytes (903507 compressed) at 0x00010000 in 13.2 seconds (effective 970.8 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 130...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (130 compressed) at 0x00008000 in 0.1 seconds (effective 490.2 kbit/s)...
Hash of data verified.
Compressed 300324 bytes to 142238...
Writing at 0x00213520... (100 %)
Wrote 300324 bytes (142238 compressed) at 0x001d0000 in 2.6 seconds (effective 939.9 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
Done

確認してみます。 ( screen 接続時にはすでに出力が流れたあととなったので、ここでは idf-monitor に頼っています。

$ pwd
/home/pojiro/Sandbox/AtomVM/src/platforms/esp32
$ idf-monitor -p /dev/ttyACM0
--- esp-idf-monitor 1.9.0 on /dev/ttyACM0 115200
--- Warning: No ELF files found. Please provide the ELF file paths, required for binary log decoding.
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0x28 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4037c96a
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce2820,len:0x14d4
load:0x403c8700,len:0xd0c
load:0x403cb700,len:0x2eec
entry 0x403c8920
I (24) boot: ESP-IDF v5.5.5 2nd stage bootloader
I (24) boot: Multicore bootloader
I (25) boot: chip revision: v0.2
I (25) boot: efuse block revision: v1.3
I (27) boot.esp32s3: Boot SPI Speed : 80MHz
I (31) boot.esp32s3: SPI Mode       : DIO
I (35) boot.esp32s3: SPI Flash Size : 4MB
I (38) boot: Enabling RNG early entropy source...
I (43) boot: Partition Table:
I (45) boot: ## Label            Usage          Type ST Offset   Length
I (52) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (58) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (65) boot:  2 factory          factory app      00 00 00010000 001c0000
I (71) boot:  3 boot.avm         RF data          01 01 001d0000 00080000
I (78) boot:  4 main.avm         RF data          01 01 00250000 00100000
I (84) boot: End of partition table
I (88) esp_image: segment 0: paddr=00010020 vaddr=3c130020 size=3a7fch (239612) map
I (139) esp_image: segment 1: paddr=0004a824 vaddr=3fc9f800 size=055f4h ( 22004) load
I (144) esp_image: segment 2: paddr=0004fe20 vaddr=40374000 size=001f8h (   504) load
I (145) esp_image: segment 3: paddr=00050020 vaddr=42000020 size=12ce60h (1232480) map
I (375) esp_image: segment 4: paddr=0017ce88 vaddr=403741f8 size=1b528h (111912) load
I (401) esp_image: segment 5: paddr=001983b8 vaddr=50001008 size=00020h (    32) load
I (401) esp_image: segment 6: paddr=001983e0 vaddr=600fe000 size=0006ch (   108) load
I (415) boot: Loaded app from partition at offset 0x10000
I (416) boot: Disabling RNG early entropy source...
I (426) cpu_start: Multicore app
I (435) cpu_start: GPIO 44 and 43 are used as console UART I/O pins
I (435) cpu_start: Pro cpu start user code
I (435) cpu_start: cpu freq: 160000000 Hz
I (437) app_init: Application information:
I (441) app_init: Project name:     atomvm-esp32
I (445) app_init: App version:      v0.7.0-alpha.1-211-g0220c78e
I (451) app_init: ELF file SHA256:  89696a527...
I (455) app_init: ESP-IDF:          v5.5.5
I (459) efuse_init: Min chip rev:     v0.0
I (463) efuse_init: Max chip rev:     v0.99
I (467) efuse_init: Chip rev:         v0.2
I (471) heap_init: Initializing. RAM available for dynamic allocation:
I (477) heap_init: At 3FCA8FB0 len 00040760 (257 KiB): RAM
I (482) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM
I (487) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (492) heap_init: At 600FE06C len 00001F7C (7 KiB): RTCRAM
I (499) spi_flash: detected chip: generic
I (501) spi_flash: flash io: dio
W (504) spi_flash: Detected size(16384k) larger than the size in the binary image header(4096k). Using the size in the binary image header.
W (517) i2c: This driver is an old driver, please migrate your application code to adapt `driver/i2c_master.h`
I (527) sleep_gpio: Configure to isolate all GPIO pins in sleep state
I (533) sleep_gpio: Enable automatic switching of GPIO sleep configuration
I (540) main_task: Started on CPU0
I (540) main_task: Calling app_main()

    ###########################################################

       ###    ########  #######  ##     ## ##     ## ##     ##
      ## ##      ##    ##     ## ###   ### ##     ## ###   ###
     ##   ##     ##    ##     ## #### #### ##     ## #### ####
    ##     ##    ##    ##     ## ## ### ## ##     ## ## ### ##
    #########    ##    ##     ## ##     ##  ##   ##  ##     ##
    ##     ##    ##    ##     ## ##     ##   ## ##   ##     ##
    ##     ##    ##     #######  ##     ##    ###    ##     ##

    ###########################################################

I (600) AtomVM: Starting AtomVM revision 0.8.0-dev+git.0220c78e
I (600) sys: Loaded BEAM partition boot.avm at address 0x1d0000 (size=524288 bytes)
I (640) network_driver: Initialized network interface
I (640) network_driver: Created default event loop
I (640) AtomVM: Found startup beam esp32init.beam
I (650) AtomVM: Starting esp32init.beam...
---
AtomVM init.
I (700) sys: Loaded BEAM partition main.avm at address 0x250000 (size=1048576 bytes)
Starting application...
Hello World
Console.puts() and Console.print() work with binary or charlist strings.
Return value: ok
I (730) AtomVM: AtomVM application terminated.  Going to sleep forever ...

バッチリですね。

I (700) sys: Loaded BEAM partition main.avm at address 0x250000 (size=1048576 bytes)
Starting application...
Hello World
Console.puts() and Console.print() work with binary or charlist strings.
Return value: ok
I (730) AtomVM: AtomVM application terminated.  Going to sleep forever ...

は、 AtomVM 向け Elixir Project を作るGeneric UNIX で実行してみる の節で作成したコードが動作して出力されています。

このことから、ターゲット固有のライブラリコードを使わない限りは、 Generic UNIX 向け、ESP32 向けに関わらず同じ Elixir アプリケーションを動かせることが想像できます。
それはそうですよね。 VM 用の BEAM bytecode は変わらないからです。

M5STACK CORE S3 での開発手順

I (435) cpu_start: GPIO 44 and 43 are used as console UART I/O pins

とあるので(G44 が RX, G43 が TX)、 UART をシリアルケーブルで /dev/ttyUSB0 としてidf-monitor でモニタしつつ、AtomVM 向け Elixir Project を作るに沿ったプロジェクトにおいて、

  1. コードを修正する
  2. avm ファイルを作る by mix atomvm.packbeam
  3. 書き込む by mix atomvm.esp32.flash --port /dev/ttyACM0

とすれば、コードを書き変え→書き込み→コンソールで確認をスムーズに行えそうです。

  • 画像左が USB-UART で私のマシンでは /dev/USB0
  • 画像右が USB-CDC で私のマシンでは /dev/ttyACM0

今日はここまで。

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?