11. 快閃記憶體下載
動機
In this step, we will discuss how to load data into external flash memory. The compiler compiles the application code and assets in your project into a binary or hex file. Depending on the specifications in the linker script, parts of the binary or hex file will be placed in internal flash, while other parts will be placed in external flash. Typically, assets such as images and fonts are stored in external flash, whereas the application code is stored in internal flash.
在開發過程中,我們需要一種方法將資料寫入外部快閃記憶體,但從執行快閃記憶體讀取資料的程式時就沒必要做寫入操作。
在開發過程中,我們需要一種方法將資料寫入外部快閃記憶體,但從執行快閃記憶體讀取資料的程式時就沒必要做寫入操作。
- 為STM32CubeProgrammer撰寫快閃記憶體載入軟體
- 使用基於應用程式的專有解決方案
Note
目標
兩種將資料寫入外部快閃記憶體的常見方法:
驗證
本節的目的為選擇並開發一種將數據載入到外部快閃記憶體的機制。
驗證點 | 基本原理 |
---|---|
Data can be flashed to the external flash | External flash can be used for storage |
先決條件
以下是本節的驗證點:
- 有關快閃記憶體的資訊,查閱資料手冊
- 關於MCU與外部快閃記憶體之間的連接的資訊
執行
STM32CubeProgrammer的快閃記憶體載入軟體
STM32CubeProgrammer帶有用於各種STM32評估套件的快閃記憶體載入程式。 The flash loaders are small programs that are loaded to the RAM of the MCU and executed during flashing to facilitate the programming of the flash.
快閃記憶體載入軟體包括兩部分:
- 配置與快閃記憶體通信所需的GPIO和快閃記憶體介面
- 釐清快閃記憶體程式設計所需的指令序列的快閃記憶體演算法
這些通常基於現有的快閃記憶體裝載程式。 如果您可以為正在使用的快閃記憶體找到快閃記憶體載入軟體,最好以該軟體作為基礎並修改GPIO部分。 如果您通過複製評估套件中的快閃記憶體電路來設計硬體,則可以直接使用該套件的快閃記憶體裝載軟體。
The flash loader projects provided with STM32CubeProgrammer are found in the installation folder, which is C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\ExternalLoader if it is installed in the default directory.
Flash loader projects can also be found here on github: STM32 External Flashloaders on GitHub.
Further reading
- Section 3.9 in UM0892: STM32 ST-LINK utility software description.
- STMicroelectronics Community: How to add your SPI flash into the STM32CubeProgrammer's external loader Part 1.
- STMicroelectronics Community: How to add your SPI flash into the STM32CubeProgrammer's external loader Part 2.
基於應用程式的專有解決方案
另一種解決方案是將快閃記憶體載入程式碼包含到應用程式本身。 該理念是,您的應用程式中已存在快閃記憶體配置(以便可以從其載入),也許您通過之前的測試已經知道如何寫一塊程式碼到快閃記憶體中。 然後,您只需一種將新的快閃記憶體數據傳輸到您的應用程式的方法。 一種方法是透過UART。 應用程式接收數據流,並將數據逐塊寫入快閃記憶體。
在該操作執行期間,快閃記憶體無法處於記憶體映射模式,因此通常必須將應用程式置於特殊模式。
可在網路找到用於位元組傳輸的開源解決方案。 例如,Y-modem協定在資料上提供16位元 CRC。
測試
可在網路找到用於位元組傳輸的開源解決方案。 例如,Y-modem協定在資料上提供16位元 CRC。
建議立即徹底測試整個快閃記憶體,以儘早發現可能存在的問題。