This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Linker Script and Assigning a value to a specific address

Hello,
I want to keep some variables in my code at certain addresses. For this, I created a new section in the LD file to reserve a certain area from the existing FLASH memory. I wait for the variable I created by typing __attribute__((section(".flash_rw.__at_0x000...))) to write to the address I specified. However, it writes the value to a completely different address in the section I created. I use arm-none-eabi-. GNU Arm Embedded Toolchain version 10 2021.10.

MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x40000 /* 256 KB ana Flash bellek */
FLASH_RW (rx) : ORIGIN = 0x00040000, LENGTH = 0x40000 /* 256 KB yazılabilir Flash bellek */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x18000 /* 96 KB RAM */
}

SECTIONS
{
    ....
    ....
    ....
    ....
    
    .flash_rw :
    {
        . = ORIGIN(FLASH_RW);
        __flash_rw_start__ = .;

        *(.flash_rw)
        *(.flash_rw.*)

        . = ALIGN(4);
        __flash_rw_end__ = .;
    } > FLASH_RW

unsigned short tristor50x35[584] __attribute__((section(".flash_rw.__at_0x0006A4CA"))) = 
{
	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x820,	0x842,	0x842,	0x842,
    ........
};

The output of the code is as follows;

Flash Address tristor50x35 => 0x00057b70

Top replies

Parents
  • non constant or forward reference address expression for section .abs_tristor50x35

        .flash_rw :
        {
            . = ORIGIN(FLASH_RW);
            __flash_rw_start__ = .;
    
            *(.flash_rw)
            *(.flash_rw.*)
    
            . = ALIGN(4);
            __flash_rw_end__ = .;
        } > FLASH_RW
    	
    	.abs_tristor50x35 ADDR_TRISTOR : { *(.flash_rw.__at_ADDR_TRISTOR) }

    #define ADDR_TRISTOR 0x0006A4CA
    
    unsigned short tristor50x35[584] __attribute__((section(".flash_rw.__at_ADDR50X35"))) = 
    {
    	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,
    	.....
    };

    I got an error like this.




    EDIT:

        .flash_rw :
        {
            . = ORIGIN(FLASH_RW);
            __flash_rw_start__ = .;
    
    		tristor50x35 = .; . += 1168; /* reserve 1168bytes for tristor50x35 */
    		. = ORIGIN(FLASH_RW) + 0x20000; /* 0x40000 + 0x20000 = 0x60000 */
    		tristor50x35 = .; 
    
            *(.flash_rw)
            *(.flash_rw.*)
    
            . = ALIGN(4);
            __flash_rw_end__ = .;
        } > FLASH_RW
        
        
        unsigned short tristor50x35[584] __attribute__((section(".flash_rw"))) = 
    {
    	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x820,	0x842,	0x842,	0x842,
    };
    
    output => Flash Address tristor50x35 => 0x00060000
    
    It was solved this way. It will be a bit challenging for all the variables.

Reply
  • non constant or forward reference address expression for section .abs_tristor50x35

        .flash_rw :
        {
            . = ORIGIN(FLASH_RW);
            __flash_rw_start__ = .;
    
            *(.flash_rw)
            *(.flash_rw.*)
    
            . = ALIGN(4);
            __flash_rw_end__ = .;
        } > FLASH_RW
    	
    	.abs_tristor50x35 ADDR_TRISTOR : { *(.flash_rw.__at_ADDR_TRISTOR) }

    #define ADDR_TRISTOR 0x0006A4CA
    
    unsigned short tristor50x35[584] __attribute__((section(".flash_rw.__at_ADDR50X35"))) = 
    {
    	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,
    	.....
    };

    I got an error like this.




    EDIT:

        .flash_rw :
        {
            . = ORIGIN(FLASH_RW);
            __flash_rw_start__ = .;
    
    		tristor50x35 = .; . += 1168; /* reserve 1168bytes for tristor50x35 */
    		. = ORIGIN(FLASH_RW) + 0x20000; /* 0x40000 + 0x20000 = 0x60000 */
    		tristor50x35 = .; 
    
            *(.flash_rw)
            *(.flash_rw.*)
    
            . = ALIGN(4);
            __flash_rw_end__ = .;
        } > FLASH_RW
        
        
        unsigned short tristor50x35[584] __attribute__((section(".flash_rw"))) = 
    {
    	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x0,	0x820,	0x842,	0x842,	0x842,
    };
    
    output => Flash Address tristor50x35 => 0x00060000
    
    It was solved this way. It will be a bit challenging for all the variables.

Children
No data