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.
Example
This example assumes that you have the following:
- A microcontroller that is one of the list of supported microcontrollers on a working PCB. To get started quickly, consider using one of our starter kits.
- A compatible JTAG adapter to connect the device up to your PC
/* blinky.js */
MCU.start();
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:
- Searches the system for a supported JTAG interface.
- Queries the target device ID using the JTAG interface. From this, it understands information about the target architecture, memory layout, etc.
- Translates your JavaScript source into machine code for the target, taking into account aforementioned target information.
- Downloads the machine code to the target over the JTAG link and executes it.
- Maintains the JTAG debug link in order to capture
console.log
messages from the device and display them in the host console.
MCU.start
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.
Concepts
Coming soon…