Calling section addresses from C
I'm using CrossStudio 1.3 for MSP430, and want to use the start and end of my CODE section in my C code. I've tried using &__CODE_end__ without success. Have I got a wrong character somewhere, or does this not work in my version?
Thanks John
-
Hello Paul,
I should add that I'm also trying to use the address in my header file to setup my data memory size:
#define START_DATA 0x1200 // must start & end on 512 byte boundary
#define END_DATA &___CODE_start___ //0xac00 // make sure this matches memory map file!
#define MSP430_MEMSIZE (END_DATA - START_DATA)/512
Perhaps it doesn't work in this way?John
-
Hello John -
Unrelated to your specific question, but - it is always a good idea to enclose any complex #define with (), like this :
#define MSP430_MEMSIZE ((END_DATA - START_DATA)/512)
Been bitten by this once or twice. You are probably safe with this one, since your subtraction is already enclosed, and multiply/divide is left-to-right; but it's good practice anyway and does no harm. -
Thanks Paul,
I got there after a bit of trial and error. My code now looks like:
extern unsigned char __begin_CODE[]; // two underscores, and __begin_CODE, __end_CODE, not CODE_start
// Address limits of data memory
#define START_DATA 0x1200 // must start & end on 512 byte boundary
#define END_DATA (unsigned int)__begin_CODE //0xac00 // make sure this matches memory map file!
#define MSP430_MEMSIZE ((END_DATA - START_DATA)/512)However, every time I use MSP430_MEMSIZE, it does the full calculation, which adds quite a bit to my code size, as compared to putting in a number for the start of code. Is there any way of persuading the compiler and linker to just do the calculation once at build time, because the sections don't change thereafter?
Thanks, John
-
that is true from C code, not from assembler code, yoy can just add
public _CODE_Size_CODE_Size equ ___end_CODE - ___begin_CODEpublic _CODE_Size
_CODE_Size equ ___end_CODE - ___begin_CODE
in assembler there are allways one _ character more than in C
into an assembler code (or just modify crt0.asm if you do not use any)
then in your C code add
extern unsigned int CODE_size (no underscore here), and use &CODE_size as the size of your code not the value (that has no sense due it is a label not a real variable)
Please sign in to leave a comment.
Comments
9 comments