This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Starterware/MSP430FR6972: the question of using " __persistent"

Part Number: MSP430FR6972

Tool/software: Starterware

Hello, sir

I want to use "__persistent" to initialize variable to FRAM  and stop to the value lose when power supply drop. the code is following

 

__persistent int xx = 0;
__persistent unsigned char cc[10]= {0x0A};
int main(void)
{
  WDTCTL = WDTPW | WDTHOLD;                 // Stop WDT

  P7OUT &= ~BIT0;                           // Clear P7.0 output latch for a defined power-on state
  P7DIR |= BIT0; 
  P7OUT &= ~BIT1;                           // Clear P7.1 output latch for a defined power-on state
  P7DIR |= BIT1; 
  for(unsigned char j= 0; j<10;j++)
  {
     if(cc[j] == j )  
// LED0 blink {P7OUT ^= BIT0;} __delay_cycles(100000); } if(xx == 5) {
//LED1 open P7OUT |= BIT1; } xx =5; for(unsigned char i= 0; i<10;i++ ) { cc[i] = i; } }

After power failure ,I found  that LED0 didn't blink  and LED1 be lighten  when the power supply again . I think the LED0 shoud blink when the power supply again . why?

the content of lnkmsp430fr6972.xcl is:

-Z(CONST)DATA16_P,DATA20_P=7000-FF7F
-Z(DATA)DATA16_HEAP+_DATA16_HEAP_SIZE
-Z(DATA)DATA20_HEAP+_DATA20_HEAP_SIZE

  • Hello Jent,

    Are you sure that the pin is not just blinking faster than you can recognize it? You are only supplying a delay of 100 ms 10 times, so for 1 second LED0 will rapidly toggle 10 times. This may look more like the LED turning on at half power before turning off a second later.

    I don't have much experience with IAR persistent values, but in CCS you have to declare an array as persistent before defining its length. However the IAR MSP430 C/C++ Compiler User Guide has a valid example of this type for __no_init as well as a #pragma example on page 312:

    e2e.ti.com/.../1745169
    www.ti.com/.../slaa628.pdf
    ftp.iar.se/.../EW430_CompilerReference.pdf

    Regards,
    Ryan
  • Hi Ryan

    Thank you for your help ,I tried a delay of 500ms, it didn't blink yet.However I found the values of array stored in the FRAM was correct when the power supply again. so I think that pointer of array will change when the power supply again .Is it like the malloc function??

    Regards
    Jent
  • Hi Jent,

    If the value of the FRAM array is correct then your issue lies in another part of your system. Check that the LED pin is not somehow shorted to GND. I also noticed that you are missing PM5CTL0 &= ~LOCKLPM5; which disables the GPIO power-on default high-impedance mode to activate previously configured port settings and is required in order to drive the IOs properly.

    Regards,
    Ryan
  • Thank you Ryan ,
    I found the problem too. Missing PM5CTL0 &= ~LOCKLPM5 caused the problem . I chalked it up to a rookie mistake. . .
    I do appreciate your help very much!

    Best regards
    Jent

**Attention** This is a public forum