gpt4 book ai didi

c - 在链接器文件STM32中添加一个RAM段

转载 作者:行者123 更新时间:2023-12-05 06:00:06 40 4
gpt4 key购买 nike

我非常努力地尝试了解如何使用链接器文件,但我的大脑显然根本不了解它。我使用的是 STM32L476,它有两个 RAM 区域,RAM 和 RAM2(下面的内存定义)。我想将缓冲区放入 RAM2,但在 Cube 生成的默认链接描述文件中没有用于 RAM2 的部分。对我来说似乎是一个很好的锻炼。我真的认为以下内容可以解决问题,我添加的只是 .sensor_buffer 部分:

/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */

_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */

/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
}

/* Sections */
SECTIONS
{
.sensor_buffer :
{
KEEP(*(.sensor_buffer))
} >RAM2

/* The startup code into "RAM" Ram type memory */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >RAM

/* The program code and other data into "RAM" Ram type memory */
.text :
{
...
} >RAM

// Other Cube-generated sections here
}

但是,这会向不在 RAM2 中的地址添加一个 .sensor_buffer 部分。来自 .map 文件:

...
.igot.plt 0x0000000020000190 0x0 load address 0x000000000800f29c
.igot.plt 0x0000000020000190 0x0 c:/st/stm32cubeide_1.6.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/thumb/v7e-m+fp/hard/crtbegin.o

.sensor_buffer 0x0000000020000190 0x2000 load address 0x000000000800f29c
.sensor_buffer
0x0000000020000190 0x2000 Core/Src/main.o
0x0000000020002190 . = ALIGN (0x4)

.bss 0x0000000020002190 0x1fb0 load address 0x000000000801129c
0x0000000020002190 _sbss = .
0x0000000020002190 __bss_start__ = _sbss
...

有人可以指出我在这里哪里出错了,和/或更好的是,我可以通过一些“简单”的例子来适应 LD 吗?我真的很想得到这些东西,但是第一步对我来说真的很残酷,除了一组相当密集的手册页之外没有任何资源。

编辑 添加用于声明缓冲区的代码。在 main.c 中,全局作用域:

static uint8_t data[DATA_BUFFERS][DATA_SIZE] __attribute__((section(".sensor_buffer")));

最佳答案

你在其他地方有错误。也许你根本就没有使用这个链接器脚本(你忘了在命令行中添加或更改名称)

我已经编译它并将它链接到 CubeIDE 没有任何问题(我在缓冲区声明中使用 100 和 100 因为我不知道你的宏 [100x100 = 0x2710] 的值)

.sensor_buffer  0x0000000010000000     0x2710
*(.sensor_buffer)
.sensor_buffer
0x0000000010000000 0x2710 Core/Src/main.o

.isr_vector 0x0000000020000000 0x0
0x0000000020000000 . = ALIGN (0x4)

关于c - 在链接器文件STM32中添加一个RAM段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67860784/

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