Getting Started

MetalScript is a compiler for JavaScript, specifically designed to target small microcontroller devices.

This page is a stub. More content will appear here in future.

Back home


This example assumes that you have the following:

/* blinky.js */
setInterval(() => mcu.gpio('B4').toggle(), 500);

To the right is a simple code example that blinks an LED. Save this as blinky.js and modify the pin number B4 to whichever pin corresponds to the LED on your target MCU.

To run this on the microcontroller, attach the microcontroller to your PC using the JTAG interface, and run this command in a command prompt:

metalscript blinky.js

This will run the JavaScript on the device. If everything works correctly, you should see the LED toggling every 500 ms.

How does this work?

The MetalScript command line tool translates the input JavaScript to machine code and downloads it to the device for execution. In its default mode of execution, it will do this in the following steps:

  1. Searches the system for a supported JTAG interface.
  2. Queries the target device ID using the JTAG interface. From this, it understands information about the target architecture, memory layout, etc.
  3. Translates your JavaScript source into machine code for the target, taking into account aforementioned target information.
  4. Downloads the machine code to the target over the JTAG link and executes it.
  5. Maintains the JTAG debug link in order to capture console.log messages from the device and display them in the host console.


The call to MCU.start() is required before your code can access any IO, such as the GPIO we're using in this example. If you have any commonjs require calls, or ECMAScript import calls (neither of which this example has), these must precede the call to MCU.start().

Behind the scenes, MetalScript is running an internal interpreter on all code that precedes MCU.start(). See Concepts for more details.


Coming soon…