硬汉嵌入式论坛

 找回密码
 立即注册
查看: 9092|回复: 8
收起左侧

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

  [复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
发表于 2020-9-18 00:53:02 | 显示全部楼层 |阅读模式


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

  1. /* #########################  Startup and Lowlevel Init  ######################## */

  2. #ifndef __PROGRAM_START
  3. #define __PROGRAM_START           __main
  4. #endif

  5. #ifndef __INITIAL_SP
  6. #define __INITIAL_SP              Image$ARM_LIB_STACK$ZI$Limit
  7. #endif

  8. #ifndef __STACK_LIMIT
  9. #define __STACK_LIMIT             Image$ARM_LIB_STACK$ZI$Base
  10. #endif

  11. #ifndef __VECTOR_TABLE
  12. #define __VECTOR_TABLE            __Vectors
  13. #endif

  14. #ifndef __VECTOR_TABLE_ATTRIBUTE
  15. #define __VECTOR_TABLE_ATTRIBUTE  __attribute__((used, section("RESET")))
  16. #endif
复制代码





回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
 楼主| 发表于 2020-9-18 02:47:06 | 显示全部楼层
调用说明:
1、__main(); 直接调用
2、extern uint32_t  __Vectors;外部extern即可使用。
3、__INITIAL_SP和__STACK_LIMIT要设置分散加载,带上ARM_LIB_STACK才能识别。


AC5:

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

  3. /*
  4. ;-------- <<< Use Configuration Wizard in Context Menu >>> -------------------
  5. */

  6. /*--------------------- Flash Configuration ----------------------------------
  7. ; <h> Flash Configuration
  8. ;   <o0> Flash Base Address <0x0-0xFFFFFFFF:8>
  9. ;   <o1> Flash Size (in Bytes) <0x0-0xFFFFFFFF:8>
  10. ; </h>
  11. *----------------------------------------------------------------------------*/
  12. #define __ROM_BASE      0x00000000
  13. #define __ROM_SIZE      0x00080000

  14. /*--------------------- Embedded RAM Configuration ---------------------------
  15. ; <h> RAM Configuration
  16. ;   <o0> RAM Base Address    <0x0-0xFFFFFFFF:8>
  17. ;   <o1> RAM Size (in Bytes) <0x0-0xFFFFFFFF:8>
  18. ; </h>
  19. *----------------------------------------------------------------------------*/
  20. #define __RAM_BASE      0x20000000
  21. #define __RAM_SIZE      0x00040000

  22. /*--------------------- Stack / Heap Configuration ---------------------------
  23. ; <h> Stack / Heap Configuration
  24. ;   <o0> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
  25. ;   <o1> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
  26. ; </h>
  27. *----------------------------------------------------------------------------*/
  28. #define __STACK_SIZE    0x00000200
  29. #define __HEAP_SIZE     0x00000C00

  30. /*
  31. ;------------- <<< end of configuration section >>> ---------------------------
  32. */


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


  38. /*----------------------------------------------------------------------------
  39.   Scatter File Definitions definition
  40. *----------------------------------------------------------------------------*/
  41. #define __RO_BASE       __ROM_BASE
  42. #define __RO_SIZE       __ROM_SIZE

  43. #define __RW_BASE       __RAM_BASE
  44. #define __RW_SIZE      (__RAM_SIZE - __STACK_SIZE - __HEAP_SIZE)


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

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

  55. #if __HEAP_SIZE > 0
  56.   ARM_LIB_HEAP  __HEAP_BASE EMPTY  __HEAP_SIZE  {   ; Reserve empty region for heap
  57.   }
  58. #endif

  59.   ARM_LIB_STACK __STACK_TOP EMPTY -__STACK_SIZE {   ; Reserve empty region for stack
  60.   }
  61. }
复制代码


AC6:

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

  3. /*
  4. ;-------- <<< Use Configuration Wizard in Context Menu >>> -------------------
  5. */

  6. /*--------------------- Flash Configuration ----------------------------------
  7. ; <h> Flash Configuration
  8. ;   <o0> Flash Base Address <0x0-0xFFFFFFFF:8>
  9. ;   <o1> Flash Size (in Bytes) <0x0-0xFFFFFFFF:8>
  10. ; </h>
  11. *----------------------------------------------------------------------------*/
  12. #define __ROM_BASE      0x00000000
  13. #define __ROM_SIZE      0x00080000

  14. /*--------------------- Embedded RAM Configuration ---------------------------
  15. ; <h> RAM Configuration
  16. ;   <o0> RAM Base Address    <0x0-0xFFFFFFFF:8>
  17. ;   <o1> RAM Size (in Bytes) <0x0-0xFFFFFFFF:8>
  18. ; </h>
  19. *----------------------------------------------------------------------------*/
  20. #define __RAM_BASE      0x20000000
  21. #define __RAM_SIZE      0x00040000

  22. /*--------------------- Stack / Heap Configuration ---------------------------
  23. ; <h> Stack / Heap Configuration
  24. ;   <o0> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
  25. ;   <o1> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
  26. ; </h>
  27. *----------------------------------------------------------------------------*/
  28. #define __STACK_SIZE    0x00000200
  29. #define __HEAP_SIZE     0x00000C00

  30. /*
  31. ;------------- <<< end of configuration section >>> ---------------------------
  32. */


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


  38. /*----------------------------------------------------------------------------
  39.   Scatter File Definitions definition
  40. *----------------------------------------------------------------------------*/
  41. #define __RO_BASE       __ROM_BASE
  42. #define __RO_SIZE       __ROM_SIZE

  43. #define __RW_BASE       __RAM_BASE
  44. #define __RW_SIZE      (__RAM_SIZE - __STACK_SIZE - __HEAP_SIZE)


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

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

  55. #if __HEAP_SIZE > 0
  56.   ARM_LIB_HEAP  __HEAP_BASE EMPTY  __HEAP_SIZE  {   ; Reserve empty region for heap
  57.   }
  58. #endif

  59.   ARM_LIB_STACK __STACK_TOP EMPTY -__STACK_SIZE {   ; Reserve empty region for stack
  60.   }
  61. }
复制代码




回复

使用道具 举报

16

主题

148

回帖

196

积分

初级会员

积分
196
发表于 2020-9-18 09:05:31 | 显示全部楼层
老哥 我还不明白分散加载啥意思 有相关教程吗
回复

使用道具 举报

17

主题

101

回帖

152

积分

初级会员

积分
152
发表于 2020-9-18 09:42:42 | 显示全部楼层
dyhfaily 发表于 2020-9-18 09:05
老哥 我还不明白分散加载啥意思 有相关教程吗

http://www.armbbs.cn/forum.php?m ... 6%C9%A2%BC%D3%D4%D8  层主看下这个
回复

使用道具 举报

36

主题

2039

回帖

2147

积分

至尊会员

积分
2147
发表于 2020-9-18 11:06:13 | 显示全部楼层
dyhfaily 发表于 2020-9-18 09:05
老哥 我还不明白分散加载啥意思 有相关教程吗

MDK的help文档有
Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better.
回复

使用道具 举报

0

主题

13

回帖

13

积分

新手上路

积分
13
发表于 2023-10-26 11:25:10 | 显示全部楼层
cmsis_armcc.h和cmsis_armclang.h是哪一个版本的
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
 楼主| 发表于 2023-10-26 12:52:57 | 显示全部楼层
quar 发表于 2023-10-26 11:25
cmsis_armcc.h和cmsis_armclang.h是哪一个版本的

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

使用道具 举报

0

主题

1

回帖

1

积分

新手上路

积分
1
发表于 2024-3-8 00:58:35 来自手机 | 显示全部楼层
硬汉哥你好,sct文件里面定义的宏可以在C文件中引用吗
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106660
QQ
 楼主| 发表于 2024-3-8 08:49:08 | 显示全部楼层
BlackZhou 发表于 2024-3-8 00:58
硬汉哥你好,sct文件里面定义的宏可以在C文件中引用吗

这个有个特别的用法

MDK获取未使用RAM空间首地址方法
https://www.armbbs.cn/forum.php? ... 1353&fromuid=58
(出处: 硬汉嵌入式论坛)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-4-28 09:13 , Processed in 0.214349 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表