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.

msp430fr5739 FRAM读写问题

Other Parts Discussed in Thread: MSP430FR5739

 普通学生,最近在做东西的时候对fram的读写的C语言程序很迷糊,请问应该学习些什么?

  • 以下链接是WIKI上提供的相关MSP430FR5739 FRAM的Training供参考。
    processors.wiki.ti.com/.../MSP430_FR57xx_Training_Workshop
  • 建议先运行下官网例程,通过例程来学习


  • #if defined(__TI_COMPILER_VERSION__)
    #pragma PERSISTENT(FRAM_write)
    unsigned long FRAM_write[WRITE_SIZE] = {0};
    #elif defined(__IAR_SYSTEMS_ICC__)
    __persistent unsigned long FRAM_write[WRITE_SIZE] = {0};
    #elif defined(__GNUC__)
    unsigned long __attribute__((persistent)) FRAM_write[WRITE_SIZE] = {0};                    //???????
    #else
    #error Compiler not supported!
    #endif

    请问例程代码这段宏定义中的__((persistent)) FRAM_write[WRITE_SIZE] = {0};   有什么意义,不太理解,查阅数据手册说的很模糊

  • Here is example code which should show you how to use data in FRAM.

    #include <msp430.h>
    
    #define WRITE_SIZE      128
    
    void FRAMWrite(void);
    
    unsigned char count = 0;
    unsigned long data;
    
    #if defined(__TI_COMPILER_VERSION__)
    #pragma PERSISTENT(FRAM_write)
    unsigned long FRAM_write[WRITE_SIZE] = {0};
    #elif defined(__IAR_SYSTEMS_ICC__)
    __persistent unsigned long FRAM_write[WRITE_SIZE] = {0};
    #elif defined(__GNUC__)
    unsigned long __attribute__((persistent)) FRAM_write[WRITE_SIZE] = {0};
    #else
    #error Compiler not supported!
    #endif
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;               // Stop WDT
    
        // Configure GPIO
        P1OUT &= ~BIT0;                         // Clear P1.0 output latch for a defined power-on state
        P1DIR |= BIT0;                          // Set P1.0 to output direction
    
        // Disable the GPIO power-on default high-impedance mode to activate
        // previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        // Initialize dummy data
        data = 0x00010001;
    
        while(1)
        {
            data += 0x00010001;
            FRAMWrite();
            count++;
            if (count > 100)
            {
                P1OUT ^= 0x01;                  // Toggle LED to show 512K bytes
                count = 0;                      // ..have been written
                data = 0x00010001;
            }
        }
    }
    
    void FRAMWrite(void)
    {
        unsigned int i = 0;
    
        for (i = 0; i < WRITE_SIZE; i++)
        {
            FRAM_write[i] = data;
        }
    }
    

  • 你看到前面的#if defined没? 一般编译器如CCS,运行你这段程序时只会执行这句#pragma PERSISTENT(FRAM_write) 在FRAM中生成地址的。同理unsigned long __attribute__((persistent)) FRAM_write[WRITE_SIZE] = {0};  的作用同#pragma PERSISTENT(FRAM_write) 只是编译器不同罢了。

  • 条件编译看见了,能详细说一下FRAM_write[WRITE_SIZE] = {0},这句么?
  • 这个没什么好纠结的吧?就像定义一个向量一样,a[n]={0}.
  • 就是定义一个数组,每个元素都是0