本帖最后由 xhackerustc 于 2024-5-13 23:20 编辑
与https://bbs.21ic.com/icview-3375412-1-1.html 一样也是充分利用APM32F411大sram的特性,在开发阶段尽可能避免烧写flash,从而加快开发验证速度和延长flash寿命。只不过上次帖子是裸机程序,这次换成RT-Thread RTOS的bring up和开发,本帖所用原理对于其它芯片bring up RT-Thread时同样适用。在第三个测评贴我们已经在RT-Thread主线仓库中bring up好一个基本的系统,有uart和gpio,那么接下来SPI、ADC、I2C这些在RT-Thread中一个一个bring up过程其实可以分块测试,并由sram启动。到最后把所有外设bsp都bring up完毕后再整合起来,烧录flash后全部验证一次。
方法和上次帖子基本差不多,重点是添加一个适合于sram用的RT-Thread link script,基于目前已有的bsp/apm32/apm32f411v-tinyboard/board/linker_scripts/link.lds比较简单,删除section对于FLASH的使用全挪进SRAM中,笔者改好的bsp/apm32/apm32f411v-tinyboard/board/linker_scripts/link_ram.lds如下:
/*
* linker script for APM32F411 with GNU ld
*/
/* Program Entry, set to mark it as "used" and avoid gc */
MEMORY
{
DATA (rxw) : ORIGIN = 0x20000000, LENGTH = 128k /* 128KB sram */
}
ENTRY(Reset_Handler)
_system_stack_size = 0x200;
SECTIONS
{
.text :
{
. = ALIGN(4);
_stext = .;
KEEP(*(.apm32_isr_vector)) /* Startup code */
. = ALIGN(4);
*(.text) /* remaining code */
*(.text.*) /* remaining code */
*(.rodata) /* read-only data (constants) */
*(.rodata*)
*(.glue_7)
*(.glue_7t)
*(.gnu.linkonce.t*)
/* section information for finsh shell */
. = ALIGN(4);
__fsymtab_start = .;
KEEP(*(FSymTab))
__fsymtab_end = .;
. = ALIGN(4);
__vsymtab_start = .;
KEEP(*(VSymTab))
__vsymtab_end = .;
. = ALIGN(4);
/* section information for initial. */
. = ALIGN(4);
__rt_init_start = .;
KEEP(*(SORT(.rti_fn*)))
__rt_init_end = .;
. = ALIGN(4);
. = ALIGN(4);
_etext = .;
} > DATA
/* .ARM.exidx is sorted, so has to go in its own output section. */
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
/* This is used by the startup in order to initialize the .data secion */
_sidata = .;
_start_address_init_data = .;
} > DATA
__exidx_end = .;
/* .data section which is used for initialized data */
.data :
{
. = ALIGN(4);
/* This is used by the startup in order to initialize the .data secion */
_sdata = . ;
_start_address_data = .;
*(.data)
*(.data.*)
*(.gnu.linkonce.d*)
. = ALIGN(4);
/* This is used by the startup in order to initialize the .data secion */
_edata = . ;
_end_address_data = .;
} >DATA
.stack :
{
. = . + _system_stack_size;
. = ALIGN(4);
_estack = .;
_end_stack = .;
} >DATA
__bss_start = .;
_start_address_bss = .;
.bss :
{
. = ALIGN(4);
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .;
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(4);
/* This is used by the startup in order to initialize the .bss secion */
_ebss = . ;
*(.bss.init)
} > DATA
__bss_end = .;
_end_address_bss = .;
_end = .;
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF debug sections.
* Symbols in the DWARF debugging sections are relative to the beginning
* of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
}
然后修改bsp/apm32/apm32f411v-tinyboard/rtconfig.py使用sram版本的link script如下:
diff --git a/bsp/apm32/apm32f411v-tinyboard/rtconfig.py b/bsp/apm32/apm32f411v-tinyboard/r
tconfig.py
index 37b0d21d3a..e354b55a49 100644
--- a/bsp/apm32/apm32f411v-tinyboard/rtconfig.py
+++ b/bsp/apm32/apm32f411v-tinyboard/rtconfig.py
@@ -46,7 +46,7 @@ if PLATFORM == 'gcc':
DEVICE = ' -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sect
ions -fdata-sections'
CFLAGS = DEVICE + ' -Dgcc'
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -Wa,-mimplicit-it=thumb '
- LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rt-thread.map,-cref,-u,Reset_Handler -T board/linker_scripts/link.lds'
+ LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rt-thread.map,-cref,-u,Reset_Handler -T board/linker_scripts/link_ram.lds'
CPATH = ''
LPATH = ''
再修改下bsp/apm32/libraries/APM32F4xx_Library/Device/Geehy/APM32F4xx/Source/system_apm32f4xx.c,定义VECT_TAB_SRAM
--- a/bsp/apm32/libraries/APM32F4xx_Library/Device/Geehy/APM32F4xx/Source/system_apm32f4xx.c
+++ b/bsp/apm32/libraries/APM32F4xx_Library/Device/Geehy/APM32F4xx/Source/system_apm32f4xx.c
@@ -43,7 +43,7 @@
/* #define DATA_IN_ExtSRAM */
/* Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */
-/* #define VECT_TAB_SRAM */
+#define VECT_TAB_SRAM
编译后再由pyocd加载进sram重启就能丝般顺滑地从sram启动RT-Thread了
|