Setting Target Memory Location for Compiled Library

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Setting Target Memory Location for Compiled Library

跳至解决方案
1,631 次查看
jimfell
Contributor III

I've compiled the Freescale USB stack (v4.0.2) as a library, and I'd like to specify its location in memory on the target, so that it can be used by both the main application code and our bootloader.  Is there a way to do this without adding `#pragma define_section` to all of the source files in the stack and `__declspec (section_name)` to every function and variable declarations in the USB stack source?  I'm using CodeWarrior 10.2.  Thanks.

标签 (1)
0 项奖励
回复
1 解答
1,479 次查看
jimfell
Contributor III

My apologies for not posting this sooner, but I was able to resolve the problem on my own using function pointers.  For example, let's say function MyFunc needs to be addressed at 0x00000300:

typedef void (*fpMyFunc_t)(void);

extern const fpMyFunc_t fpMyFunc @ 0x00000300; // Additional function pointers can be added at offsets of 4 bytes

Function MyFunc is located somewhere in source, let's say it's in a file called file.c.  The following then needs to be added to the linker command file:

FORCE_ACTIVE { _MyFunc } # prevents linker from deadstripping the function, now that it's not directly called

SECTIONS {

...

  .text_MyFunc : # A separate section is needed for each function to be addressed

  {

    OBJECT (_MyFunc, file_c.obj)

    . = ALIGN (0x4);

  } >> code

...

  .my_vectors :

  {

   WRITEW(ADDR(.text_MyFunc));

    # Additional function pointers may be assigned here 

  } >> myfunctionvectors # defined in MEMORY section of LCF

}

Now, at link time the address of MyFunc will be assigned to the function pointer fpMyFunc, which effectively acts as an alias for MyFunc without having to change the source file in which MyFunc is actually located.  I know that there may be a couple other ways to do this, but this implementation suits our needs.

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,480 次查看
jimfell
Contributor III

My apologies for not posting this sooner, but I was able to resolve the problem on my own using function pointers.  For example, let's say function MyFunc needs to be addressed at 0x00000300:

typedef void (*fpMyFunc_t)(void);

extern const fpMyFunc_t fpMyFunc @ 0x00000300; // Additional function pointers can be added at offsets of 4 bytes

Function MyFunc is located somewhere in source, let's say it's in a file called file.c.  The following then needs to be added to the linker command file:

FORCE_ACTIVE { _MyFunc } # prevents linker from deadstripping the function, now that it's not directly called

SECTIONS {

...

  .text_MyFunc : # A separate section is needed for each function to be addressed

  {

    OBJECT (_MyFunc, file_c.obj)

    . = ALIGN (0x4);

  } >> code

...

  .my_vectors :

  {

   WRITEW(ADDR(.text_MyFunc));

    # Additional function pointers may be assigned here 

  } >> myfunctionvectors # defined in MEMORY section of LCF

}

Now, at link time the address of MyFunc will be assigned to the function pointer fpMyFunc, which effectively acts as an alias for MyFunc without having to change the source file in which MyFunc is actually located.  I know that there may be a couple other ways to do this, but this implementation suits our needs.

0 项奖励
回复
1,479 次查看
dataScout
NXP Employee
NXP Employee


Hello,

Which target processor are you using?

Regards

0 项奖励
回复