Help with embedded code linking

David Brown david@westcontrol.com
Mon Jul 21 12:46:00 GMT 2014


(This is not really a gcc question - more of a general or embedded C
question.  You might like to discuss it on then comp.lang.c or
comp.arch.embedded newsgroups.)


While this sort of thing /can/ be done using linker and library magic,
it is often better to use an indirection table - it helps keep the parts
independent.

Make one "base" program containing all the common code.  Then you can
have multiple "application" programs that can be updated.  It is up to
you whether the "base" program has the "main()" function and calls the
application code as needed, or whether the "application" programs are
the main programs and call functions in the "base" code as needed
(either way can work).

A program that is exporting a set of functions will then have a struct
typedef with a list of pointers, such as:

typedef struct {
	int versionInfo;
	void (*fooP)(void);
	int (*barP)(int a, int b);
} exportTable_t;


The exporting code will define the table:

const exportTable_t exportTable = {
	0x00000001,
	&foo,
	&bar
}

And the importing code will use the table:

extern const exportTable_t exportTable;
#define foo exportTable.fooP
#define bar exportTable.barP


Then the importing program can use the external functions as "x = bar(y,
z);".

Of course, the importing and exporting code need to agree on where the
table is placed - that can be a fixed location, or an initialisation
parameter sent from one to the other (the definitions above have to be
adjusted to suit the method).  But the fixed format and single location
means it is much easier to mix and match the base code and the
application code.





On 21/07/14 12:17, Grzesiek Gajoch wrote:
> Thanks for reply,
> faster programmer is not a option - programming is done via WiFi (it
> has to be done that way).
> Yes, that's what I want to do - but the question is how to tell the
> linker about libraries (which are already somewhere in memory)?
> Pozdrawiam,
> 
>          Grzegorz Gajoch
> 
> 
> 
> 2014-07-21 11:53 GMT+02:00 Niklas Gürtler <profclonk@gmail.com>:
>> That is possible by placing the library in one part of the flash via a
>> linker script, and the remainder of the code in another part.
>> Alternatively you could buy a faster programming device such as Segger
>> J-Link which can flash even big microcontrollers in <1s ...
>>
>> On 21.07.2014 11:37, Grzesiek Gajoch wrote:
>>> Hi all,
>>> My "problem" is as follows:
>>> I have relatively big code for STM32 microcontroller (~300KB binary file).
>>> Every time I want to test new software version I have to recompile all
>>> of it and then reflash whole memory (which takes time).
>>>
>>> I have a question:
>>> is it possible to compile "library" part of code (it does not change
>>> but takes a lot of memory) and burn it in static place in memory,
>>> when compiling "user" code (it uses functions from library) tell the
>>> linker somehow to map jumps to part of memory where the lib is (i.e.
>>> take the adresses from memory map of staticly burned lib) - the goal
>>> is to place it in "user" place in memory (and only reflash this part).
>>>
>>> Thanks for replay and help!
>>> Best regards,
>>>
>>>          Grzegorz Gajoch
>>
> 



More information about the Gcc-help mailing list