Setting Target Memory Location for Compiled Library

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Setting Target Memory Location for Compiled Library

ソリューションへジャンプ
1,632件の閲覧回数
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,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 件の賞賛
返信
2 返答(返信)
1,481件の閲覧回数
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,480件の閲覧回数
dataScout
NXP Employee
NXP Employee


Hello,

Which target processor are you using?

Regards

0 件の賞賛
返信