Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the skills of using MDK?

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

What is the skill of using MDK? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Almost all of you who play ARM Cortex M MCU are developed through MDK Keil 5 or IAR environment, as the saying goes, if you want to do a good job, you must first sharpen its tools. We use this development environment every day, so, how much do you know about some practical functions and tips in MDK Keil 5?

1. Not all source files (.c) need to be added to the project, only the necessary source files need to be added. No matter what the development environment is, as long as it is a stm32fxxx_hal_xxx.c + project, the decisive factor of the project compilation time is the source files in the project. Take the STM32 HAL library project as an example, the driver files of MCU peripherals are generally in the format of [stm32fxxx_hal_xxx.c]. How many such source files are there, which represents how many STM32 MCU peripherals are enabled in this project. We can make a comparison:

We use STM32CubeMX to generate a project, which uses external high-frequency, low-frequency crystal oscillator, SPI1 and USART1,CubeMX to generate automatically. There are only about ten necessary source files:

Then we add some unnecessary source files. Here, I simply add all the peripheral drivers in the CubeF1 firmware library, even some template.c templates that are not necessary at all:

As you can see, the size of the generated Code is very different. I still use the ARMCCV6 version of the compiler here, and I still can't see the compilation time of the two projects. If I use the ARMCCV5 version, the estimated time will be several times different. In fact, the effect of the two projects is exactly the same, and the source files that do not need to be added are of no use except a waste of compilation space and compilation time.

two。 The header file (.h) can be added to the project at will. Header files are essential in MDK's code development project. The role of the header file in the project is to provide macro definition / constant, structure declaration, enumerator declaration unified place, function declaration (you can even write the function implementation directly in the header file, without any problems). In the actual development process, the macro definition is often modified frequently, but the traditional MDK developers' habit is to add only source files instead of header files in the project, which makes it very troublesome to modify the macro definition. We should abandon this habit and add frequently used header files to the project.

3. The compiler version is V6. A very important update in MDK 5.24 and MDK 5.25 is that MDK is beginning to gradually support and improve the ARMCC_V6 compiler. In the previous versions below 5.20, I often heard that bosses used the ARMCC_V6 compiler, but most of them were courteous * *, and there were a lot of errors reported according to routines, but there were few that could be realized, but since the 5.24 version, MDK using the V6 compiler generally will not report errors again. To use the V6 compiler:

1) add the cmsis_armcc_ V6.h header file to our project and set the include path

2) the compiler version of the Tatget tab of the project is V6.9.

3) Misc Controls is left blank, C language and C++ language both choose gnu11 version, and the optimization level is arbitrary. It doesn't matter.

In this way, there is no problem for MDK to compile the project with the V6 compiler.

4. Generate a bin file. Another important function of MDK is to generate bin files. Add a line [fromelf.exe-- bin-o] to After Build under the User tab of the project.

"$L@L.bin"# L"]:

The following information from the project compilation indicates that the bin file is generated successfully:

You can see the bin file with the same name as the project file in the directory of the project file:

5. Comments and indent shortcuts

A very useful new feature in MDK Keil 5: batch comment / uncomment and code batch indent / back. If you need to comment out a large piece of code, you only need to click a button.

6. First-level file directory

MDK project, in the final analysis, consists of a large number of header files and source files, these header files and source files are packaged in different directories, the MDK project links these folder directories to find the corresponding source files and header files. However, in ST official routines, header files, source files, library files, and startup files are placed in multiple layers of chaotic directories. Although the purpose of doing this is to better classify and manage driver files, it is really not easy for us developers to migrate their official routines. I will show a few screenshots of how the official routines store project files and driver files:

In contrast to atomic routines, except for individual third-party libraries such as DSP and FATFS, there are only one-level directories with a clear structure:

We should advocate using only first-level directories in MDK, whether it is file lookup or routine migration, which is very convenient:

7. Enable MicroLIB

There is a feature in MDK that is very close to the standard C library, and that is MicroLIB, which can be found in the project configuration menu:

This library is the default standard C library alternative library, after choosing this, you can use some simplified library functions of the standard C library, such as fputc memcpy, etc., of which the most commonly used is of course fputc, this function can be written directly with printf function to print data, peripherals can be serial port, can also be a display screen.

8. Manual KeilKill

You should all know that MDK has a KeilKill script that deletes the compiled obj and other intermediate files, so that the project will not take up too much space when copying, pasting or packaging, and the size of the intermediate files generated is directly related to the amount of source file code in the project. In fact, KeilKill can be done manually, that is, delete all other files in the same directory as the project file (.uvprojx), and the effect is exactly the same as the KeilKill script.

After reading the above, have you mastered the skills of using MDK? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report