跳转到主要内容

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

基于应用程序的专有解决方案

另一种解决方案是将闪存加载代码包含到应用程序本身。 该理念是,您的应用程序中已存在闪存配置(以便可以从其加载) ,也许您通过之前的测试已经知道如何写一块代码到闪存中。 然后,您只需一种将新的闪存数据传输到您的应用程序的方法。 一种方法是通过UART。 应用程序接收数据流,并将数据逐块写入闪存。

在该操作执行期间,闪存无法处于存储器映射模式,因此通常必须将应用程序置于特殊模式。

可在互联网上找到用于字节传输的开源解决方案。 例如,Y-modem协议在数据上提供16位CRC。

测试

可在互联网上找到用于字节传输的开源解决方案。 例如,Y-modem协议在数据上提供16位CRC。

建议立即彻底测试整个闪存,以尽早发现可能存在的问题。