Hi Brennen.
GNU C does allow you to put variables in a “user defined” section. These variables have to be global (defined above the function definition).
For example, here’s three variables defined as global and placed into the section USER1 by use of the “attribute” specification.
/************************************************************
Variables assigned to a user section
************************************************************/
unsigned int encoder_count attribute ((section(“USER1”))) = {0};
unsigned char marker_pulse attribute ((section(“USER1”))) = {0};
unsigned char direction attribute ((section(“USER1”))) = {0};
/**********************************************************
MAIN
**********************************************************/
int main (void) {
int j;
int a,b,c;
Now, in the linker command script, I will first identify where in flash I want to place the USER1 section. Note that I placed it in the last 8k block of flash memory.
/* specify the LPC2106 memory areas */
MEMORY
{
flash : ORIGIN = 0, LENGTH = 248K
user_flash : ORIGIN = 0x3E000, LENGTH = 8K
ram : ORIGIN = 0x00200000, LENGTH = 64K
}
Now, we have to create a linker output section and direct it’s placement into the “user_flash” memory area.
/* now define the output sections */
SECTIONS
{
. = 0;
.text : {
*(.text) *(.rodata) (.rodata) *(.glue_7) *(.glue_7t) _etext = .;
} >flash
.data : {
_data = .; *(.data)
_edata = .;
} >ram AT >flash
.bss :
{
_bss_start = .;
*(.bss) } >ram
.user :
{
_user_start = .;
*(USER1)
} >user_flash
. = ALIGN(4);
_bss_end = . ; }
_end = .;
Now if you compile and link this, these three variables appear in the last 8k block of flash. You would have to use the IAP routines at run time to update them, obviously.
.user 0x0003e000 0x8
0x0003e000 _user_start = .
*(USER1)
USER1 0x0003e000 0x8 main.o
0x0003e000 encoder_count
0x0003e005 direction
0x0003e004 marker_pulse
0x0003e008 . = ALIGN (0x4)
0x0003e008 _bss_end = .
0x0003e008 _end = .
Sorry that this is such a long description. You can see the advantage of the professional compilers; they usually have shortcuts available to do this more conveniently.
Cheers,
Jim Lynch