[SAoC] "Druntime for Microcontrollers" project thread

Severin Teona teona.severin9 at gmail.com
Mon Sep 14 07:59:08 UTC 2020

Hi all,

I am Teona Severin and I am a first year Masters’ Degree student 
at University Politehnica of Bucharest. During my bachelor’ 
years, I was most interested in fields such as Operating Systems, 
Programming Languages and Paradigms and Embedded Systems, with a 
focus on the Internet of Things.
Learning new programming languages and understanding the way a 
compiler interacts with the operating system were the most 
fascinating things I have learned in my last 4 years of study. 
After studying different programming languages like Prolog, 
Haskell or Java, in the summer of 2019 I was introduced to the 
D-Language by Eduard Stăniloiu and Răzvan Nițu during a workshop 
at the summer-school I was volunteering for, “Ideas and Projects 
Being an Internet of Things enthusiast, I began wondering whether 
it was possible or not to use D with different types of embedded 
and resource constrained devices. This is why I chose as my 
bachelor project “D-Language for IoT systems”. This project 
consisted in writing a few libraries for high-performance 
embedded systems (such as Raspberry Pi or BeagleBone Black), 
through which one can access different pins exported by the 
device (I2C[1], GPIO[2] or ADC[3] pins). Also, I have ported 
TockOS’ [4] C userland to D[5], in order to run D code on 
microcontrollers based on ARM Cortex-M CPUs (TockOS’ target 
A big problem I encountered while porting the userland was the 
fact that the Druntime was not built for the target architecture 
and even if it would have been, it would not have fit the memory 
on the device. As a conclusion, I had to use ‘betterC’, a very 
useful concept for devices with little memory, but lots of 
functionalities such as classes, GC or exceptions could not be 

Starting from this point, I have decided to participate this year 
at Symmetry Autumn of Code and create a micro-runtime for the D 
language, to be used with microcontrollers and memory constrained 
devices. Up until now, I have managed to compile and run D code 
on microcontrollers with “betterC” but only without the standard 
D library and runtime and of course, without key concepts of D 
This project combines perfectly all the fields I have an interest 
in: programming languages, understanding the way the compiler 
works (with or without an operating system) and embedded systems.

During SAoC, I have planned the next steps:

Milestone 1: Build a runtime (doesn’t matter the size yet) for 
the specified architecture:
- Try to build the runtime for the Cortex-M CPU architecture:
  * either by using the ‘ldc-build-runtime’ toolchain (which 
currently fails because of a ‘CMake’ error)
  * or by building and compiling manually the source code
- If the build succeeds, I won’t be able to test it because the 
size of the druntime doesn’t fit in the microcontroller’s 
constrained resources.
- Begin removing unnecessary functionalities (that a code running 
on a microcontroller does not need) from the ‘object.d’ file 
(most probably by stubbing the code)

Milestone 2:  Try to have a small object.d implementation
- Continue removing any functionality a small class doesn’t need.
- Try to test the new ‘object.d’ on the microcontroller after a 
successful build of the file.

Milestone 3: Attempt a port of the current Garbage Collector
- Try to port the current GC for the target architecture
- If that fails in the first 2 weeks, try to implement a 
small-sized GC from scratch (this could exceed the deadline of 
this milestone)

Milestone 4: Stress test and further implementations
- If the GC is ported, begin to stress-test the runtime
- Write a few drivers that actively use classes and communicate 
with different devices (an LCD screen, a temperature sensor, etc).
- If everything goes well, begin research for porting other 
concepts like Exceptions or Errors.
- If the GC is not ported at the beginning of this milestone, 
finish the GC and stress-test in the remaining time.

I will keep you posted weekly with everything I manage to do (or 
I don’t manage to do).

Thank a lot,

[1]: https://github.com/DLang-IoT/i2c
[2]: https://github.com/DLang-IoT/gpio
[3]: https://github.com/DLang-IoT/adc
[4]: https://www.tockos.org
[5]: https://github.com/DLang-IoT/libtock-d

More information about the Digitalmars-d mailing list