Relocation without __declspec keyword

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Relocation without __declspec keyword

Jump to solution
2,767 Views
markusa
Contributor I

Hello,

I am trying to program a bootloader-application combination at MPC5643L using CodeWarrior 10.5.

Bootloader and application communicate by a shared structure therefore the pointer to this structure must be located to a fixed address.

The access to the structure members via this pointer is located in various other files which are being shared with other projects so it's difficult to change the declaration of the variable.

So here's my question:

Is it possible to locate a variable (in RAM) on a defined address without using the __declspec keyword ?

 

I tried this:

volatile tTableStruct TheTableStruct;  #pragma push #pragma section RW ".ptrTableStruct" volatile tTableStruct *TableStruct = &TheTableStruct; #pragma pop 

 

It compiles but the section ".ptrTableStruct" is empty and the pointer "TableStruct" is located somewhere in RAM.

 

Then I tried this:

volatile tTableStruct TheTableStruct;  #pragma push #pragma section data_type ".ptrTableStruct" volatile tTableStruct *TableStruct = &TheTableStruct; #pragma pop 

This leads to an linker error:

sections used for data must have an uninitialized data section in line #1

 

Thank you,

Markus

Labels (1)
0 Kudos
Reply
1 Solution
1,988 Views
stanish
NXP Employee
NXP Employee

Hello markusa,

The pragma section  requires also uninitialized section parameter to add  for  the  data sections.

If you have a small data threshold set to a default value which is 8 you should add also "sdata_type" parameter in order to place the pointer into your custom section.

Could you try to adjust the pragma section:

volatile tTableStruct TheTableStruct;

#pragma push 

#pragma section data_type sdata_type ".ptrTableStruct" ".ptrTableStruct"

volatile tTableStruct *TableStruct = &TheTableStruct; 

#pragma pop 

Hope it helps.

Stan

View solution in original post

0 Kudos
Reply
8 Replies
1,988 Views
PedroBecerra
Contributor III

On older versions of codewarrior it works like:

extern volatile tTableStruct  TableStruct @0xAAAAAAAA;  

// where 0xAAAAAAAA is the addres you want your struct be placed.

volatile tTableStruct  TableStruct;

0 Kudos
Reply
1,988 Views
stanish
NXP Employee
NXP Employee

Pedro,

FYI: The "@" operator does not work in PowerPC version of compiler (CodeWarrior for MCUs).

It is applicable e.g. for S08, CFv1 targets.

Stan

0 Kudos
Reply
1,989 Views
stanish
NXP Employee
NXP Employee

Hello markusa,

The pragma section  requires also uninitialized section parameter to add  for  the  data sections.

If you have a small data threshold set to a default value which is 8 you should add also "sdata_type" parameter in order to place the pointer into your custom section.

Could you try to adjust the pragma section:

volatile tTableStruct TheTableStruct;

#pragma push 

#pragma section data_type sdata_type ".ptrTableStruct" ".ptrTableStruct"

volatile tTableStruct *TableStruct = &TheTableStruct; 

#pragma pop 

Hope it helps.

Stan

0 Kudos
Reply
1,988 Views
markusa
Contributor I

Hello Stanislav,

thank you - this solves the error.

Maybe you can help me with the 2nd issue too ...

The variable "TableStruct" is used in several (shared) files.

To access the variable I use the following code in each C-source file:

extern volatile tTableStruct* TableStruct;

But to be able to use these files with CW and other compilers I have to change it to:

#if defined(__COMPILER_CODEWARRIOR_ECLIPSE__)

#pragma push

#pragma section sdata_type ".ptrTableStruct" ".ptrTableStruct"

extern volatile tTableStruct *TableStruct;

#pragma pop

#else

extern volatile tTableStruct* TableStruct;

#endif

Do you think there is a better solution ?

Thank you for your time,

Markus

0 Kudos
Reply
1,988 Views
stanish
NXP Employee
NXP Employee

Hi Markus,

there is an alternative way which does not require #pragma push/pop (so you can use a macro):

the "test.h" header file:

#pragma section RW ".ptrTableStruct" ".ptrTableStrct"  // defines a custom section to be used with __declspec(section ...)

#define CW_DEF __declspec(section ".ptrTableStruct")   // Create custom __declspec() macro   

#if __CWCC__   // internal compiler macro to identify CodeWarrior Compiler

CW_DEF extern volatile tTableStruct *TableStruct;

#else

extern volatile  char* TableStruct;

#endif

a source file where table is defined:

#include "test.h"

CW_DEF volatile tTableStruct *TableStruct;

Hope it helps.

Stan

0 Kudos
Reply
1,988 Views
markusa
Contributor I

thx for the info.

0 Kudos
Reply
1,988 Views
Wlodek_D_
Senior Contributor II

Dear markusa,

Thank you for your post, however please consider moving it to the right community place (e.g. CodeWarrior Development Tools ) for better visibility.

For details please see general advice https://community.freescale.com/docs/DOC-99909

Thank you for using Freescale Community.

Regards,

Wlodek_D.

0 Kudos
Reply
1,988 Views
markusa
Contributor I

Hello Wlodek,

thank you for the information.

I've moved the post to the correct community place.

Best regards,

Markus

0 Kudos
Reply