返回列表 发新帖我要提问本帖赏金: 50.00元(功能说明)

[活动] 【APM32F411V开发板测评】SRAM启动RT-Thread

[复制链接]
 楼主| xhackerustc 发表于 2024-5-13 23:10 | 显示全部楼层 |阅读模式
本帖最后由 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如下:
  1. /*
  2. * linker script for APM32F411 with GNU ld
  3. */

  4. /* Program Entry, set to mark it as "used" and avoid gc */
  5. MEMORY
  6. {
  7.     DATA (rxw) : ORIGIN = 0x20000000, LENGTH = 128k  /* 128KB sram */
  8. }
  9. ENTRY(Reset_Handler)
  10. _system_stack_size = 0x200;

  11. SECTIONS
  12. {
  13.     .text :
  14.     {
  15.         . = ALIGN(4);
  16.         _stext = .;
  17.         KEEP(*(.apm32_isr_vector))      /* Startup code */
  18.         . = ALIGN(4);
  19.         *(.text)                        /* remaining code */
  20.         *(.text.*)                      /* remaining code */
  21.         *(.rodata)                      /* read-only data (constants) */
  22.         *(.rodata*)
  23.         *(.glue_7)
  24.         *(.glue_7t)
  25.         *(.gnu.linkonce.t*)

  26.         /* section information for finsh shell */
  27.         . = ALIGN(4);
  28.         __fsymtab_start = .;
  29.         KEEP(*(FSymTab))
  30.         __fsymtab_end = .;
  31.         . = ALIGN(4);
  32.         __vsymtab_start = .;
  33.         KEEP(*(VSymTab))
  34.         __vsymtab_end = .;
  35.         . = ALIGN(4);

  36.         /* section information for initial. */
  37.         . = ALIGN(4);
  38.         __rt_init_start = .;
  39.         KEEP(*(SORT(.rti_fn*)))
  40.         __rt_init_end = .;
  41.         . = ALIGN(4);

  42.         . = ALIGN(4);
  43.         _etext = .;
  44.     } > DATA

  45.     /* .ARM.exidx is sorted, so has to go in its own output section.  */
  46.     __exidx_start = .;
  47.     .ARM.exidx :
  48.     {
  49.         *(.ARM.exidx* .gnu.linkonce.armexidx.*)

  50.         /* This is used by the startup in order to initialize the .data secion */
  51.         _sidata = .;
  52.         _start_address_init_data = .;
  53.     } > DATA
  54.     __exidx_end = .;

  55.     /* .data section which is used for initialized data */

  56.     .data :
  57.     {
  58.         . = ALIGN(4);
  59.         /* This is used by the startup in order to initialize the .data secion */
  60.         _sdata = . ;
  61.         _start_address_data = .;

  62.         *(.data)
  63.         *(.data.*)
  64.         *(.gnu.linkonce.d*)

  65.         . = ALIGN(4);
  66.         /* This is used by the startup in order to initialize the .data secion */
  67.         _edata = . ;
  68.         _end_address_data = .;
  69.     } >DATA

  70.     .stack :
  71.     {
  72.         . = . + _system_stack_size;
  73.         . = ALIGN(4);
  74.         _estack = .;
  75.         _end_stack = .;
  76.     } >DATA

  77.     __bss_start = .;
  78.     _start_address_bss = .;
  79.     .bss :
  80.     {
  81.         . = ALIGN(4);
  82.         /* This is used by the startup in order to initialize the .bss secion */
  83.         _sbss = .;

  84.         *(.bss)
  85.         *(.bss.*)
  86.         *(COMMON)

  87.         . = ALIGN(4);
  88.         /* This is used by the startup in order to initialize the .bss secion */
  89.         _ebss = . ;

  90.         *(.bss.init)
  91.     } > DATA
  92.     __bss_end = .;
  93.     _end_address_bss = .;

  94.     _end = .;

  95.     /* Stabs debugging sections.  */
  96.     .stab          0 : { *(.stab) }
  97.     .stabstr       0 : { *(.stabstr) }
  98.     .stab.excl     0 : { *(.stab.excl) }
  99.     .stab.exclstr  0 : { *(.stab.exclstr) }
  100.     .stab.index    0 : { *(.stab.index) }
  101.     .stab.indexstr 0 : { *(.stab.indexstr) }
  102.     .comment       0 : { *(.comment) }
  103.     /* DWARF debug sections.
  104.      * Symbols in the DWARF debugging sections are relative to the beginning
  105.      * of the section so we begin them at 0.  */
  106.     /* DWARF 1 */
  107.     .debug          0 : { *(.debug) }
  108.     .line           0 : { *(.line) }
  109.     /* GNU DWARF 1 extensions */
  110.     .debug_srcinfo  0 : { *(.debug_srcinfo) }
  111.     .debug_sfnames  0 : { *(.debug_sfnames) }
  112.     /* DWARF 1.1 and DWARF 2 */
  113.     .debug_aranges  0 : { *(.debug_aranges) }
  114.     .debug_pubnames 0 : { *(.debug_pubnames) }
  115.     /* DWARF 2 */
  116.     .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
  117.     .debug_abbrev   0 : { *(.debug_abbrev) }
  118.     .debug_line     0 : { *(.debug_line) }
  119.     .debug_frame    0 : { *(.debug_frame) }
  120.     .debug_str      0 : { *(.debug_str) }
  121.     .debug_loc      0 : { *(.debug_loc) }
  122.     .debug_macinfo  0 : { *(.debug_macinfo) }
  123.     /* SGI/MIPS DWARF 2 extensions */
  124.     .debug_weaknames 0 : { *(.debug_weaknames) }
  125.     .debug_funcnames 0 : { *(.debug_funcnames) }
  126.     .debug_typenames 0 : { *(.debug_typenames) }
  127.     .debug_varnames  0 : { *(.debug_varnames) }
  128. }
然后修改bsp/apm32/apm32f411v-tinyboard/rtconfig.py使用sram版本的link script如下:
  1. diff --git a/bsp/apm32/apm32f411v-tinyboard/rtconfig.py b/bsp/apm32/apm32f411v-tinyboard/r
  2. tconfig.py
  3. index 37b0d21d3a..e354b55a49 100644
  4. --- a/bsp/apm32/apm32f411v-tinyboard/rtconfig.py
  5. +++ b/bsp/apm32/apm32f411v-tinyboard/rtconfig.py
  6. @@ -46,7 +46,7 @@ if PLATFORM == 'gcc':
  7.      DEVICE = ' -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sect
  8. ions -fdata-sections'
  9.      CFLAGS = DEVICE + ' -Dgcc'
  10.      AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -Wa,-mimplicit-it=thumb '
  11. -    LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rt-thread.map,-cref,-u,Reset_Handler -T board/linker_scripts/link.lds'
  12. +    LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rt-thread.map,-cref,-u,Reset_Handler -T board/linker_scripts/link_ram.lds'

  13.      CPATH = ''
  14.      LPATH = ''
再修改下bsp/apm32/libraries/APM32F4xx_Library/Device/Geehy/APM32F4xx/Source/system_apm32f4xx.c,定义VECT_TAB_SRAM
  1. --- a/bsp/apm32/libraries/APM32F4xx_Library/Device/Geehy/APM32F4xx/Source/system_apm32f4xx.c
  2. +++ b/bsp/apm32/libraries/APM32F4xx_Library/Device/Geehy/APM32F4xx/Source/system_apm32f4xx.c
  3. @@ -43,7 +43,7 @@
  4. /* #define DATA_IN_ExtSRAM */

  5. /* Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */
  6. -/* #define VECT_TAB_SRAM */
  7. +#define VECT_TAB_SRAM


编译后再由pyocd加载进sram重启就能丝般顺滑地从sram启动RT-Thread了

打赏榜单

Gfan 打赏了 50.00 元 2024-07-17
理由:APM32F411V Tiny测评活动优质测评帖

szt1993 发表于 2024-5-23 17:54 | 显示全部楼层
SRAM启动RT-Thread与flash启动有什么区别?
 楼主| xhackerustc 发表于 2024-5-23 22:14 | 显示全部楼层
功能没区别,但是sram启动免去烧写flash的过程
[鑫森淼焱垚] 发表于 2024-5-24 19:16 来自手机 | 显示全部楼层
优秀
星辰大海不退缩 发表于 2024-6-22 20:43 | 显示全部楼层
一般默认是sram启动吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

42

主题

165

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部

42

主题

165

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部