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]:

 

  1. 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]:

 

  1. 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 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM