1. How to create an ARM project and an arm Project
To learn about stm32, the first step is to select a development tool. GCC, MDK, and IAR have their own advantages and disadvantages. Here, I select MDK5.14 for use. If MDK is used for the first time and a development board is available, many templates are provided for us to learn. However, I found that using these templates directly makes it interesting for me to quickly implement functions, but it makes me confused when I parse the code, and I don't even know how the program runs, I don't know why I did this design, so I had the idea of building my own project out of the routine, and I had a bunch of errors for the first time, it took me nearly four hours to solve these mistakes through Baidu and my own searches. I recorded my entire experience. Although the chips or software development may be different in the future, but the specific ideas are the same. This process also applies to all use MDK generation for the STM32 Program (Firmware Library mode ). In order to quickly solve the same error again in the future, I will try to provide detailed steps to handle it.
Preparations
Create a project folder and add the OUTPUT and SOURCE folders below it (as shown below ):
Add a folder APP under the SOURCE folder to store user files.
Note: The names of all folders (including the folders on the project path) must be in English, because Chinese may encounter unknown compilation errors in some cases.
Move the header file and the corresponding sub-file code in the standard library file to the SOURCE folder. I am using STM32F10x_StdPeriph_Lib_V3.5.0. There may be other changes to the library in the future. This requires you to follow this idea to handle them, decompress STM32F10x_StdPeriph_Lib and find... \ stm32f10x_stdperiph_lib \ STM32F10x_StdPeriph_Lib_V3.5.0 \ Libraries
And copy...\ Project folder (current project, English) \ SOURCEIn the folder, CMSIS is the Cortex microcontroller Software Interface Standard, which provides the stm32 Startup File, peripherals definition, and device definition. The STM32F10x_StdPeriph_Driver provides library functions to perform operations on the chip.
SOURCEThe folder content is as follows:
At this point, the entire project is ready, and the following will begin to use MDK to build the project.
Use MDK to create a project
1. Create an arm mdk project. I chose the chip stm32fw.vs, which is consistent with the development board chip and located under the current project file. During project creation, add the corresponding chip, but do not add the Startup code. manually copy the STM32F10x in the \ Keil \ ARM \ Startup \ ST folder. s (the Startup file will be explained later) to the current project folder and add it to start_up under the current project.
2. Create a file and save it in the above... // APP folder. Save the file name as main. c and add it to the USER folder.
3. Add the DRIVE folder to the project and use the driver file, that is...\ SOURCE \ STM32F10x _ StdPeriph_Driver \ srcAdd the driver file to the DRIVE folder as follows:
Add inc query support to target for header file search.
Note: Important. Otherwise, the MDK cannot identify the header file you contain.
The procedure is as follows:
1. Select the target folder in MDK, right-click and select OPTION (shortcut: ALT + F7), and select C/C ++ at the top of the pop-up dialog box.
2. in the lower part of the dialog box, add: the current project Folder \ SOURCE \ STM32F10x_StdPeriph_Driver \ inc provides support for header files (new support will also be added later ), that is, include the path of the used header file in the software!
Compile and correct
After completing the preceding steps, add the code to the main function. The header file is # include "stm32f10x. h". Compile the code.
In this case
C: \ Keil \ ARM \ Inc \ ST \ STM32F10x \ stm32f10x. h (8319): error: #5: cannot open source input file "stm32f10x_conf.h": No suchfile or directory
Stm32f10x_conf.h is the declaration of the peripheral header file and the assert processing command in the program. I did not find this header file in the 3.5 solid state library, so I downloaded a header file with all the peripheral header file declarations stm32f10x_conf.h, put it into the current project Folder \ SOURCE \ STM32F10x_StdPeriph_Driver \ inc and continue compilation. A bunch of ports are undefined, because although stm32f10x_conf.h is added, it is not actually enabled. search in h, about the location of 100 rows
Cancel the comments of # defineUSE_STDPERIPH_DRIVER, as shown in. In addition, # include "stm32f10x_conf.h" is defined at the end of # include "stm32f10x. h,
The header file stm32f10x_conf.h is described below.
It contains all the peripheral header files you need. You can uncomment the corresponding header files if you need any peripherals.
In addition, if
C: \ Keil \ ARM \ Inc \ ST \ STM32F10x \ stm32f10x. h (97): error: #35: # error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x. h file )"
Indicates that you did not declare the type of the selected STM chip, In the stm32f10x. h. Find the following code snippet. The following is an English comment to show you how to select it. just remove the comment of the corresponding type of the Board sub-model you use. (important, the register settings for the Board sub-model will be different, if the program does not run properly), if the stm32f107 is interconnected, cancel the annotation of STM32F10X_CL.
To solve the above problems, a basic ARM engineering architecture without errors will be built up. Of course, you need to add relevant code to implement the desired functions, I will introduce the peripherals later!