Place variables at absolute address

Showing results for 
Search instead for 
Did you mean: 

Place variables at absolute address

Senior Contributor I

Hello to all of you!


I'm working with CW v6.1 and MCF51QE128. I've got a special section where I put constant data (user config). Till now, I didn't mind where the compiler puts those variables, as long as they were inside this section. Rigth now, the order matters to me.


First, I assume that the compiler will place the variables in the same order I declare them. If VAR1 is declared before VAR2, then VAR1 is in a smaller address than VAR2. But I found out that the compiler place them wherever it wants. I also try adding the @ but if I do, then the variable dissapears from xMAP.


Here's how I declare them and how they appear in the xMAP:


#pragma define_section _myDATA ".myDATA" far_absolute R

#pragma explicit_zero_data on

__declspec(_myDATA) dword FLASH_DATA_CHECKSUM;


__declspec(_myDATA) byte FLASH_USUARIO_ACTIVO = 0xFF;

__declspec(_myDATA) dword FLASH_CLAVE = 0xFFFFFFFF;




__declspec(_myDATA) byte ResetCounter = 0xFF;

__declspec(_myDATA) byte ForceDelAllCounter = 0x00;

__declspec(_myDATA) byte ATcmdNotRecogCounter = 0x00;

__declspec(_myDATA) byte ATcmdNoRtaCounter  = 0x00;

__declspec(_myDATA) byte FLASH_ALARM_STATE[4];

__declspec(_myDATA) byte FLASH_IGNICION_STATE[4];

__declspec(_myDATA) tSPAM FLASH_SPAM_list[dim_SPAM];

__declspec(_myDATA) dword FLASH_DATA_END;



# .myDATA

  00002800 00000001 .myDATA FLASH_USUARIO_ACTIVO (Grabaciones Flash.c)

  00002801 00000004 .myDATA FLASH_CLAVE (Grabaciones Flash.c)

  00002805 00000001 .myDATA ResetCounter (Grabaciones Flash.c)

  00002806 00000001 .myDATA ForceDelAllCounter (Grabaciones Flash.c)

  00002807 00000001 .myDATA ATcmdNotRecogCounter (Grabaciones Flash.c)

  00002808 00000001 .myDATA ATcmdNoRtaCounter (Grabaciones Flash.c)

  00002809 00000004 .myDATA FLASH_DATA_END (Grabaciones Flash.c)

  0000280D 00000050 .myDATA FLASH_SPAM_list (Grabaciones Flash.c)

  0000285D 00000004 .myDATA FLASH_IGNICION_STATE (Grabaciones Flash.c)

  00002861 00000004 .myDATA FLASH_ALARM_STATE (Grabaciones Flash.c)

  00002865 00000010 .myDATA FLASH_CONSULTA_SALDO_NUM (Grabaciones Flash.c)

  00002875 00000014 .myDATA FLASH_CONSULTA_SALDO_TXT (Grabaciones Flash.c)

  00002889 00000010 .myDATA FLASH_RECARGA_SALDO_NUM (Grabaciones Flash.c)

  00002899 000000A8 .myDATA FLASH_USUARIOS (Grabaciones Flash.c)

  00002941 00000004 .myDATA FLASH_DATA_CHECKSUM (Grabaciones Flash.c)



I hope someone can help me


Best Regards!



Labels (1)
0 Kudos
1 Reply

Senior Contributor I

I've been reading this thread but it is not exactly what I need, although it helped me.

Testing, I've found out that if I don't initialize the variables, then they are arranged upside down in memory: The first declared variable is at a higher memory address and the last declared variable is at the lowest address (section ini). But if I initialize one of them, the one that it is initialized appears first in memory (lower address).

Also, to avoid any other problem, I've declared all the variables so its length is multiple of 4. Just in case.

What I'd like to know is how to place a constant variable, inside a section and at a fixed address. Like using @ or : modifiers. If I use any of them, they dessapear from xMAP.

0 Kudos