Creating a microcontroller startup file
Mike via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Apr 8 04:17:08 PDT 2015
On Tuesday, 7 April 2015 at 20:33:26 UTC, Jens Bauer wrote:
>
> Question number 2: Is it possible to change the VectorFunc to
> be a real function pointer, rather than a void* ?
>
I did something along these lines (modified to match your
example) and it worked fine for me:
alias VectorFunc = void function();
@attribute("weak") @attribute("alias", "defaultHandler")
extern void Reset_Handler();
@attribute("weak") @attribute("alias", "defaultHandler")
extern void NMI_Handler()
@attribute("weak") @attribute("alias", "defaultHandler")
extern void HardFault_Handler();
@attribute("section",".isr_vector.ro")
immutable ISR[3] g_pfnVectors =
[
&Reset_Handler
, &NMI_Handler
, &HardFault_Handler
];
I did this before "weak", "alias", and "section" attributes were
added, however. To see my original code, look at the slide in
the presentation here: https://youtu.be/o5m0m_ZG9e8?t=2332. My
original code had everything decorated with extern(C) as well so
I could refer to the symbol directly in my linker scripts. That
may not be needed for you, so I left it out.
> Question number 3: How can I call an external function and keep
> the binary file size down ?
Are you compiling with -ffunction-sections -fdata-sections and
linking with --gc-sections? You may need to in order to get rid
of some things.
What do you using for your D runtime? Perhaps some code in your
runtime is implicitly linking to some code you're not directly
calling.
I also add the following to my linker scripts to get rid of stuff
I don't find necessary:
/DISCARD/ :
{
*(.ARM.extab*)
*(.ARM.exidx*)
}
/DISCARD/ :
{
*(.ARM.attributes*)
*(.comment)
}
You can see the latest incarnation of my linker script here:
https://github.com/JinShil/stm32f42_discovery_demo/blob/master/linker/linker.ld
> Question number 4: How can I reduce the function declaration of
> the Reset_Handler and NMI_Handler shown above ?
Try something along these lines.
enum weak = gcc.attribute.attribute("weak");
enum isrDefault = gcc.attribute.attribute("alias",
"defaultHandler");
extern @weak @isrDefault void NMI_Handler();
extern @weak @isrDefault void HardFault_Handler();
I use this idiom briefly in my code here:
https://github.com/JinShil/stm32f42_discovery_demo/blob/master/source/start.d
The enum thing kinda bugs me about D, but you'll see it used
everywhere, especially phobos. It's called a manifest constant,
and you can find a short blurb about it at the bottom of this
page: http://dlang.org/enum.html
Mike
More information about the Digitalmars-d-learn
mailing list