Bringing the Moddable SDK (and modern JavaScript) to the Raspberry Pi Pico
Today Moddable is launching a public effort to bring the Moddable SDK to the Raspberry Pi Pico development board. The Moddable SDK includes XS, the only modern JavaScript engine designed for resource constrained microcontrollers. The Pico is powered by the new RP2040 microcontroller (MCU) from the same organization that created the Raspberry Pi family of Linux computers and sells for just $4. Bringing these two together allows developers to use the full power of JavaScript on this exciting new MCU.
New MCUs are introduced all the time and no SDK can support them all. Moddable decided to invest in support for the RP2040 at the encouragement of our community in a discussion thread. We see the potential for the RP2040 to become the first MCU many developers learn. We want them to have the choice to use the full power of JavaScript and the Moddable SDK. As an added bonus, the Moddable SDK also supports TypeScript, so that is now available for the Pico too.
Because the idea for porting the Moddable SDK to the Pico arose in our community, we are committed to working with the community on the port. Moddable has taken the first steps to get a basic port working. The work to finish the port and make it easy for developers to work is being done in the Pico branch of our repository on GitHub. Once the port is stable and complete, we'll merge it to the main brach.
The hardware
In terms of memory, storage space, and CPU power, the Pico falls somewhere between the ESP8266 and ESP32 MCUs already supported in the Moddable SDK. It uses an ARM instruction set, instead of Xtensa. The Pico has no radio, so Wi-Fi and Bluetooth are not directly supported. In addition to an extensive suite of standard IO capabilities, the Pico has a custom IO subsystem called PIO that offers unique capabilities that will be interesting to explore.
For our porting work, we are using the Raspberry Pi Pico development board.
The software
The Pico SDK is the foundation for the Moddable SDK port to the RP2040 MCU. It provides a bare bones embedded API. It is focused on efficient access to hardware capabilities. The APIs appear to be unique to the Pico, with a few exceptions like the use of TinyUSB. Using these APIs has generally been straightforward, though applying them to more complex problems like multi-threading web workers is yet to be explored.
The initial port
The initial port of the Moddable SDK for the Pico is just enough to run the hello world and blink examples. That represents a great deal of work, as it also includes integration with the Moddable SDK build system. Here are some of the capabilities in the port:
- Builds on macOS and Linux
- Supports standard JavaScript (including nearly all of the forthcoming ECMAScript 2021 specification). Here are some of the language features we've verified already:
- Timer class
- Cryptographic classes
- Digital write (to blink an LED)
- Source level JavaScript debugging with xsbug, including runtime instrumentation
- Preloaded JavaScript images for instant-on (JavaScript execution begins just milliseconds after Pico is plugged in)
- Automatic removal of unused JavaScript language features from the engine to minimize flash size and download time
- Documentation on setting up build environment on macOS and Linux
The to-do list
Turning the initial port into a truly useful, complete port is a big project. Each individual developer has their own ideas and priorities to the port.
Here's a quick list of items to do to help start conversations.
- Digital input
- Digital monitor (interrupt notification on GPIO input change)
- Analog input
- PWM output
- I²C
- SPI output (needed for displays)
- Audio (no example in Pico SDK?)
- Look at how to integrate PIO (RMT on ESP32 might be realistic starting point)
- Atomics in XS (not currently linking)
- Web Workers (to make use of the second CPU core)
- Flash read/write (to enable preferences and mods)
- Mods
- Support for building on Windows
- Bulletproofing build / install on macOS, Windows, and Linux
- Improving set-up documentation
- Testing
- Implementing TC53 IO -- ECMAScript Modules for Embedded Systems
- Eliminate need to always unplug Pico and push button to enter programming mode
- Serial interrupt support for debugger connection (lower latency debugging)
Some of these are straightforward projects that can be done by taking a look at how other ports work. Others, like PIO support, are open-ended explorations.
Join us
Earlier this month, Moddable shipped support for the ESP-IDF 4.2 after a month-long developer preview. During that time, the community provided bug reports, feedback, and improvements that helped make the final release better. We're excited to see how the Pico porting effort will benefit from community involvement from this early start.
Porting is a great way to learn. You'll learn about the Moddable SDK -- how it works and how it is organized -- and about the RP2040 MCU. We've set up a Porting Discussion on GitHub. Feel free to contribute to an existing discussion topic or start a new one.
The Pico branch is available now as part of the Moddable SDK. The instructions for getting started are in the repository.