MSP430FR5969: #pragma SET_DATA_SECTION(".fram_vars") variables cannot be modified

Part Number: MSP430FR5969

Tool/software:

I'm using #pragma SET_DATA_SECTION(".fram_vars") to declare variables in FRAM. However, I am not able to modify such variables in real time. I add a dummie code to demonstrate. The array "w2" gets some initial values, but then I want to modify these values.

#pragma SET_DATA_SECTION(".fram_vars")
volatile unsigned char w2[10][2]={0};

#pragma SET_DATA_SECTION()

// Función para inicializar el arreglo con valores específicos
void init_array()
{
unsigned char w2_init[10][2]={
{15, 103},

{137, 154},

{146, 152},

{217, 70},

{114, 251},

{6, 6},

{71, 27},

{122, 109},

{41, 220},

{237, 232}};

for(int i=0;i<10;i++)
{
for(int j=0;j<2;j++)
{
w2[i][j] = w2_init[i][j];
}
}
}
void GPIO_init(void)
{
// Configure GPIO
P1OUT = 0;
P1DIR = 0xFF;

P2OUT = 0;
P2DIR = 0xFF;

P3OUT = 0;
P3DIR = 0xFF;

P4OUT = 0;
P4DIR = 0xFF;

PJOUT = 0;
PJDIR = 0xFFFF;

//PM5CTL0 |= LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
PM5CTL0 &= ~LOCKLPM5; // to activate previously configured port settings
CSCTL0_H = CSKEY >> 8; // Unlock CS registers
CSCTL1 |= DCORSEL;
CSCTL1 |= DCOFSEL_4; // Set DCO to 16MHz if DCORSEL=1
//CSCTL1 |= DCOFSEL_6; // Set DCO to 8MHz if DCORSEL=0,
/*CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Set SMCLK = MCLK = DCO
// ACLK = VLOCLK
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // set all dividers
CSCTL0_H = 0; */ // Lock CS registers
FRCTL0 = FRCTLPW | NACCESS_1; // Cambia el valor NACCESS_x para agregar la cantidad correcta de estados de espera

}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
GPIO_init();
init_array();
volatile unsigned char dummie=0;
volatile unsigned char d=0;
dummie = w2[3][1];
for(int i=0;i<10;i++)
{
for(int j=0;j<2;j++)
{
dummie=w2[i][j];
w2[i][j]=92;
d=w2[i][j];
}

}
return 0;
}

  • You didn't mention changing the linker (msp430fr5969.cmd) file. Unless you did, it doesn't know anything about your .fram_vars section, and probably gave you a warning. When I just tried it, the linker assigned address 0x0010 to the section, which is in a reserved area of the SFRs, and so is not (reliably) writable.

    If you're looking to put w2 into a writable area of FRAM, I suggest making it Persistent with something like:

    > #pragma PERSISTENT("w2")  // FRAM and writable

    This will put w2 into a section called ".TI.persistent", which the linker .cmd file places in a writable area in low FRAM. (You can see how this is done in the .cmd file.)

    [Edit: Fixed typo.]

  • Hi, 

    Thanks for your answer. I did change the linker. However, when I tried to rewrite the variable, it did not change its value. Anyways, your suggestion seems to solve the problem. Thank you very much.

**Attention** This is a public forum