在链接器文件STM32中添加一个RAM段
Adding a RAM section in linker file STM32
我非常努力地想了解如何使用链接器文件,但我的大脑显然根本不了解它。我使用的是 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
...
有人能指出我哪里出错了吗,and/or,更好的是,我可以通过一些“简单”的例子来适应 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)
我非常努力地想了解如何使用链接器文件,但我的大脑显然根本不了解它。我使用的是 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
...
有人能指出我哪里出错了吗,and/or,更好的是,我可以通过一些“简单”的例子来适应 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)