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.

MSP430FR5994 FRAM固定地址读写数据

Expert 2115 points


使用下面代码定义数组到FRAM中,数组不能写入数据,一直为0

#pragma LOCATION(data, 0x10000);
#pragma PERSISTENT(data);
uint16_t dataRecorded1[1024] = {0};

但是将#pragma LOCATION(data, 0x10000) 注释掉后就可以正常读写,这是为什么?

  • #pragma location 的用法:

    #pragma location = {address | register | NAME} 
    该指令用处

    1. 定位该指令之后的全局或静态变量到指定的absolute address上。其中变量必须定义为__no_init。 
      pragma location = address 等价于 @ address,其中变量也必须定义为__no_init 。 
      示例: 
      __no_init volatile char alpha @ 0xFF2000 
      运用绝对地址定位,还需注意地址的对齐问题。

    2. 定位该指令之后的变量到指定寄存器中,其中该变量必须声明为__no_init,同时该变量的作用域为整个文件。 
      ===========register(寄存器R4-R11) 
      pragma location = register 等价于 @ register,其中变量也必须定义为__no_init

    3. 将该指令之后的函数或变量放置到一个指定的section中。其中,不要试图将那些通常放在不同section的变量放置在同一section中。 
      =============NAME(A user-defined section name; cannot be a section name predefined for use by the compiler and linker. 
      pragma location = section 等价于 @ section

    示例 
    变量放置在自定义的section中。 
    __no_init int alpha @ “MY_NOINIT”; /* OK */ 
    #pragma location=”MY_CONSTANTS” 
    const int beta; /* OK */

    函数放置在自定义section中。 
    void f(void) @ “MY_FUNCTIONS”; 
    void g(void) @ “MY_FUNCTIONS” 


    #pragma location=”MY_FUNCTIONS” 
    void h(void);

    1. #pragma required = symbol 
      #pragma required确保链接输出中包括某个符号所需的另一个符号。该指令必须放在紧邻第二个符号的前边。如果符号在应用中不可见,使用该指令。例如,如果仅通过某个变量所在的段对其进行间接引用,必须使用#pragma required。 
      eg: 
      const char copyright[] = “Copyright by me”; 
      #pragma required=copyright 
      int main() 

      /* Do something here. */ 

      Even if the copyright string is not used by the application, it will still be included by the 
      linker and available in the output.
  • #pragma LOCATION(data, 0x10000);  这样定义应该没错啊,我在示例代码中也见到了这种定义方法,调试运行可以看到data的地址确实是0x10000 ,但是不能写入,所以读取一直为0


    PERSISTENT 换成 NOINIT 也可以正常编译,但是不能写入,而且读取一直为0xFF



  • 是啊,我也遇到了同样的问题