ARM核心--MemoryMap

ARM核心--MemoryMap

ARMv7-M Essentials 0

Link: https://www.bilibili.com/video/BV1MMVPzrE8S/?spm_id_from=333.1387.homepage.video_card.click&vd_source=e742ab928a70238934780b04b84d177d

1. 可寻址空间大小 / 可寻址空间范围

  • 可寻址空间大小:4GB;
  • 可寻址空间范围:0x0000_0000 ~ 0xFFFF_FFFF

2. 分块

  1. 代码:指的是用户代码编译之后机器码存放在片内Flash区域;起始地址给的是0x0?
  2. SRAM:即片内RAM;存放运行时的数据;一般起始地址就是0x2000_0000;
  3. 外设:用于访问外设;一般起始地址是0x4000_0000
  4. RAM: 指的是片外RAM,起始地址0x6000_0000,对应RT应该是SDRAM;
  5. 设备:
  6. 系统/供应商定义:其中有一个核销的系统控制空间,它里面有CPUID,地址是0xE000_ED00;

3. 示例代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//main.c
#include "stm32f10x.h"
#include <stdint.h>
#define CODE_ADDR_START 0x00000000
#define CODE_ADDR_END 0x1FFFFFFF
#define SRAM_ADDR_START 0x20000000
#define SRAM_ADDR_END 0x3FFFFFFF
#define SCB_CPUID_ADDR 0xE000ED00

uint32_t example_function(void)
{
return 0;
}

uint32_t example_value = 0x12345678;
int main(void)
{
// get the address of the example function
uint32_t function_addr = (uint32_t)&example_function;
if (function_addr < CODE_ADDR_START || function_addr > CODE_ADDR_END)
{
while(1);
}
// get the address of the example value
uint32_t value_addr = (uint32_t)&example_value;
if (value_addr< SRAM_ADDR_START || value_addr > SRAM_ADDR_END)
{
while(1);
}
//get the value of the SCB CPUID register
uint32_t cpuid_value = *(volatile uint32_t *)SCB_CPUID_ADDR;
if (0 == cpuid_value)
{
while(1);
}
return 0;
}

这个工程是为了验证默认的代码和变量区域分别在哪里:

  1. 代码:函数应该在代码区,对应为片内Flash;
  2. 变量:变量应该在SRAM,片内RAM中;
作者

Gavin

发布于

2025-05-10

更新于

2025-05-10

许可协议

CC BY-NC-SA 4.0

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×