Arduino and D

Mike via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 25 16:40:43 PDT 2014


On Saturday, 25 October 2014 at 21:49:53 UTC, Ty Tower wrote:
> Has anybody tapped the massive Arduino programming explosion 
> using D instead of C++ ?
> I got started on Arduino a few years back and it has taken the 
> microprocessor popularity through the roof .
> Unfortunately you download the IDE (Integrated Development 
> Environment) from Arduino.cc direct and then using a $3 
> development board with a 328p chip on it ,proceed to program 
> the  chip to do pretty much whatever you can think of including 
> turning stuff on with your mobile from anywhere in the world  
> and much much more .
>
> I wondered if someone could adapt it to D ?

As far as I know, none of the main D compilers (DMD, LDC, GDC) 
can generate code for 8-bit MCUs.  I remember reading somewhere 
that GDC has turned on a flag that specifically disables it.  
However, I think it would be cool if a motivated individual would 
actually flip this flag and see how far they can get.  I don't 
now if avr-gcc is part of the mainline GCC branch, though.  In 
summary, the Atmel ATmega needs some infrastructure first.

The ARM Cortex-M based Arduino boards (Arduino Due for example) 
can already be programmed with D using either the LDC compiler 
(with ARM Thumb backend) or the GDC compiler.  I've encountered 
several bugs trying to get a bare-bones druntime compiled with 
the LDC compiler, but the LDC folks have been attentive and 
appear to be addressing them (Thank you!).  A minimal "Hello 
World" how-to was created on the D Wiki [1] to help users get 
started with this.  There are also instructions for building a 
GDC cross-compiler on a Linux host [2] (Thank you, GDC!).  A 
presentation was also given at DConf 2014 providing an 
introduction to some work done on this platform [3].  Most of my 
work has stalled as I try to find a way to make the experience 
more polished, and less like patchwork.

Bottom line, though, is druntime has not been ported to the ARM 
Cortex-M platform, so that is the barrier.  The good news is that 
it's not necessary to have the entire druntime ported to do basic 
C-style programming in D.  In fact, a simple object.d file with a 
few dummy implementations will get you quite far [4].  The 
current druntime isn't suited very well to bare-metal 
programming, and really expects an operating system to exist 
underneath.  There have been efforts to try an change that, but 
they've mostly met resistance.  All work on this platform 
currently exists outside of the main D programming language 
repositories.

There also appears to be a more mature implementation of druntime 
for an STM32 MCU (ARM Cortex-M4) in minlibd [5].

I hope that gives you some of the information you were looking 
for.

Mike

[1] 
http://wiki.dlang.org/Minimal_semihosted_ARM_Cortex-M_%22Hello_World%22
[2] 
http://wiki.dlang.org/Bare_Metal_ARM_Cortex-M_GDC_Cross_Compiler
[3] https://www.youtube.com/watch?v=o5m0m_ZG9e8
[4] 
https://github.com/JinShil/D_Runtime_ARM_Cortex-M_study/wiki/1.3-Structs
[5] https://bitbucket.org/timosi/minlibd


More information about the Digitalmars-d mailing list