Engineer's Notes | Creating an external Flash programming driver (.stdlr) using STM32CubeMX
⚫ Install STM32CubeIDE
⚫ Install the HAL library corresponding to the MCU model
The development of the external loader is divided into three parts. The first part is to use STM32CubeMX to configure and generate the project. The second part is the driver debugging of the external Flash, which mainly includes initialization, erasing, writing and reading operations. The third part calls the driver function to generate the external loader, including the definition of the external Flash information, including the size of the Flash capacity, the size of the page, and the information related to the Sector; the code required by the external loader in the third step and the driver of the corresponding device can be obtained in the following GitHub repository, and everyone is also welcome to submit their own debugged device drivers to the repository.
address:
https://github.com/WellinZHANG/External_Loader
Here, we use STM32CubeMX integrated in STM32CubeIDE to configure and generate the project.
New Construction
Select the corresponding device, fill in the project name, and select the storage location:
Pin Configuration
Select the corresponding Flash pin according to the hardware schematic diagram. Here, select Bank2 and configure as shown below. Note that the speed of the pin is adjusted to High and the QSPI interrupt is enabled. The FlashSize value is set to N, and the Flash size is configured as 2N+1.
Clock Configuration
According to the clock source on the board, perform the corresponding clock configuration. Here, the internal clock is used as the clock source of the system PLL.
Generate Project
Switch to the Code Generator tab and check the “Generate perioheral initialization as pair of '.c/.h' files per peripheral” option.
Get the relevant driver code from the GitHub repository mentioned at the beginning.
first step
Add the code in mian_test.c in the External-Loaders\ QSPI testing directory to the corresponding main.c file in the project.
Note that when adding code, keep the USER CODE BEGIN x and USER CODE END x tags, otherwise the added code will be overwritten when Cube MX regenerates the code.
Step 2
Replace the QSPI HAL driver files in the \External-Loaders\QSPI Drivers\IS25LP128F directory with the corresponding files in the project.
third step
Open CubeMX and regenerate the project. Because in order to adapt to all series of QSPI interfaces, the QSPI HAL driver provided by GitHub does not provide the corresponding QSPI peripheral configuration function, it needs to be generated through CubeMX.
the fourth step
As shown in the figure above, since the control instructions of each model of FLASH are slightly different, you need to adjust it according to the QPSI FLASH device you choose. At the same time, you need to debug whether the reading and writing of QSPI is normal. If the reading and writing of QSPIF lash is not normal, then add breakpoints at the positions marked in the figure below to find out which link is wrong and further adjust the driver.
After completing the QSPI driver debugging, we need to add the code required to generate the external loader and modify the corresponding configuration.
first step
Add the corresponding code and store it in the \External-Loaders\Loader_Files directory. Since the linker files of H7 and other series are different, they are divided into two folders, H7 and others. We select the problematic files in the H7 directory. Add all the files to the project.
Step 2
Modify the name in Dev_Inf.c to the name you want to set, usually set to MCU+Flash name.
third step
Modify the Linker configuration and open the settings page through "project" -> "Properties". Change the ld file in the red box to linker.ld. (It has been added to the project in the first step).
the fourth step
Modify the configuration and generate the stdlr file after compilation. Open the settings page through "project" -> "Properties" and add the following instructions in "post build steps":
Finally, compile to generate the corresponding stdlr file in the project directory. Copy it to the extra loader folder in the STM32CubeProgrammer installation directory and you can use it.
This method can quickly generate an external burning script to burn the external QSPI FLASH.