Skip to content

Latest commit

 

History

History
139 lines (91 loc) · 5.86 KB

flashing-firmware.md

File metadata and controls

139 lines (91 loc) · 5.86 KB

Build and flash firmware

日本語

Firmware architecture

Host and MOD

firmware architecture

Stack-chan's firmware consists of a program that provide the basic operation of Stack-chan (host), and a user application (mod). Once the host is written, the mod can be installed in a short time for fast development. First write the host, and then write the mods as needed.

Manifest File

The host and the MOD each consist of a manifest file (manifest.json), source code for JavaScript modules, and resources such as images and audio. The manifest file includes the names and locations of the JavaScript modules (modules) , as well as the configurations that can be referenced within the modules (config). Additionally, the manifest file can include other manifest files (include).

For all configuration items, please refer to the Moddable official documentation.

Configuration

StackChan can change settings such as motor types and pin assignments from the manifest file. You can modify stack-chan/firmware/stackchan/manifest_local.json for local settings. The following settings can be written under the "config" key.

Key Description Available values
driver.type Type of motor driver "scservo", "rs30x", "pwm", "none"
driver.panId ID of the serial servo used for pan axis (horizontal rotation of the neck) 1~254
driver.tiltId ID of the serial servo used for tilt axis (vertical rotation of the neck) 1~254
driver.offsetPan Offset of the pan axis -90~90
driver.offsetTilt Offset of the tilt axis -90~90
tts.type TTS type "local", "voicevox"
tts.host Host name when TTS communicates with server "localhost", "ttsserver.local", etc.
tts.port Port number when TTS communicates with server 1~65535

Additionally, you can specify the paths of other manifest files in a list format under the "include" key.

Writing the base program (hosts)

As stated above, Stack-chan's firmware comprises a base program (host) and a user application (MOD). The following commands are used to build and write a host.

No sudo required for the command.

$ npm run build --target=esp32/m5stack_cores3
$ npm run deploy --target=esp32/m5stack_cores3

The program will be saved under the $MODDABLE/build/ directory.

If written correctly, the face of Stack-chan will appear a few seconds after startup. The M5Stack buttons will change Stack-chan's behavior as follows:

  • A Button (in the case of CoreS3, the bottom-left area of the screen) ... Stack-chan will look in a random direction every 5 seconds.
  • B Button (in the case of CoreS3, the bottom-center area of the screen) ... Stack-chan will look left, right, down, and up.
  • C Button (in the case of CoreS3, the bottom-right area of the screen) ... The color of Stack-chan's face will invert.

(Postscript by Goto)

If the following message was displayed when you try to write, you have to give a permission.

Serial port /dev/ttyUSB0
/dev/ttyUSB0 failed to connect: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'
  1. Add the user to the dialout group:

To access the serial port, the user must be added to the dialout group. Execute the following command.

$ sudo usermod -a -G dialout $USER

After executing the command, log out and log in again.

  1. Grant the serial port permission:

Use the following command to grant the serial port permission. The following command is an example when the port is /dev/ttyUSB0.

$ sudo chmod 666 /dev/ttyUSB0
  1. Write to the correct port:

Use the -p option to explicitly specify the port to connect to.

$ npm run deploy --target=esp32/m5stack_cores3 -p /dev/ttyUSB0

Debugging

You can debug the program using the following commands:

$ npm run debug --target=esp32/m5stack_cores3

These commands will open Moddable's debugger xsbug and connect it to the M5Stack.

xsbug

Using xsbug, you can check logs, set breakpoints (temporarily pause the program at specific lines), and perform step-by-step execution. For detailed instructions on how to use xsbug, please refer to the official documentation.

(Optional) Writing user application (mods)

The following command is used to build and write a mod.

No sudo required for the command.

$ npm run mod --target=esp32/m5stack_cores3 [mod manifest file path]

Example: Installing mods/look_around

$ npm run mod --target=esp32/m5stack_cores3 ./mods/look_around/manifest.json

> stack-chan@0.2.1 mod
> mcrun -d -m -p ${npm_config_target=esp32/m5stack} ${npm_argument} "./mods/look_around/manifest.json"

# xsc mod.xsb
# xsc check.xsb
# xsc mod/config.xsb
# xsl look_around.xsa
Installing mod...complete

Next Step