Startup files for STM32F4xx

Johannes Pfau via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 25 10:11:21 PDT 2015


Am Sat, 25 Apr 2015 11:38:45 +0000
schrieb "Martin Nowak" <code at dawg.eu>:

> On Saturday, 25 April 2015 at 05:07:04 UTC, Jens Bauer wrote:
> > I hope to find a good way to use import for microcontroller 
> > libraries, so it'll be easy for everyone. I'm thinking about 
> > something like ...
> >
> > import mcu.stm32f439.all
> 
> I think that belongs in the makefile/dub.json as 
> -version=STM32F439.
> Then you could simply import mcu.gpio or mcu.spi.

We need a better / clever generic approach to solve 'board
configuration' issues. Here version blocks work but you might also
want to specify other configuration options (clock speed if
static, ...) and we don't have -D to define constants.

I think we could use 'reverse' imports but I'm not sure if it's a
horrible hack or a great idea:



When compiling library code:

// board.di (Only 'runtime' config variables)
-------------------------------------------------
module board.config;
__gshared const int configA;
__gshared const int configB;
-------------------------------------------------

//library code: lib.d
-------------------------------------------------
import board.config;

void doFoo() // Function => runtime value
{
    auto a = configA;
}

void templateFoo()() // Template => ctfe value
{
    auto b = ctfeConfigA; //This value is not in .di => error if
    //template is instantiated in the library
}
-------------------------------------------------

gdc lib.d -Ipath/for/board.di -o lib.o


User code:
// board.d ('runtime' + 'ctfe' config variables)
-------------------------------------------------
module board.config;
__gshared const int configA = 42;
__gshared const int configB = 42;
enum ctfeConfigA = 42;
-------------------------------------------------

gdc lib.o board.d


More information about the Digitalmars-d-learn mailing list