要約
- M5 Stamp S3でmruby/cを動作させる。(PlatformIO, ESP-IDF)
- コードを公開しました:https://github.com/uist1idrju3i/M5StampS3_mrubyc
参考文献
手順
- PlatformIO(CLI)をインストールする。
- プロジェクトを作成する。
% pio init --board m5stack-stamps3
- platformio.iniを編集する。
[env:m5stack-stamps3] platform = espressif32@6.10.0 board = m5stack-stamps3 framework = espidf lib_deps = https://github.com/mrubyc/mrubyc.git#release3.3.1 build_flags = -Isrc/lib/mrubyc -I.pio/libdeps/m5stack-stamps3/mrubyc/src -DMRBC_INT64=1
- mruby/c公式で用意されているESP32用のHAL(mrubyc/hal/esp32)を、src/lib/mrubycにコピーしてhal.cを一部修正する。
- hal_init関数内の処理に
config.clk_src = TIMER_SRC_CLK_APB;
を付け足す。 - on_timer関数内の処理を2行修正する。
TIMERG0.int_clr_timers.t0_int_clr = 1;
TIMERG0.hw_timer[TIMER_0].config.tn_alarm_en = TIMER_ALARM_EN;
- hal_init関数内の処理に
- main.cを作成する。 (参考文献のものを使用させていただきました)
#include <stdio.h> #include <stdlib.h> #include "mrubyc.h" #define MRBC_MEMORY_SIZE (1024 * 30) static uint8_t memory_pool[MRBC_MEMORY_SIZE]; const uint8_t mrbbuf[] = { 0x52, 0x49, 0x54, 0x45, 0x30, 0x33, 0x30, 0x30, 0x00, 0x00, 0x00, 0x6a, 0x4d, 0x41, 0x54, 0x5a, 0x30, 0x30, 0x30, 0x30, 0x49, 0x52, 0x45, 0x50, 0x00, 0x00, 0x00, 0x4e, 0x30, 0x33, 0x30, 0x30, 0x00, 0x00, 0x00, 0x42, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x51, 0x02, 0x00, 0x2d, 0x01, 0x00, 0x01, 0x07, 0x02, 0x2d, 0x01, 0x01, 0x01, 0x25, 0xff, 0xf0, 0x11, 0x01, 0x38, 0x01, 0x69, 0x00, 0x01, 0x00, 0x00, 0x06, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x00, 0x00, 0x02, 0x00, 0x04, 0x70, 0x75, 0x74, 0x73, 0x00, 0x00, 0x05, 0x73, 0x6c, 0x65, 0x65, 0x70, 0x00, 0x45, 0x4e, 0x44, 0x00, 0x00, 0x00, 0x00, 0x08, }; void app_main() { mrbc_init(memory_pool, MRBC_MEMORY_SIZE); if (mrbc_create_task(mrbbuf, 0) != NULL) { mrbc_run(); } }
- M5 Stamp S3に転送して動作させてみる。
% pio run -t upload % pio device monitor
動作確認環境
- MacBookPro (2021, M1 Pro, macOS Sequoia 15.3.1)
- M5 StampS3 (Espressif ESP32-S3)
- PlatformIO Core, version 6.1.16
% pio pkg list Resolving m5stack-stamps3 dependencies... Platform espressif32 @ 6.10.0 (required: espressif32 @ 6.10.0) ├── framework-arduinoespressif32 @ 3.20017.241212+sha.dcc1105b (required: platformio/framework-arduinoespressif32 @ ~3.20017.0) ├── framework-espidf @ 3.50400.0 (required: platformio/framework-espidf @ ~3.50400.0) ├── tool-cmake @ 3.16.4 (required: platformio/tool-cmake @ ~3.16.0) ├── tool-esptoolpy @ 1.40501.0 (required: platformio/tool-esptoolpy @ ~1.40501.0) ├── tool-mkfatfs @ 2.0.1 (required: platformio/tool-mkfatfs @ ~2.0.0) ├── tool-mklittlefs @ 1.203.210628 (required: platformio/tool-mklittlefs @ ~1.203.0) ├── tool-mkspiffs @ 2.230.0 (required: platformio/tool-mkspiffs @ ~2.230.0) ├── tool-ninja @ 1.9.0 (required: platformio/tool-ninja @ ^1.7.0) ├── tool-openocd-esp32 @ 2.1100.20220706 (required: platformio/tool-openocd-esp32 @ ~2.1100.0) ├── tool-riscv32-esp-elf-gdb @ 12.1.0+20221002 (required: espressif/tool-riscv32-esp-elf-gdb @ ~12.1.0) ├── tool-xtensa-esp-elf-gdb @ 12.1.0+20221002 (required: espressif/tool-xtensa-esp-elf-gdb @ ~12.1.0) ├── toolchain-esp32ulp @ 1.23800.240113 (required: platformio/toolchain-esp32ulp @ ~1.23800.0) ├── toolchain-riscv32-esp @ 14.2.0+20241119 (required: platformio/toolchain-riscv32-esp @ 14.2.0+20241119) └── toolchain-xtensa-esp-elf @ 14.2.0+20241119 (required: platformio/toolchain-xtensa-esp-elf @ 14.2.0+20241119) Libraries └── mrubyc @ 0.0.0+20250211225825.sha.4e2be54 (required: git+https://github.com/mrubyc/mrubyc.git#release3.3.1)