STM32F103C8T6 ARM STM32 Minimum System Development Board
September 13, 2020
libmaple -- linker scripts
Libmaple comes with a dandy set of linker scripts.
I am trying to learn from them and set up my own to properly handle
BSS variables as well a variables in the data section.
This is a topic I have always skimmed over and intended to look at
carefully some day, and maybe that day has come.
I ran across the above series doing a search on linker script tutorials.
Odd addresses
You may have noticed an odd thing (bad pun), that addresses in branches and jump tables
are odd and actually point one byte beyond where they should.
The reason is that the low bit actually indicates that the processor should branch
and execute in "thumb" mode once it branches.
For a processor like the M3 this should always be the case.
Startup code
After coming out of reset, the processor could immediately begin executing C code.
However, in order to set up the execution environment that is usually expected,
and number of things ought to be done first:
- Copy value of intialized variables from flash to ram.
- Zero the bss section in ram.
A lot of other stuff can go on during startup (but since I am writing my own code
I have control over that). When using libmaple, which also uses "newlib" there are
all kinds of things going on, some related to C++ constructors.
Linker script
Most C programmers take this for granted, and it is hidden away inside the usual compile and link
sequence. C programmers working with embedded systems may need to at least be aware of it and to
set it up properly.
When all was said and done, it was not hard at all to put together a more proper lds file,
and to add a routine "startup.c" that gets called before main() and initializes data in RAM that
needs to be initialized.
Strings
An interesting business is string constants. The compile puts these into .rodata, so it is easy to gather
them up and put them into flash. So the following strings would go into flash:
puts ( "This goes into flash!" );
char *msg = "This goes into flash also!!";
No need to drag "const" into this. I find this nice, since I have plenty of strings and having them get
tucked away in flash is ideal.
Feedback? Questions?
Drop me a line!
Tom's Computer Info / [email protected]