This article will introduce how to implement distributed loading of files through practical operations. The development tool is: mdk; development board: Wildfire stm32f407
1. Establish the project
Learn about the method of distributed image loading by implementing a simple addition calculation software algorithm.
Create a project, create folders and corresponding files, and set paths;
The corresponding c file is as follows:
The corresponding h file is as follows:
The main function and test function are as follows:
After compilation, view the map file information, as follows:
Check whether the project output is correct and the result is correct, as follows:
2. How to set up scattered loading
①Open the project options page, set the default option under Linker, and use scattered loading files.
software to allocate memory locations for the project. The file extension of scatter-loading files is sct .
The content before modification is as follows:
② Modify the scattered file , because the rom size of the microcontroller is 1M here, divided into 2 parts, each part is 0x0007FFFF, and the area size needs to be configured according to the actual situation. Make the following modifications in the default scattered loading file, change the size of the first loading area LR_IROM1 to 0x0007FFFF, change the size of its first execution area ER_IROM1 to 0x0007FFFF, and create a new loading area of LR_MY_ADD with its starting address Immediately after LR_IROM1, the size is also 0x0007FFFF, in which an execution area ADD_TEST starting address is consistent with LR_MY_ADD, and all the code of myadd.o is placed in this area.
③Compile and view map information
Online simulation, the function address is as follows, matching the information in the map
3. Summary
When the compiler generates an executable file, it first compiles each .c file into a .o file (this process is called compilation), and then links many .o files into an executable file (this process is called linking). During the linking process, link files are used to specify link-time behavior. By modifying the scatter-loading file sct, different files can be placed at specified locations.
Reference: GD32F1x0_ScatterLoading_V3.1.0
Welcome to follow the official account: Embedded Learning and Practice