gpt4 book ai didi

c - 如何初始化外部RAM中的变量?

转载 作者:行者123 更新时间:2023-11-30 18:44:40 25 4
gpt4 key购买 nike

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;

现在您必须创建/修改链接器脚本以将该部分放入 RAM 中:

MEMORY
{
...
ram_data (rwx) : ORIGIN = RAM_start_addr, LENGTH = section_length
...
}

SECTIONS
{
...

.mySection section_address :
{
KEEP(*(.ram))
} > ram_data

...
}

编译它,您的数据将被放置在 RAM 中。

关于c - 如何初始化外部RAM中的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57251840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com