[Raspberry Pi Pico Review] FreePascal RPI Pico Engineering Structure Analysis
[Copy link]
This post was last edited by tjCFeng on 2021-3-29 11:07
Last time, I installed the IDE and compiled the examples to run Pico, but I didn't read the code, and I didn't know how the whole program worked. This time, I will take a look at the structure of the project, understand the author's method, and see how he did it.
Let's open the example project file first. Again, without looking at the code, we can directly open the project properties to see the settings. There are several differences between FreePascal's Pico project and a normal application project:
1. Compiler settings:
2. Selection of runtime library:
If you create a Windows project directly, the target platform settings are all default and change with the operating system, and there is no choice for the runtime library. The biggest differences are basically these two points. There is nothing much to say about the compiler, just choose the corresponding one, and the runtime library also needs to be selected correctly. This runtime library is actually the definition of the register address and structure of each RP2040. If you develop it according to the conventional register operation method, it is already considered to include all files. But did the author really design it this way?
Go directly into the folder of Example. First, you can see several folders of adc, blinky, i2c, spi, and uart. You can tell from the names that they are routines for corresponding functions. Then there are several .sh files. These should be script files used when compiling under Linux. Ignore them for now. The most important one is the folder of units, which contains many .obj and .pas files, as well as a .a file. We all know that .pas files are Pascal files, that is, files for developers to call. So what are these .obj files used for? Shouldn't temporary files be deleted?
Students who use C language to write programs know that the main process of compiling a program is:
Source code →
Preprocessor →
compiler →
Assembler →
object code →
Linker →
Executables
The third to last step is the .obj file. Linking it with the resource file through the linker will generate the final binary file. But what role does this "temporary file" of C language play in Pascal projects? The .obj file is a compiled binary file. It has complete functions and can provide external interfaces. At this time, through the macro definition of the code, the Pascal compiler will include it as a static link library into the final program.
When using, you must first declare the name, parameters, and calling method of each function you need. This name is consistent with the name provided by .obj. If you want to change the name you want, you need to redefine it with the keyword "name". This method is exactly the same as the method of Pascal calling dynamic link libraries, except that dynamic link files cannot be included in the program, and they must be released with a lot of small tails (.dll files); static link files can be included, and only a binary file is generated in the end.
It is undoubtedly a huge workload to use registers directly to complete all functions, so the author "scammed" and compiled Pico's SDK with a C compiler in advance, so that these "temporary files" can be used by me, and the same is true for .a files.
(End)
|