This page is a stub. More content will appear here in future.
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:
How does this work?
- 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.
- Downloads the machine code to the target over the JTAG link and executes it.
- Maintains the JTAG debug link in order to capture
console.logmessages 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
Behind the scenes, MetalScript is running an internal interpreter on all code that precedes
MCU.start(). See Concepts for more details.