不同的 SDK 版本 flash 結構可能不同,以實際 SDK 版本提供的為準。
最近開發用的晶片正好是 Nodic 的 52840,學習過程中,正好對相關的知識做個總結,方便自己後面回顧。
先貼出一張 52840 和 52832 的 flash 結構圖,這個是在網上翻閱資料找到的圖片,當時保存到電腦裡,正好拿出來用。
圖片以 nRF52840 S140 v6 為例,52840 有 1MB 的 flash 和 256Kb RAM, 從上圖可以看出 flash 最下邊是 SoftDevice(藍牙協議棧),中間是 Application(應用層), 再往上是 UserData 和 Bootloader。SoftDevice 下邊還有 MBR(Master Boot Record,主引導記錄)下邊我們在詳細分析它們。
52840 flash 結構解析SoftDevice(藍牙協議棧)上邊圖中可以知道 SoftDevice 在 Flash 中的映射地址是 0x00000000-0x00026000,總共是 152Kb,但是其中要拆分成 4Kb 的 MBR 和 148Kb 的 Softdevice。
MBR(Master Boot Record,主引導記錄), The main functionality of the MBR is to provide an interface to allow in-system updates of the application, the SoftDevice, and bootloader firmware,MBR 的主要功能是提供一個接口,以允許對應用程式,SoftDevice 和引導加載程序固件進行系統內更新。
ApplicationApplication 存放了我們應用程式代碼,在 Flash 中的映射地址是 0x00026000-0x000ED000,共 796Kb。
UserDataUserData 存放了配置信息,資料中是這樣解釋的:This 28KB section of flash memory is reserved for config settings. It uses an open source file system called Little File System, which is a part of ARM Mbed OpenSource to store bonding data. For example, when you bond the nRF52 with another Central device,用於存儲綁定數據,它在 Flash 中的映射地址是 0x000ED000-0x000F4000,共 28Kb。
BootloaderBootloader,總共 48Kb,但是要拆分成三部分,分別是
Bootloader(40Kb,引導程序,0x000F4000-0x000FE000)
Master Boot Record Params(4Kb,主引導記錄參數,0x000FE000-0x000FF000)
Bootloader Settings(4Kb,引導程序設置,0x000FF000-0x00100000)
BootloaderA bootloader may be used to handle in-system update procedures.
The bootloader has full access to the SoftDevice Application Programming Interface (API) and can be implemented like any application that uses the SoftDevice. In particular, the bootloader can make use of the SoftDevice API for Bluetooth® Low Energy communication.
上邊是官方文檔的原文,bootloader主要用於處理系統內更新程序,主要用途有:
booting into an application
activating new firmware
optionally, entering DFU mode where DFU transports are activated and new firmware can be delivered
feeding the watchdog timer
Master Boot Record Params官方文檔中沒有找出相關的信息,但是應該和 MBR 相似,存放了程序引導信息。
Bootloader SettingsBootloader Settings 保存了 bootloader 和 DFU 信息,如:
current firmware - size, CRC-32,當前固件 - 大小,CRC-32。
pending firmware - size, CRC-32,待定的固件--大小,CRC-32。
progress of the firmware update,固件更新的進度。
progress of the firmware activation,激活固件的進度。
current firmware versions (application and bootloader),當前的固件版本(應用程式和引導程序)。
transport-specific data,傳輸特定數據。
其他除了 flash 中的結構地址映射外,還需要關注 FICR(信息配置寄存器,0x10001000) 和 UICR(用戶信息配置寄存器,0x10000000),
FICR, 存儲了工廠信息配置,是在出廠時預先編程的,用戶不能擦除。這些寄存器包含了晶片特有的信息和配置。
UICR, 可以用於配置用戶特定設置的非易失性存儲器(NVM)寄存器,用於管理 FLASH 區域(0x0-0x80000)中的 NVM 存儲器存儲,一般不建議在這裡面存儲信息,除非不使用 softdevice 則可以通過 fstorage 將數據寫入 UICR (即只能在禁用 softdevice 時使用)。
52840 上電運行流程上電後,系統先執行 softdevice,softdevice 通過讀取 UICR 一個寄存器的值,來判斷目前系統是否有 BootLoader ,如果沒有 BootLoader ,系統直接跳到 application;如果有 BootLoader,系統先跳到 BootLoader,BootLoader 再根據目前的情況來決定是進入升級模式還是跳往 application。
結尾本人水平有限,錯誤、疏漏之處在所難免,還請各位多多包涵,如有問題,歡迎評論指導我修正錯誤,也希望本文能給你帶來一些對 52840 flash 映射理解上的幫助!
參考[1] Master boot record:https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsds_s140%2FSDS%2Fs1xx%2Fmbr_bootloader%2Fmbr.html
[2] Bootloader:https://learn.sparkfun.com/tutorials/nrf52840-advanced-development-with-the-nrf5-sdk/building-blinky-for-the-sparkfun-nrf52840-mini-breakout
[3] Bootloader:https://infocenter.nordicsemi.com/topic/sds_s140/SDS/s1xx/mbr_bootloader/bootloader.html
[4] Bootloader Settings:https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Flib_bootloader.html
現在的公眾號都沒有留言功能了,早知道就不應該把原先帶留言功能的公眾號註銷重新來過。需要留言的朋友們,可以在左下角查看原文連結,在我的博客內留言,留言記得填寫有效郵箱,這樣才能收到我的回覆郵件!