STM32片上Flash內(nèi)存映射、頁面大小、寄存器映射
一、怎么看Flash大小
1.1 通過型號
型號會印在MCU表面,可以通過觀察獲得,我的是STM32F103RBT6(以下分析基于這個(gè)型號),對照下圖的STM32產(chǎn)品命名,可知STM32F103RBT6的Flash是128KB。
()
圖1 Ordering information scheme
1.2 通過數(shù)據(jù)手冊(內(nèi)存映射)
也可以通過數(shù)據(jù)手冊得到Flash大小,首先根據(jù)型號從官網(wǎng)下得對應(yīng)的數(shù)據(jù)手冊Datasheet(點(diǎn)這里,輸入MCU型號進(jìn)行檢索。STM32F103RB相關(guān)的手冊都在這:http://www.st.com/internet/mcu/product/164487.jsp),打開找到Memory map這張圖,如圖2紅框所示(圖2紅框放大即為圖3),F(xiàn)lash在內(nèi)存的映射地址0x0800 0000 ~ 0x0801 FFFF,即大小為128KB。通過該方法也可以了解到片上Flash的內(nèi)存映射。
圖2 Memory map
圖3 Memory map中的SRAM和Flash
二、塊大小
對于系統(tǒng)而言,F(xiàn)lash分為片上Flash(Embedded Flash)和外置Flash。通常說,F(xiàn)lash先分塊再分頁,擦除是按塊進(jìn)行,這樣的說法應(yīng)該只是對外置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對應(yīng)的參考手冊為RM0008 Reference manual,定位到Embedded Flash memory章節(jié)(也可以通過搜索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相關(guān)寄存器
Flash寄存器在內(nèi)存的映射如下[1]:
圖5 Memory map中的Flash Interface
Flash各寄存器具體地址如下[2]:
圖6 Flash memory interface registers of medium-density devices
具體到各寄存器功能,位含義,得參考[3],F(xiàn)lash寄存器映射如下:
圖7 Flash register map
五、Information block
Flash中Information block在內(nèi)存映射如下[1]:
圖8 Memory map中的System memory
具體的Flash的Information block地址如下:
圖9 Information block of medium-density devices
System memory包含一段引導(dǎo)程序(當(dāng)系統(tǒng)從片上Flash啟動(dòng)會用到),F(xiàn)lash出廠后就不能修改,不曉得我理解得對不對,貼出原文如下[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.