Skip to content

thecharge/micro-typescript

Repository files navigation

MTSC-1 — write TypeScript, run it on a tiny chip

This project is created by Radoslav Sandov and uses agentic development in cases and places in order to deliver the tasks

MTSC-1 lets you write TypeScript and run it on a small microcontroller. Two boards work today: the Raspberry Pi Pico (RP2040) and the STM32F411 "Black Pill". You do not need any special tools. You plug the board into your computer. It shows up like a USB stick. You open a file, change it, and save. The board reads your code, turns it into a tiny program by itself, and runs it. Your code can blink lights, set brightness, read sensors, and more.

The idea in one picture

flowchart LR
    A[You edit MAIN.TS on the USB drive] --> B[You press Save]
    B --> C[The board reads the file]
    C --> D[The board turns TypeScript into bytecode on-chip]
    D --> E[The board runs it]
    E --> F[The LED changes / text appears on the serial port]
    F --> A
Loading

New here? Read docs/START-HERE.md first. It is a slow, plain-words how-to that walks you through build → flash → run, with every word explained and no jargon.

Try it in 3 steps

  1. Put the program on the board. Hold the BOOTSEL button, plug in the Pico, then run:
    make flash
  2. Open the drive. A USB drive named MTSCPY appears. It has two files:
    • MAIN.TS — your main program (a loop that sets the LED brightness)
    • PWMLED.TS — a small class that controls the LED Open MAIN.TS, change a number, and save. The LED changes.
  3. See messages. Anything you console.log shows up here:
    make monitor

On a Black Pill (STM32F411) instead

The same workflow, with a different way to put the firmware on:

  1. Hold the BOOT0 button, tap reset (or replug), then run make blackpill-flash. This uses dfu-util — no extra hardware needed.
  2. A USB drive named MTSCBP appears with MAIN.TS (it uses the pin name LED = PC13, the on-board LED). Edit and save; the board recompiles and runs.
  3. make blackpill-monitor shows console.log output.

Use ts/types/blackpill.d.ts in your editor for the Black Pill's pin names.

No board? Run the same TypeScript on your computer:

make emu EX=examples/sum.ts

What can the TypeScript do?

It can do math, if/while, functions, classes, and talk to hardware:

analogWrite(LED, 32768);          // set the LED to half brightness
let light = analogRead(A0);       // read a sensor
console.log("light = " + light);  // print it

A full list of hardware commands (with one example each) is in docs/HAL.md. The list of TypeScript features is in docs/DIALECT.md.

Documentation

Read this To learn
docs/START-HERE.md First time? A slow, plain-words how-to: build, flash, and run, step by step
docs/USAGE.md Every job and the one command for it (build, test, flash, run, watch)
docs/DEBUG.md Debugging a board with an ST-Link — one command, simple steps
docs/HAL.md Every hardware command with an example (LED, PWM, sensor, I2C, SPI, UART)
docs/DIALECT.md What TypeScript MTSC-1 understands, with examples
docs/ARCHITECTURE.md How the whole thing works inside (with diagrams)
docs/DEVELOPMENT.md How to build, test, and add a new board
docs/WORK-BREAKDOWN.md What's left, what's blocked (and on what), and what to start now

Put ts/types/mtsc.d.ts (Pico) or ts/types/blackpill.d.ts (Black Pill) in your editor’s project so it knows all the commands and that board's pin names.

What is real today

  • Edit-on-drive workflow on the RP2040 (USB drive + serial), verified on hardware.
  • On-chip TypeScript compiler: numbers, strings, if/while, &&/||, functions, recursion, classes (new, this, methods), import between files, and all the hardware commands.
  • Full hardware command set runs on the emulator. On the Pico it is verified on real silicon (2026-05-30): GPIO in/out (self-readback), ADC, temperatureC, now/delay timing, the I2C/SPI/UART buses (any bus by number, configurable pins, and a confirmed no-hang when no device is attached), and the two-way serial control demo (1/0/t/a). A real external bus device (sensor/ analyzer) is the only Pico check still open.
  • A host emulator that runs the exact same engine, for fast tests.

What is not done yet (being honest)

Full TypeScript type checking (types are accepted but not checked yet), a JIT, rich strings/arrays, and more chips (ESP32, RP2350). The STM32 Black Pill firmware is complete, builds, and runs on real silicon (the LED responds and the USB-MSC drive enumerates as BlackPill Disk), but its USB enumeration is not yet stable — first-silicon OTG-FS bring-up needs more work (likely a clean USB reset on boot). Also, on the F411 you get either the editable drive (MSC) or the serial console (CDC), not both (a 4-endpoint silicon limit), so each is a separate firmware build. Crystal is 25 MHz (HSE_MHZ=25). Finishing this needs an interactive bench session (ideally an ST-Link for logs); tracked in the hardware-acceptance change. The Pico's I2C/SPI/UART buses are now implemented in firmware too; their real-bus timing is likewise pending an on-hardware check. Progress is tracked in openspec/ (this project is spec-driven).

Build & test

make ci      # format, lint, spelling, tests, build the firmware
make test    # just the tests

About

A MicroPython inspired Typescript implementation for MCUs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors