eric2013 发表于 2020-9-18 00:53:02

STM32H7的MDK汇编启动代码__main,__initial_sp,__Vectors等在C里面的调用方法



AC5是在cmsis_armcc.h文件夹
AC6是在cmsis_armclang.h文件夹

/* #########################Startup and Lowlevel Init######################## */

#ifndef __PROGRAM_START
#define __PROGRAM_START         __main
#endif

#ifndef __INITIAL_SP
#define __INITIAL_SP            Image$ARM_LIB_STACK$ZI$Limit
#endif

#ifndef __STACK_LIMIT
#define __STACK_LIMIT             Image$ARM_LIB_STACK$ZI$Base
#endif

#ifndef __VECTOR_TABLE
#define __VECTOR_TABLE            __Vectors
#endif

#ifndef __VECTOR_TABLE_ATTRIBUTE
#define __VECTOR_TABLE_ATTRIBUTE__attribute__((used, section("RESET")))
#endif




eric2013 发表于 2020-9-18 02:47:06

调用说明:
1、__main(); 直接调用
2、extern uint32_t__Vectors;外部extern即可使用。
3、__INITIAL_SP和__STACK_LIMIT要设置分散加载,带上ARM_LIB_STACK才能识别。


AC5:

#! armcc -E
; command above MUST be in first line (no comment above!)

/*
;-------- <<< Use Configuration Wizard in Context Menu >>> -------------------
*/

/*--------------------- Flash Configuration ----------------------------------
; <h> Flash Configuration
;   <o0> Flash Base Address <0x0-0xFFFFFFFF:8>
;   <o1> Flash Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
*----------------------------------------------------------------------------*/
#define __ROM_BASE      0x00000000
#define __ROM_SIZE      0x00080000

/*--------------------- Embedded RAM Configuration ---------------------------
; <h> RAM Configuration
;   <o0> RAM Base Address    <0x0-0xFFFFFFFF:8>
;   <o1> RAM Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
*----------------------------------------------------------------------------*/
#define __RAM_BASE      0x20000000
#define __RAM_SIZE      0x00040000

/*--------------------- Stack / Heap Configuration ---------------------------
; <h> Stack / Heap Configuration
;   <o0> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
;   <o1> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
*----------------------------------------------------------------------------*/
#define __STACK_SIZE    0x00000200
#define __HEAP_SIZE   0x00000C00

/*
;------------- <<< end of configuration section >>> ---------------------------
*/


/*----------------------------------------------------------------------------
User Stack & Heap boundary definition
*----------------------------------------------------------------------------*/
#define __STACK_TOP    (__RAM_BASE + __RAM_SIZE)    /* starts at end of RAM */
#define __HEAP_BASE    (AlignExpr(+0, 8))         /* starts after RW_RAM section, 8 byte aligned */


/*----------------------------------------------------------------------------
Scatter File Definitions definition
*----------------------------------------------------------------------------*/
#define __RO_BASE       __ROM_BASE
#define __RO_SIZE       __ROM_SIZE

#define __RW_BASE       __RAM_BASE
#define __RW_SIZE      (__RAM_SIZE - __STACK_SIZE - __HEAP_SIZE)


LR_ROM __RO_BASE __RO_SIZE{                     ; load region size_region
ER_ROM __RO_BASE __RO_SIZE{                     ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$Sections)
   .ANY (+RO)
   .ANY (+XO)
}

RW_RAM __RW_BASE __RW_SIZE{                     ; RW data
   .ANY (+RW +ZI)
}

#if __HEAP_SIZE > 0
ARM_LIB_HEAP__HEAP_BASE EMPTY__HEAP_SIZE{   ; Reserve empty region for heap
}
#endif

ARM_LIB_STACK __STACK_TOP EMPTY -__STACK_SIZE {   ; Reserve empty region for stack
}
}


AC6:

#! armclang -E --target=arm-arm-none-eabi -mcpu=cortex-m7 -xc
; command above MUST be in first line (no comment above!)

/*
;-------- <<< Use Configuration Wizard in Context Menu >>> -------------------
*/

/*--------------------- Flash Configuration ----------------------------------
; <h> Flash Configuration
;   <o0> Flash Base Address <0x0-0xFFFFFFFF:8>
;   <o1> Flash Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
*----------------------------------------------------------------------------*/
#define __ROM_BASE      0x00000000
#define __ROM_SIZE      0x00080000

/*--------------------- Embedded RAM Configuration ---------------------------
; <h> RAM Configuration
;   <o0> RAM Base Address    <0x0-0xFFFFFFFF:8>
;   <o1> RAM Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
*----------------------------------------------------------------------------*/
#define __RAM_BASE      0x20000000
#define __RAM_SIZE      0x00040000

/*--------------------- Stack / Heap Configuration ---------------------------
; <h> Stack / Heap Configuration
;   <o0> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
;   <o1> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
*----------------------------------------------------------------------------*/
#define __STACK_SIZE    0x00000200
#define __HEAP_SIZE   0x00000C00

/*
;------------- <<< end of configuration section >>> ---------------------------
*/


/*----------------------------------------------------------------------------
User Stack & Heap boundary definition
*----------------------------------------------------------------------------*/
#define __STACK_TOP    (__RAM_BASE + __RAM_SIZE)    /* starts at end of RAM */
#define __HEAP_BASE    (AlignExpr(+0, 8))         /* starts after RW_RAM section, 8 byte aligned */


/*----------------------------------------------------------------------------
Scatter File Definitions definition
*----------------------------------------------------------------------------*/
#define __RO_BASE       __ROM_BASE
#define __RO_SIZE       __ROM_SIZE

#define __RW_BASE       __RAM_BASE
#define __RW_SIZE      (__RAM_SIZE - __STACK_SIZE - __HEAP_SIZE)


LR_ROM __RO_BASE __RO_SIZE{                     ; load region size_region
ER_ROM __RO_BASE __RO_SIZE{                     ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$Sections)
   .ANY (+RO)
   .ANY (+XO)
}

RW_RAM __RW_BASE __RW_SIZE{                     ; RW data
   .ANY (+RW +ZI)
}

#if __HEAP_SIZE > 0
ARM_LIB_HEAP__HEAP_BASE EMPTY__HEAP_SIZE{   ; Reserve empty region for heap
}
#endif

ARM_LIB_STACK __STACK_TOP EMPTY -__STACK_SIZE {   ; Reserve empty region for stack
}
}




dyhfaily 发表于 2020-9-18 09:05:31

老哥 我还不明白分散加载啥意思 有相关教程吗

初晴sama 发表于 2020-9-18 09:42:42

dyhfaily 发表于 2020-9-18 09:05
老哥 我还不明白分散加载啥意思 有相关教程吗

http://www.armbbs.cn/forum.php?mod=viewthread&tid=86218&highlight=%B7%D6%C9%A2%BC%D3%D4%D8层主看下这个

byccc 发表于 2020-9-18 11:06:13

dyhfaily 发表于 2020-9-18 09:05
老哥 我还不明白分散加载啥意思 有相关教程吗

MDK的help文档有

quar 发表于 2023-10-26 11:25:10

cmsis_armcc.h和cmsis_armclang.h是哪一个版本的

eric2013 发表于 2023-10-26 12:52:57

quar 发表于 2023-10-26 11:25
cmsis_armcc.h和cmsis_armclang.h是哪一个版本的

CMSIS5.X版本就开始有了,可以使用最新的5.9.0

BlackZhou 发表于 2024-3-8 00:58:35

硬汉哥你好,sct文件里面定义的宏可以在C文件中引用吗

eric2013 发表于 2024-3-8 08:49:08

BlackZhou 发表于 2024-3-8 00:58
硬汉哥你好,sct文件里面定义的宏可以在C文件中引用吗

这个有个特别的用法

MDK获取未使用RAM空间首地址方法
https://www.armbbs.cn/forum.php?mod=viewthread&tid=111353&fromuid=58
(出处: 硬汉嵌入式论坛)
页: [1]
查看完整版本: STM32H7的MDK汇编启动代码__main,__initial_sp,__Vectors等在C里面的调用方法