Relocating Data in Internal RAM

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

Relocating Data in Internal RAM

Jump to solution
1,386 Views
makarand_phadke
Contributor I

New RAM Section "myCodeInRAM" is created in the ram and i am  able to assign specific object to this memory section with below code.

#pragma section  ".myCodeInRAM" data_mode=far_abs __declspec(section ".myCodeInRAM") unsigned char data0;

Now i have Number of variables which need to be assigned to this section. Is there a mechanism by which i can avoid specifying  __declspec(section ".myCodeInRAM") as prefix for every variable?

Labels (1)
Tags (1)
0 Kudos
1 Solution
1,121 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

I found the root cause of your problem. You have to place the declaration of the variables to the pragma. So delete the pragma from file SPIR_Interface.c and place it to SPIR_Interface.h

In SPIR_Interface C will be following code:

uint16_t VaSPIR_Cnt_CellVolt[360];
uint16_t VaSPIR_Cnt_CellVoltPEC[120];
uint16_t VeSPIR_Cnt_StrVolt;
uint8_t VeSPIR_Cnt_StrVoltSt;
uint16_t VeSPIR_Cnt_LinkVolt;
uint8_t VeSPIR_Cnt_LinkVoltSt;

and in SPIR_Interface.h will be:

#pragma push                                                                                                                                                        
#pragma section all_types ".__my_ram" ".__my_ram" data_mode=far_abs code_mode=far_abs

extern uint16_t VaSPIR_Cnt_CellVolt[360];
extern uint16_t VaSPIR_Cnt_CellVoltPEC[120];
extern uint16_t VeSPIR_Cnt_StrVolt;
extern uint8_t VeSPIR_Cnt_StrVoltSt;
extern uint16_t VeSPIR_Cnt_LinkVolt;
extern uint8_t VeSPIR_Cnt_LinkVoltSt;

                                                                            

#pragma pop 

Regards,

Martin

View solution in original post

9 Replies
1,121 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

I am not able to reproduce your issue on my side. Could you please create simple example and post it here? I will try to investigate deeper. From the files you shared, I am not able to reproduce it.

I tried to use your variables and insert to my project. I had to place the variables to FORCEACTIVE in linker file because of linker garbage collector, but I see the variables placed in correct section.

Regards,

Martin

0 Kudos
1,121 Views
makarand_phadke
Contributor I

Hello martin,

As Requested I am attaching Sample project. Following are observation.

I have used #pragma section in Main.c file. All that variable are correctly allocated in RAM

Same #pragma used in BSW/SPIR_Interface.c However at this time those variables are assigned to .bss Section

Appreciate all your Support.

Thanks and Best Regards,

Makarand Phadke

Embedded Software Engineer

0 Kudos
1,122 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

I found the root cause of your problem. You have to place the declaration of the variables to the pragma. So delete the pragma from file SPIR_Interface.c and place it to SPIR_Interface.h

In SPIR_Interface C will be following code:

uint16_t VaSPIR_Cnt_CellVolt[360];
uint16_t VaSPIR_Cnt_CellVoltPEC[120];
uint16_t VeSPIR_Cnt_StrVolt;
uint8_t VeSPIR_Cnt_StrVoltSt;
uint16_t VeSPIR_Cnt_LinkVolt;
uint8_t VeSPIR_Cnt_LinkVoltSt;

and in SPIR_Interface.h will be:

#pragma push                                                                                                                                                        
#pragma section all_types ".__my_ram" ".__my_ram" data_mode=far_abs code_mode=far_abs

extern uint16_t VaSPIR_Cnt_CellVolt[360];
extern uint16_t VaSPIR_Cnt_CellVoltPEC[120];
extern uint16_t VeSPIR_Cnt_StrVolt;
extern uint8_t VeSPIR_Cnt_StrVoltSt;
extern uint16_t VeSPIR_Cnt_LinkVolt;
extern uint8_t VeSPIR_Cnt_LinkVoltSt;

                                                                            

#pragma pop 

Regards,

Martin

1,121 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

you can use following construction:

#pragma push

#pragma section all_types ".__myRAM" ".__myRAM"

unsigned int my_var1;
unsigned int my_var2;
unsigned int my_var3;

#pragma pop

Instead of all_types you can specify section data type, for example data_type, sdata_type, etc.

If you have any other questions, please feel free to write me back.

Regards,

Martin

1,121 Views
makarand_phadke
Contributor I

Hello Martin,

Below Solution did not work. I tried with both sdata_type and data_type. Linker is placing this variables in “.bss” section instead of ".__myRAM"

Does it require some Compiler setting?

Thanks and Best Regards,

Makarand Phadke

0 Kudos
1,121 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

please look at the example in the attachment (do not forget about linker file). If you look to the map file, you will see that variables are placed to correct section.

pastedImage_1.png

Regards,

Martin

0 Kudos
1,121 Views
makarand_phadke
Contributor I

Replicating the same changes in my Project however it does not work. Please find attached related files for your reference.

Thanks and Best Regards,

Makarand Phadke

0 Kudos
1,121 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

because you mix different data types (not all of them are sdata) in your section, I recommend you to use #pragma section all_types ".__myRAM" ".__myRAM" instead of sdata_type.

Regards,

Martin

0 Kudos
1,121 Views
makarand_phadke
Contributor I

Used all_types as suggested still the same results. No variable is assigned to ".__my_ram" section.

#pragma push

#pragma section all_types ".__my_ram" ".__my_ram" data_mode=far_abs code_mode=far_abs

0 Kudos