第一种,通过增加LDFLAGS
使用外部需要配置修改导出的makefile,
比如,
uint32_t g_test_buffer[250000] __attribute__((section(".exsram")));其中 .exsram为外部ram,地址为 0x68000000,
那么,
makefile中的链接器部分需要增加选项,
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -Wl,--section-start=.exsram=0x68000000其中,-Wl—section-start=.exsram=0x68000000 -u _printf_float 为增加的选项,
- -Wl,:这是一个前缀,告诉编译器后面的选项是为链接器准备的。
- —section-start:链接器选项,用于设置段的起始地址。
- .exsram:这是段的名称。在这个上下文中,.exsram 是一个自定义的段名,用于指定应该放置在外部SRAM中的代码或数据。
- 0x68000000:段在内存中的起始地址。这个地址必须是一个有效的内存地址,且通常需要与目标硬件平台的内存布局相匹配。
这样设置好后直接可以编译,.ld脚本文件中无需再次设置。
第二种,修改 .ld脚本的方法
STM32F103ZETx_FLASH.ld
...
/* Specify the memory areas */MEMORY{RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64KFLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512KEXTRAM (rx) : ORIGIN = 0x68000000, LENGTH = 1M}
...
SECTIONS{ ... .exsram : /* External SRAM */ { *(.exsram) *(.exsram*) _exsram_end = .; } > EXTRAM
...}程序中即可使用
uint32_t g_test_buffer[250000] __attribute__((section(".exsram")));无需修改Makefile.
来源:CSDN 原文,首次发布于 2024-09-04。