只要用Cortex-M单片机都会遇到的问题

[复制链接]
 楼主| Diyer2015 发表于 2017-11-28 14:14 | 显示全部楼层 |阅读模式
MSP的位置 = 全局变量数+HEAP_SIZE+Stack_Size。
KEIL编译器对RAM的排列方式(地址由低到高):
    1、全局变量(包括已初始化的变量和没初始化的变量);
    2、Heap所占的空间;
    3、主Stack所占空间;
 楼主| Diyer2015 发表于 2017-11-28 14:15 | 显示全部楼层
Stack_Size      EQU     0x0200;

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp   


Heap_Size       EQU     0x000;

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit
 楼主| Diyer2015 发表于 2017-11-28 14:15 | 显示全部楼层
编译器怎么知道我定义的Stack_Mem存储区是栈空间呢
 楼主| Diyer2015 发表于 2017-11-28 14:35 | 显示全部楼层
Defining __initial_sp, __heap_base and __heap_limit
One of several methods you can use to specify the initial stack pointer and heap bounds is to define the following symbols:
__initial_sp
__heap_base
__heap_limit.
 楼主| Diyer2015 发表于 2017-11-28 14:35 | 显示全部楼层
__asm void dummy_function(void)
{
    EXPORT __initial_sp
    EXPORT __heap_base
    EXPORT __heap_limit

__initial_sp EQU STACK_BASE
__heap_base EQU HEAP_BASE
__heap_limit EQU (HEAP_BASE + HEAP_SIZE)
}
 楼主| Diyer2015 发表于 2017-11-28 14:36 | 显示全部楼层
The constants STACK_BASE, HEAP_BASE and HEAP_SIZE can be defined in a header file, for example stack.h, as follows:
/* stack.h */
#define HEAP_BASE 0x20100000  /* Example memory addresses */
#define STACK_BASE 0x20200000
#define HEAP_SIZE ((STACK_BASE-HEAP_BASE)/2)
#define STACK_SIZE ((STACK_BASE-HEAP_BASE)/2)
Note
This method of specifying the initial stack pointer and heap bounds is supported by both the standard C library (standardlib) and the micro C library (microlib).
xujunyi3611 发表于 2017-11-28 16:23 | 显示全部楼层
关于容量和空间的问题吗?
 楼主| Diyer2015 发表于 2018-9-3 15:16 | 显示全部楼层
应该是这样的道理!

一起探讨吧!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

63

主题

1615

帖子

13

粉丝

63

主题

1615

帖子

13

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