This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
Hey all,
I am trying to figure out the best way that I can reference in code the start address and length of a memory section defined in the linker file.
I have found a way to do this, but it seems a little hacky and I was wondering if there is a cleaner way to do it.
As an example, I would have the following in my linker file:
#define TEST_ADDRESS_LOC 0x15000 #define TEST_ADDRESS_LEN 0x1000 TEST_ADDRESS = TEST_ADDRESS_LOC; MEMORY { TEST_SECTION: origin = TEST_ADDRESS_LOC, length = TEST_ADDRESS_LEN } SECTIONS { .testSection : {} > TEST_SECTION type=NOINIT }
and then in code I would define
extern volatile unsigned long TEST_ADDRESS;
and use TEST_ADDRESS as my origin pointer (very similar to how the compiler maps the register addresses).
While this gets the job done, is there a cleaner way to do this where I don't have to use the variables (where i can just access the sections start address and length without having to define it in two places in the linker file), or is there a way I can assign the value of TEST_ADDRESS to the origin of TEST_SECTION?
How about this? Put these lines ...
Christopher Carl said:#define TEST_ADDRESS_LOC 0x15000
#define TEST_ADDRESS_LEN 0x1000
... in header file. #include that header in both the C code and the linker command file. Then change this ...
Christopher Carl said:extern volatile unsigned long TEST_ADDRESS;
to something like ...
volatile unsigned long *special_pointer = TEST_ADDRESS_LOC;
Then you don't need the variable TEST_ADDRESS.
Changing topics. And this is a minor thing, but I thought I would point it out. This ...
Christopher Carl said:TEST_SECTION: origin = TEST_ADDRESS_LOC, length = TEST_ADDRESS_LEN
... is not a section, but a memory range. So it would be more clear if you used the name TEST_MEMORY_RANGE instead of TEST_SECTION.
Thanks and regards,
-George