• What Comes Next: Fractal

    Monday, October 27, 2014

    10/27/2014– Kevin Mehall

    Jon’s last post hinted at what we’re working on next, a project we’re calling Fractal. I wanted to explain in a little more detail what we’re planning for the Fractal software stack.

    Our users love Tessel for the ease of getting started. This is especially apparent at hackathons and other meetups we’ve held for people to try Tessel. A first-time user can go from zero to something quite impressive in only a few hours. Many customers have been asking about their next steps once they build a prototype – Tessel can’t just be a device for winning hackathons. A good platform needs to scale as your project turns into a product and help you win in the marketplace too.

    Fractal is a system design tool for microcontroller firmware and hardware. For Tessel prototypes, Fractal will improve IO performance and provide better debug tools. Once your prototype works, and you want smaller, cheaper, and lower-power boards in quantity, Fractal will help you optimize your system design. It’ll help you choose the right parts and put together reference schematics and circuit board layouts as a starting point for your own hardware.

    Beyond JavaScript

    We’ve already had to include some dedicated C code in our firmware for specific applications with timing requirements that JavaScript can’t meet. The Audio module requires code in the firmware to feed the audio chip data exactly when it needs it, without waiting for the JS event loop. We’ve recently added code for driving Neopixel LEDs with the (really powerful, but nontrivial-to-configure) timer hardware built into the NXP micrcocontroller on Tessel. While this works for the handful of applications so far, it doesn’t scale; these things should be libraries, not built into the main Tessel firmware. With Fractal, we’re working on a way to ship compiled code modules that integrate tightly into the firmware, while remaining easy to use.

    Fractal adds Components, bundles of code for a discrete piece of your firmware, like an I2C controller, accelerometer driver, or JS VM containing your domain logic. Components have statically-defined, asynchronous, language-agnostic interfaces, and the Fractal compiler will be able to automatically generate cross-language bindings, so you don’t have to write them manually. This makes it easier to use the right language for each piece and phase of your project, be it prototyping or realtime control.

    The right language isn’t always JS or C. I’m enjoying Rust, and think it makes an ideal language for programming microcontrollers. Rust is a new language from Mozilla that combines high-level expressiveness and safety with low-level performance, size, and closeness to hardware. It’s a new entry into the systems programming space that has been dominated by C for decades.

    I’m also working on Signalspec, a domain-specific language for modeling IO protocols using regex-like definitions. Signalspec is a dedicated description language to abstractly define and then implement the state machines used to communicate with sensors and other chips. It saves you from writing asynchronous state machines by hand, a messy, error-prone process in existing imperative languages.

    Because of the cross-language Component interfaces that abstract the underlying hardware, porting between languages and between hardware platforms isn’t a full-system rewrite. Start by prototyping your domain logic in JS on Tessel, then port it to Rust and fit it on a $2 Cortex M0 part. Fractal will make such a port not only feasible, but easy and elegant.

    Tessel brings a few aspects of Node / JS to embedded development that will become a broader part of Fractal and improve the platform for all languages:


    Components involve a change in how code gets deployed to your Tessel. Right now, you normally download the firmware from us pre-compiled, and then tessel run or tessel push deploys a bundle of your JavaScript, which the firmware runs from a virtual filesystem. Under Fractal, your project specifies which Components get compiled in, and it will build a custom firmware image containing everything from the low-level drivers to the Colony JS runtime and your JS code, with each deploy. This means many errors are detected at compile time instead of runtime.

    The ease of installing Tessel module drivers is important piece of the Tessel user experience, and will guide the design of the Component distribution story. npm will obviously remain the way to install pure-JS packages from the Node ecosystem within a JS component.


    There’s one convention in JS that is actually more like how hardware works than most other languages: events. Hardware interrupts wake up the CPU and run an interrupt handler function on hardware events like button presses, SPI completions, and UART received bytes. Sounds kind of like a JS async callback, right?

    An OS kernel can be thought of as an interrupts-to-threads adapter. To achieve asynchronous events within this threaded model, Node uses libuv, which can be thought of as a threads-to-events adaptor. On Tessel, rather than going from interrupts to threads and back again, hardware interrupts enqueue events directly onto the JS event queue.

    Fractal components add more structure to this asynchronous call / callback model, and use it throughout every layer of the system. Explicitly defining the beginning and end of IO actions as events saves power by spending more time in sleep mode, and saves RAM by avoiding the use of multiple stacks for threads.

    We’re just getting started developing Fractal. For more details, check out our preliminary documentation and let us know what you think. Sound like something you want to work on? We’ll be developing Fractal in the open on GitHub, and we’re hiring.

    #kevin mehall #fractal #Tessel #technical machine

August 2018

January 2018

July 2017

February 2017

November 2016

October 2016

September 2016

August 2016

July 2016

June 2016

April 2016

March 2016

February 2016

November 2015

September 2015

August 2015

July 2015

June 2015

May 2015

March 2015

February 2015

January 2015

December 2014

November 2014

October 2014

September 2014

August 2014

July 2014

June 2014

May 2014

April 2014

March 2014

February 2014

January 2014

December 2013

November 2013

October 2013

September 2013

August 2013

July 2013