使用下面代码定义数组到FRAM中,数组不能写入数据,一直为0
#pragma LOCATION(data, 0x10000);
#pragma PERSISTENT(data);
uint16_t dataRecorded1[1024] = {0};
但是将#pragma LOCATION(data, 0x10000) 注释掉后就可以正常读写,这是为什么?
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.
#pragma location 的用法:
#pragma location = {address | register | NAME}
该指令用处
定位该指令之后的全局或静态变量到指定的absolute address上。其中变量必须定义为__no_init。
pragma location = address 等价于 @ address,其中变量也必须定义为__no_init 。
示例:
__no_init volatile char alpha @ 0xFF2000
运用绝对地址定位,还需注意地址的对齐问题。
定位该指令之后的变量到指定寄存器中,其中该变量必须声明为__no_init,同时该变量的作用域为整个文件。
===========register(寄存器R4-R11)
pragma location = register 等价于 @ register,其中变量也必须定义为__no_init
将该指令之后的函数或变量放置到一个指定的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);