Embedded Systems (STM32) LDC Absolute minimal runtime
Mike Franklin
slavo5150 at yahoo.com
Fri Apr 6 00:21:31 UTC 2018
On Thursday, 5 April 2018 at 15:58:28 UTC, Cora Dias wrote:
> Hi...i am a new user here.
Welcome!
> As per my observation as suggested above you need a minimal
> runtime implementation that implements the features of D that
> your code is using, some that your code is not using but is
> required by the compiler just to get a build.
Yeah, so D can be both a systems programming language and an
applications programming language, and it's even convenient
enough to use a scripting language :-) But that means that it
has both high level and low level features.
If you want to do bare-metal programming on the STM32 (or any
resource-constrained micrcontroller), you may not want or need
things like the garbage collector, runtime type information, etc.
(though with something like the STM32F7, it may be the right
choice). To do the low-level stuff, you just need the fundamental
compiler facilities, and not much, if anything, from the runtime.
So, you have a few options:
1) The -betterC switch - This switch allows you to use D like C.
No classes, No runtime-type information, no exceptions, but you
still get the compiler facilities like templates, mixins, etc.
that aren't found in C. Thus it is a "better C". See
https://dlang.org/spec/betterc.html and
https://dlang.org/blog/category/betterc/ for lots of information
about that.
I am, personally, not a fan of betterC, and affectionately call
it worseD. IMO, if the compiler would just be fixed to reduce
coupling to the runtime (as was done recently in 2.079.0) betterC
would not be needed.
2) A v2.079.0 compliant compiler - 2.079.0 did some long overdue
decoupling of the compiler from the runtime so you no longer get
compiler errors for missing features that your code doesn't even
make use of. See
https://dlang.org/changelog/2.079.0.html#minimal_runtime for more
information about that.
3) A pre-2.079.0 version of a compiler with useless stubs to get
the compiler to shut up and generate your binary. Trying to make
a minimal runtime with the current LDC release is fraught with
problems: (1) https://github.com/ldc-developers/ldc/issues/781
(2) https://github.com/ldc-developers/ldc/issues/552 GDC is much
better, but still requires a few useless stubs to get a build
(e.g.
https://github.com/JinShil/stm32f42_discovery_demo/blob/master/source/runtime/object.d)
LDC is currently working on adding the 2.079.0 features:
https://github.com/ldc-developers/ldc/pull/2641 I hope it will
be in the next LDC release. When that's done it will be a much
better competitor with GDC (and may even surpass it) when it
comes to ARM Cortex-M programming in D. I'm currently trying to
find a way to contribute to GDC to accelerate its progress, but I
have a lot to learn.
A few resource which you may find interesting:
https://bitbucket.org/timosi/minlibd - probably the most complete
port of the D runtime to the ARM Cortex-M platform. I think it's
only compatible with GDC at the moment though.
https://github.com/JinShil/stm32f42_discovery_demo - A proof of
concept illustrating the bare-metal programming ARM Cortex-M
microcontrollers without the need for -betterC, opting for
minimal runtime instead, is feasible.
https://forum.dlang.org/post/qjowkuwstewnmdunepiq@forum.dlang.org, https://theartofmachinery.com/2018/04/02/inheritance_and_polymorphism.html - A very cool way of using D's mixin features to simulate classes without the D runtime.
I hope that will give you some of what you were looking for.
Mike
More information about the Digitalmars-d
mailing list