Wren on a nRF52840 … does it fit?

Writing software for a microcontroller is significantly different than writing for other desktop, mobile, web or server platforms.  There is large choice in chip vendor, chip architectures and operating systems with usually severe resource constraints.  Likely because of this, there is no well developed application model, like there is say on mobile with iOS and Android.  This leads to developers being responsible for the full software stack.

Several approaches have been taken to reduce the developer burden, including Arduino and CircuitPython, where for supported set of boards you can program in derivatives of Processing or Python languages.  The success of these approaches, has led to the availability of libraries for various hardware peripherals and communications protocols, including I2C and Bluetooth.

OpenThread is an open-source implementation of Thread, an IPv6 protocol designed for IoT considering size, security and energy, as used in the Project Connected Home over IP. OpenThread is not supported on either the Arduino or CircuitPython platforms, but is on real-time operating systems (RTOS) including ot-rtos, RIOT and Zephyr Project. Using one of these RTOS provides an extensive set of features and libraries for development in C/C++, supported by industrial quality tooling. The learning curve is significant.

Is it possible to harness the power of an RTOS and modern SOC in a scripting language, to provide a more approachable and dynamic development experience?

With a background in embedded Smalltalk, I became interested in Wren with claims of “a small, fast, class-based, concurrent scripting language” and “Smalltalk in a Lua-sized package with a dash of Erlang and wrapped up in a familiar, modern syntax”. It is possible to experiment within a browser or locally on a desktop, and it is a pleasant experience. Consideration has been given to embedding within a larger environment, such as a game, and calling to and from C. Was it applicable to IoT ?

Of the inexpensive SOC available, the Nordic Semiconductor nRF52840 has amongst the most resources available, with deep low power modes. The nRF52840 is “built around the 32-bit ARM® Cortex™-M4 CPU with floating point unit running at 64 MHz”, 1MB Flash, 256kB of RAM and integrated multiprotocol radio, supporting concurrent Bluetooth and Thread. Nordic provides support for Zephyr on the nRF52840 in their nRF5 SDK.

Given the is constraints imposed while travelling, what you can pack and poor internet connections, I used the Adafruit Feather nRF52840 Express for a hardware target. As a hack, I used the generate_amalgamation.py utility provided in the Wren distribution to create a single file with all the Wren source. Then running the Arduino IDE and installing the board support package, it was relatively easy to build the provided example as the wren.ino and install the executable over USB. Substituting var e = [1, 2, 3]\ne.insert(3, 4)\n for the code to be executed, the VM was created, the script run and the VM torn down in 63mS, as shown below:

screen capture

The executable required 145kB of Flash and 8k of RAM, so at least for toy scripts, Wren fits on the nRF52840!

Likely because of my inexperience with this environment, I was not able to extend the example much and get stable results. The next step, to be explored in a subsequent post, is to utilize better tooling, such as the Nordic version of the Segger Embedded Studio to build on Zephyr and get a resource profile during execution.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.