Question

For an embedded system I need to place a few data structures at fixed addresses, so that a separate control CPU can access them at a known location. I'm using linker scripts for the embedded target to accomplish this, plus #defines of those same addresses for the control CPU.

It bothers me that these address constants are therefore defined in two places, the linker script and a header file. I'd like to have just one. The best solution I've come up with so far is to have the Makefile run cpp on the linker script, allowing it to #include the same header.

Is there a better way to accomplish this? Is there some little-known option to ld or a naming convention for the linker script which will automatically run it through cpp?

Was it helpful?

Solution

This isn't quite the solution you are looking for but one option is to utilize the build system to configure these values. Create a config.h.in and a target.ld.in which acts as templates and have the build system produce a config.h with the correct define and a target.ld with the correct address for the target you are building.

We use CMake for our embedded systems and it supports this kind of thing. GNU autoconf does too but I never really liked it personally.

OTHER TIPS

You could use the emdedded-C specific construct @ to place an object anywhere in the address space.

static struct SOMESTRUCT somestruct @ 0x40000000;
extern int someextint @ 0x3ffffffc;
char somebuffer[77] @ 0x80000000;

Assuming a 32-bit MCU.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top