cancel
Showing results for 
Search instead for 
Did you mean: 

i would like to know how linker commands can be used in source file to push the multiple structure defines into a part of code memory. can some body share with examples

Anand Ram
Associate III

steps i tried.

step 1: created a section in linker file ".parambuf"

step2: in source file declared a structure

typedef struct{ param_t param[256]; \

} t_param_block_t;

step 3: in header files using attributes commands to push into parambuf section.

extern t_param_block_t t_param_block0 __attribute__ ((section (".parambuf")));

step 4: hereby i defined a structure by filling its values.

t_param_block_t t_param_block0 __attribute__((section(".parambuf"))) =

{

 {  

  1,20,30,40,50,60,70,80,90,a0,b0,c0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

 }

};

but this doesn't work, according to my tricore infineon experience with linker, #pragma commands must be used before and after the defines, but for stm32 anybody knows how can be used?

1 ACCEPTED SOLUTION

Accepted Solutions

Which compiler and which linker are you using? You shouldn't need to do your "step 3", and your "step 4" should work. We do something similar with gcc and gnu ld to get the exception vector table in the right spot. In the linker script:

// stm32g474.ld
MEMORY
{
    FLASH(RX)     : ORIGIN = 0x08000000, LENGTH = 0x80000
}
 
SECTIONS
{
    .vector_table :
    {
        KEEP (*(.vector_table))
    } >FLASH
 
    ...
}

And in the source code:

#define __SECTION__(s)  __attribute__((section(s)))
 
typedef void (*exception_handler)();
 
static const exception_handler vector_table[16+102]
    __SECTION__(".vector_table") =
{
    ...
};

We do a similar thing to put code sections in SRAM for functions used in reflashing the MCU for live firmware updates, but those use the __SECTION__ attribute on the function instead of on a global like you are trying to do. It works great in both cases, so I think you are pretty close. Maybe check that the ".parambuf" section is defined correctly in the linker file and that the linker file being used is the right one?

View solution in original post

1 REPLY 1

Which compiler and which linker are you using? You shouldn't need to do your "step 3", and your "step 4" should work. We do something similar with gcc and gnu ld to get the exception vector table in the right spot. In the linker script:

// stm32g474.ld
MEMORY
{
    FLASH(RX)     : ORIGIN = 0x08000000, LENGTH = 0x80000
}
 
SECTIONS
{
    .vector_table :
    {
        KEEP (*(.vector_table))
    } >FLASH
 
    ...
}

And in the source code:

#define __SECTION__(s)  __attribute__((section(s)))
 
typedef void (*exception_handler)();
 
static const exception_handler vector_table[16+102]
    __SECTION__(".vector_table") =
{
    ...
};

We do a similar thing to put code sections in SRAM for functions used in reflashing the MCU for live firmware updates, but those use the __SECTION__ attribute on the function instead of on a global like you are trying to do. It works great in both cases, so I think you are pretty close. Maybe check that the ".parambuf" section is defined correctly in the linker file and that the linker file being used is the right one?