How to scatter-load files on a microcontroller

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;

c09394d530c7c44878582f2f6a1089ec.png

The corresponding c file is as follows:

4802d7e316532de262785b45535c03bf.png

The corresponding h file is as follows:

b44737a8a1d9e221c1a2801dc8e12a85.png

The main function and test function are as follows:

7e522b9df52f1039bc0d36ab42d585b2.png

After compilation, view the map file information, as follows:

238fa6e1340404d55a45e67201859842.png

Check whether the project output is correct and the result is correct, as follows:

d4df290a83ab9b495d14cd8adf0b2341.png

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 .

ed30d65d4b5c4951c5433b0662131b93.png

The content before modification is as follows:

4bc6aaabea2b63b010058016e67743d2.png

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.

490c745c4b4a025491cc02e3d0c07434.png

③Compile and view map information

ca4e01abfa5b833a3e51cefba7f13b94.png

Online simulation, the function address is as follows, matching the information in the map

08b73019f8f07584da101041a8ca801d.png

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

Guess you like

Origin blog.csdn.net/weixin_46158019/article/details/132310081