大家好,
我正在开发带有
STM32H7A3 MCU 和 MX66LM1G45G 128Mb OSPI 闪存的定制显示板。我已经按照教程使用 H7 参数构建了一个自定义外部加载器。我用JTAG来刷。
在 CubeIDE 或 CubeProgrammer (v2.7) 中使用我的 .stldr 自定义加载器时,它失败了。
以下是当我尝试使用外部加载程序刷新我的 .bin 应用程序(touchgfx 项目)时 CubeProgrammer 所说的内容:
[…]
w ap 0 @0x90000000 0x000D083C 字节数据 0x00000000 // 错误:无法下载段 [1]
对于使用外部加载器的 CubeIDE,它也会在 Segment[1] 处失败
(见附件的完整日志)
当我尝试使用 CubeProgrammer 读取 0x90000000 处的数据时,它也失败了(参见附件 log_cubeprogrammer_ReadData.log 文件)
我已经在我的板上的外部加载器(写入/读取/擦除)的 main.c 中成功测试了我的 OSPI 函数(没有外部加载器链接器修改)。
在我的 TouchGFX 应用项目中,我实现了相同的 OSPI 函数,并且还能够在内存映射模式下读取数据。
我不确定我的外部加载器中的链接器部分,我的猜测是问题出在这里。考虑到我的 STM32H7A3 默认在 STM32H7A3ZITX_FLASH.ld 中有一些 AXI_SRAM (0x24000000)/ AHB_SRAM (0x30000000),我不确定应该在哪个地址存储外部加载程序代码。RAM 在这个链接器中位于 0x20000000,只有 128KB(对于外部加载程序代码来说不够),所以最后我按照 H7 的示例,它说将加载程序代码存储在 0x24000004(与我的 RAM 来源和大小相同) TouchGFX 项目虽然)。
使用该链接器配置,我可以在调试模式下在 Loader_Src.c 中完成系统初始化 (Init())。
可能不是,但这是我的外部加载器和 TouchGFX 项目的链接器:
外部加载程序链接器:
- /* Entry Point */
- ENTRY(Init)
- /* Generate 2 segment for Loader code and device info */
- PHDRS {Loader PT_LOAD ; SgInfo PT_LOAD ; }
- /* Highest address of the user mode stack */
- _estack = ORIGIN(RAM_D1) + LENGTH(RAM_D1); /* end of RAM_D1 */
- /* Generate a link error if heap and stack don't fit into RAM_D1 */
- _Min_Heap_Size = 0x1000 ; /* required amount of heap */
- _Min_Stack_Size = 0x1000 ; /* required amount of stack */
- /* Specify the memory areas */
- MEMORY
- {
- RAM_D1 (xrw) : ORIGIN = 0x24000004, LENGTH = 1024K
- }
- /* Define output sections */
- SECTIONS
- {
- /* The startup code goes first into FLASH */
- .isr_vector :
- {
- . = . + 0x1FC;
- . = ALIGN(4);
- KEEP(*(.isr_vector)) /* Startup code */
- . = ALIGN(4);
- } >RAM_D1 :Loader
- .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >RAM_D1
- .ARM : {
- __exidx_start = .;
- *(.ARM.exidx*)
- __exidx_end = .;
- } >RAM_D1 :Loader
- .preinit_array :
- {
- PROVIDE_HIDDEN (__preinit_array_start = .);
- KEEP (*(.preinit_array*))
- PROVIDE_HIDDEN (__preinit_array_end = .);
- } >RAM_D1 :Loader
- .init_array :
- {
- PROVIDE_HIDDEN (__init_array_start = .);
- KEEP (*(SORT(.init_array.*)))
- KEEP (*(.init_array*))
- PROVIDE_HIDDEN (__init_array_end = .);
- } >RAM_D1 :Loader
- .fini_array :
- {
- PROVIDE_HIDDEN (__fini_array_start = .);
- KEEP (*(SORT(.fini_array.*)))
- KEEP (*(.fini_array*))
- PROVIDE_HIDDEN (__fini_array_end = .);
- } >RAM_D1 :Loader
- /* used by the startup to initialize data */
- _sidata = LOADADDR(.data);
- /* Initialized data sections goes into RAM_D1, load LMA copy after code */
- .data :
- {
- . = ALIGN(4);
- _sdata = .; /* create a global symbol at data start */
- *(.data) /* .data sections */
- *(.data*) /* .data* sections */
- . = ALIGN(4);
- _edata = .; /* define a global symbol at data end */
- } >RAM_D1 :Loader
- /* Uninitialized data section */
- . = ALIGN(4);
- .bss :
- {
- /* This is used by the startup in order to initialize the .bss secion */
- _sbss = .; /* define a global symbol at bss start */
- __bss_start__ = _sbss;
- *(.bss)
- *(.bss*)
- *(COMMON)
- . = ALIGN(4);
- _ebss = .; /* define a global symbol at bss end */
- __bss_end__ = _ebss;
- } >RAM_D1 :Loader
- /* The program code and other data goes into FLASH */
- .text :
- {
- . = ALIGN(4);
- *(.text) /* .text sections (code) */
- *(.text*) /* .text* sections (code) */
- *(.glue_7) /* glue arm to thumb code */
- *(.glue_7t) /* glue thumb to arm code */
- *(.eh_frame)
- KEEP (*(.init))
- KEEP (*(.fini))
- . = ALIGN(4);
- _etext = .; /* define a global symbols at end of code */
- } >RAM_D1 :Loader
- .Dev_info :
- {
- KEEP(*Dev_Inf.o ( .rodata* ))
- } :SgInfo
- /* Constant data goes into FLASH */
- .rodata :
- {
- . = ALIGN(4);
- *(.rodata) /* .rodata sections (constants, strings, etc.) */
- *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
- . = ALIGN(4);
- } >RAM_D1 :Loader
- /* User_heap_stack section, used to check that there is enough RAM_D1 left */
- ._user_heap_stack :
- {
- . = ALIGN(4);
- PROVIDE ( end = . );
- PROVIDE ( _end = . );
- . = . + _Min_Heap_Size;
- . = . + _Min_Stack_Size;
- . = ALIGN(4);
- } >RAM_D1 :Loader
- .ARM.attributes 0 : { *(.ARM.attributes) }
- }
TouchGFX 项目链接器:
- ENTRY(Reset_Handler)
- _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
- _Min_Heap_Size = 0x1000 ; /* required amount of heap */
- _Min_Stack_Size = 0x1000 ; /* required amount of stack */
- MEMORY
- {
- DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
- ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
- RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 1024K
- FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K
- OCTOSPI (r) : ORIGIN = 0x90000000, LENGTH = 128M
- }
- /* Sections */
- SECTIONS
- {
- /* The startup code into "FLASH" Rom type memory */
- .isr_vector :
- {
- . = ALIGN(4);
- KEEP(*(.isr_vector)) /* Startup code */
- . = ALIGN(4);
- } >FLASH
- .text :
- {
- . = ALIGN(4);
- *(.text) /* .text sections (code) */
- *(.text*) /* .text* sections (code) */
- *(.glue_7) /* glue arm to thumb code */
- *(.glue_7t) /* glue thumb to arm code */
- *(.eh_frame)
- KEEP (*(.init))
- KEEP (*(.fini))
- . = ALIGN(4);
- _etext = .; /* define a global symbols at end of code */
- } >FLASH
- /* Constant data into "FLASH" Rom type memory */
- .rodata :
- {
- . = ALIGN(4);
- *(.rodata) /* .rodata sections (constants, strings, etc.) */
- *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
- . = ALIGN(4);
- } >FLASH
- .ARM.extab : {
- . = ALIGN(4);
- *(.ARM.extab* .gnu.linkonce.armextab.*)
- . = ALIGN(4);
- } >FLASH
- .ARM : {
- . = ALIGN(4);
- __exidx_start = .;
- *(.ARM.exidx*)
- __exidx_end = .;
- . = ALIGN(4);
- } >FLASH
- .preinit_array :
- {
- . = ALIGN(4);
- PROVIDE_HIDDEN (__preinit_array_start = .);
- KEEP (*(.preinit_array*))
- PROVIDE_HIDDEN (__preinit_array_end = .);
- . = ALIGN(4);
- } >FLASH
- .init_array :
- {
- . = ALIGN(4);
- PROVIDE_HIDDEN (__init_array_start = .);
- KEEP (*(SORT(.init_array.*)))
- KEEP (*(.init_array*))
- PROVIDE_HIDDEN (__init_array_end = .);
- . = ALIGN(4);
- } >FLASH
- .fini_array :
- {
- . = ALIGN(4);
- PROVIDE_HIDDEN (__fini_array_start = .);
- KEEP (*(SORT(.fini_array.*)))
- KEEP (*(.fini_array*))
- PROVIDE_HIDDEN (__fini_array_end = .);
- . = ALIGN(4);
- } >FLASH
- /* Used by the startup to initialize data */
- _sidata = LOADADDR(.data);
- /* Initialized data sections into "RAM" Ram type memory */
- .data :
- {
- . = ALIGN(4);
- _sdata = .; /* create a global symbol at data start */
- *(.data) /* .data sections */
- *(.data*) /* .data* sections */
- . = ALIGN(4);
- _edata = .; /* define a global symbol at data end */
- } >RAM AT> FLASH
- . = ALIGN(4);
- .bss :
- {
- /* This is used by the startup in order to initialize the .bss section */
- _sbss = .; /* define a global symbol at bss start */
- __bss_start__ = _sbss;
- *(.bss)
- *(.bss*)
- *(COMMON)
- . = ALIGN(4);
- _ebss = .; /* define a global symbol at bss end */
- __bss_end__ = _ebss;
- } >RAM
- ._user_heap_stack :
- {
- . = ALIGN(8);
- PROVIDE ( end = . );
- PROVIDE ( _end = . );
- . = . + _Min_Heap_Size;
- . = . + _Min_Stack_Size;
- . = ALIGN(8);
- } >RAM
- /DISCARD/ :
- {
- libc.a ( * )
- libm.a ( * )
- libgcc.a ( * )
- }
- .ARM.attributes 0 : { *(.ARM.attributes) }
- ExtFlashSection :
- {
- *(ExtFlashSection ExtFlashSection.*)
- *(.gnu.linkonce.r.*)
- . = ALIGN(0x4);
- } >OCTOSPI
- FontFlashSection :
- {
- *(FontFlashSection FontFlashSection.*)
- *(.gnu.linkonce.r.*)
- . = ALIGN(0x4);
- } >OCTOSPI
- TextFlashSection :
- {
- *(TextFlashSection TextFlashSection.*)
- *(.gnu.linkonce.r.*)
- . = ALIGN(0x4);
- } >OCTOSPI
- }
0