如何初始化外部RAM中的变量?
How to initialize the variables in external RAM?
typedef struct test {
int a;
int b;
int c;
}_test;
__ext_ram__ _test test1 = {0}; // Declared this global variable in external RAM
我们是否需要使用 memset() 在外部 RAM 中对其进行初始化?
memset(&test1, 0, sizeof(_test));
您的链接器会为您做这件事。所以首先你定义你的变量(即你的结构)。之后声明变量并使用 section
参数将变量放置在给定部分:
_test __attribute__((section (".ram"))) MyStruct;
现在您必须 create/modify 您的链接描述文件以将该部分放入您的 RAM 中:
MEMORY
{
...
ram_data (rwx) : ORIGIN = RAM_start_addr, LENGTH = section_length
...
}
SECTIONS
{
...
.mySection section_address :
{
KEEP(*(.ram))
} > ram_data
...
}
编译它,你的数据被放置在 RAM 中。
typedef struct test {
int a;
int b;
int c;
}_test;
__ext_ram__ _test test1 = {0}; // Declared this global variable in external RAM
我们是否需要使用 memset() 在外部 RAM 中对其进行初始化?
memset(&test1, 0, sizeof(_test));
您的链接器会为您做这件事。所以首先你定义你的变量(即你的结构)。之后声明变量并使用 section
参数将变量放置在给定部分:
_test __attribute__((section (".ram"))) MyStruct;
现在您必须 create/modify 您的链接描述文件以将该部分放入您的 RAM 中:
MEMORY
{
...
ram_data (rwx) : ORIGIN = RAM_start_addr, LENGTH = section_length
...
}
SECTIONS
{
...
.mySection section_address :
{
KEEP(*(.ram))
} > ram_data
...
}
编译它,你的数据被放置在 RAM 中。