BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News WebAssembly Extended with Hot Reloading, Remote Debugging and Uniform Hardware Access

WebAssembly Extended with Hot Reloading, Remote Debugging and Uniform Hardware Access

This item in japanese

Bookmarks

Researchers recently presented WARDuino, an extension to WebAssembly targeting microcontrollers. WARDuino addresses common development pain points by adding live code updates, remote debugging, and access to the microcontroller’s hardware modules. WARDuino’s virtual machine runs five times faster than Espruino (a popular JavaScript interpreter for microcontrollers) on some benchmarks.

Robbert Gurdeep Singh and Christophe Scholliers from the Ghent University in Belgium explained in the paper key pain points of the development with microcontrollers:

It is extremely hard and time-consuming to make correct and efficient programs for microcontrollers. […] Microcontrollers programmed in a low-level programming language such as C [may be] hard to debug and maintain. […] high-level programming languages [when used] for programming microcontrollers […] have the downside that they are orders of magnitude slower than the low-level languages. Moreover, they often provide no remote debugging support. […] For performance reasons access to the peripheral devices is often baked into the programming language which means that the language has limited use if your peripheral device is not supported by the language.

While microcontrollers can be programmed with low-level languages which generally provide the best experience in terms of speed, in many situations, speed is not the main concern. On embedded devices or microcontrollers with constrained memory and CPUs, the runtime executable size, memory usage or startup latency can prove to be primary concerns. Due to low-level languages tightly coupling the program to the microcontroller’s hardware, porting a program from one microcontroller to another may carry some difficulty. The researchers also mentioned that uploading a program to the chip (flashing) may be slow and tedious, with a small change in the program requiring the whole program to be re-uploaded – in some occurrences requiring a full minute.

WARDuino is a memory-safe virtual machine leveraging WebAssembly to provide a middle ground between high-level and low-level languages. High-level languages can target WebAssembly with the existing and growing range of runtimes for Rust, Go, C, C++, Lua, and more. While WARDuino does not offer the same performance profile as low-level languages do, it uses the existing functionality provided by Wasm to define modules that expose the underlying functionality provided by the ESP32 chip, with the result that developers need not rewrite programs when switching microcontroller. Additionally, WARDunio also extends Wasm with safe live code updates and remote debugging.

Remote debugging is enabled by the WARDuino virtual machine which receives debug messages (pause, play, step, dump, break+ id, and break− id) through interrupts. The first three messages replicate standard debugging functionality. . The dump message dumps the state of the running virtual machine, including instruction pointer, stack, variables, and more. The remaining two messages correspond to adding and removing breakpoints.

Live code updates are also handled through upload, updatef” and updatel messages that the developer can send with new data as payload. The appended data will serve to respectively update the entire WebAssembly state (restart with new code), do a live update of a function or update a local. This provides functionality similar to live reload and hot module replacement.

WARDuino defines three module extensions that address a large range of devices behind a uniform interface. Most microcontrollers have pins, each of which may have multiple modes, and can be used for reading and/or writing. The API is thus comprised of three functions: pinMode, digitalWrite, digitalRead. Other microcontrollers may simulate analog outputs (like sounds) through a pulse width modulation (PWM) module. WARDuino’s setPinFrequency API caters to that case. Lastly, for hardware communicating through a serial peripheral interface (like sensors or SD-cards), WARDunio adds 9 functions to manage 8bits and 16bits transfer.

The paper includes benchmarks comparing WARDunio performance to native C, C compiled to WebAssembly and JavaScript interpreted with Espruino. The researchers concluded:

We see that [in our micro benchmarks] WARDuino consistently outperforms Espruino by a factor of 5. […] While performance compared to Espruino is good, there is still a quite large gap with the execution speeds one can expect from C. In future work we aim to reduce this gap by implementing a JIT compiler.

While some Wasm interpreters such as Wasm3 focus on performance, and startup latency, none provide the Wasm debugging functionality which has been reported by developers as a significant pain point.

The full paper is available and contains additional details about the architecture of WARDuino, its constituents, benchmark results, and prior art.

Rate this Article

Adoption
Style

BT