首页 > 代码库 > STM32 flash 内存分布介绍
STM32 flash 内存分布介绍
摘要:
本文以STM32F103RBT6为例介绍了片上Flash(Embedded Flash)若干问题,包括Flash大小(内存映射)、块大小、页面大小、寄存器。这些知识,有利于写Flash驱动。
一、怎么看Flash大小
1.1 通过型号
型号会印在MCU表面,可以通过观察获得,我的是STM32F103RBT6(以下分析基于这个型号),对照下图的STM32产品命名,可知STM32F103RBT6的Flash是128KB。
()
图1 Ordering information scheme
1.2 通过数据手册(内存映射)
也可以通过数据手册得到Flash大小,首先根据型号从官网下得对应的数据手册Datasheet(点这里,输入MCU型号进行检索。STM32F103RB相关的手册都在这:http://www.st.com/internet/mcu/product/164487.jsp),打开找到Memory map这张图,如图2红框所示(图2红框放大即为图3),Flash在内存的映射地址0x0800 0000 ~ 0x0801 FFFF,即大小为128KB。通过该方法也可以了解到片上Flash的内存映射。
图2 Memory map
图3 Memory map中的SRAM和Flash
二、块大小
对于系统而言,Flash分为片上Flash(Embedded Flash)和外置Flash。通常说,Flash先分块再分页,擦除是按块进行,这样的说法应该只是对外置Flash而言,对于片上Flash即可以按页擦除也可以整块擦除,英文原文如下[2]:
- The Flash memory erase operation can be performed at page level or on the whole Flash area (mass-erase). The mass-erase does not affect the information blocks.
三、页面大小
按1.2的方法下得该MCU的参考手册,STM32F103RBT6对应的参考手册为RM0008 Reference manual,定位到Embedded Flash memory章节(也可以通过搜索0x0800 0000来定位)。STM32有4种Flash module organization,分别是:low-density devices(32KB,1KB/page)、medium-density devices(128KB,1KB/page)、high-density devices(512KB,2KB/page)、connectivity line devices(256KB,2KB/page)、XL-density(devices(1M,2KB/page)。从上面分析可知,STM32F103RBT6的Flash是128KB,可见是medium-density devices,如下图所示:
图4 Flash module organization (medium-density devices)
四、Flash相关寄存器
Flash寄存器在内存的映射如下[1]:
图5 Memory map中的Flash Interface
Flash各寄存器具体地址如下[2]:
图6 Flash memory interface registers of medium-density devices
具体到各寄存器功能,位含义,得参考[3],Flash寄存器映射如下:
图7 Flash register map
五、Information block
Flash中Information block在内存映射如下[1]:
图8 Memory map中的System memory
具体的Flash的Information block地址如下:
图9 Information block of medium-density devices
System memory包含一段引导程序(当系统从片上Flash启动会用到),Flash出厂后就不能修改,不晓得我理解得对不对,贴出原文如下[3]:
- System memory is used to boot the device in System memory boot mode. The area is reserved for use by STMicroelectronics and contains the boot loader which is used to reprogram the Flash memory using the USART1 serial interface. It is programmed by ST when the device is manufactured, and protected against spurious write/erase operations. For further details please refer to AN2606.
The option bytes are managed by an embedded Flash Program/Erase Controller (FPEC),详情见[3]。
参考资料:
[1] DS5319: Medium-density performance line ARM-based 32-bit MCU with 64 or 128 KB Flash, USB, CAN, 7 timers, 2 ADCs, 9 communication interfaces(数据手册) DS5319.pdf
[2] RM0008: STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and STM32F107xx advanced ARM-based 32-bit MCUs(参考手册) 注:文件尺寸太大,上传不了:-(
[3] PM0075:STM32F10xxx Flash memory microcontrollers(Flash编程手册) PM0075.pdf
STM32 flash 内存分布介绍