How to create a project library using stm32

Source: Internet
Author: User

(1) Open the main interface of keilmdk and you will see a default project in the project. Click the project name and select project> close project to close the project! In this way, the entire MDK is empty. Next we will create our project template.

(2) Before creating a project, we recommend that you create a directory under a directory on your computer. All the projects created later can be placed under this directory. Here, we create a directory named development code.

(3) Click the "project"> "New uvision project" menu of Keil, and locate the folder under the postal code created just now, create a sub-Folder user under this folder (all the project files of our code are placed in the user folder), locate the sub-folder under the user folder, and save all the project files to the user folder. Name the project as your code and click Save.

(4) Next we will see a device selection interface, which is to select our chip model. Here we find the stm32f103ze below STMicroelectronics.


(5) The dialog box "Copy stm32 startup code to project..." appears ....", Ask if you want to join? Start the code to our project. Here we select "no" because the st Firmware Library file we use already contains the Startup File.

(6) Now let's look at the following three files in the user folder:

(7) Next, we will create three folders, core, OBJ, and stm32f10x_fwlib, under the release code project folder. Core is used to store core files and startup files. obj is used to store compilation process files and hex files. The stm32f10x_fwlib folder is used to store the library function source code files officially provided by St. In addition to the project file, the existing user folder is used to store the main function file main. C and other files including system_stm32f10x.c.


(8) Below we will copy the source code files in the official Firmware Library package to the following folder in our project folder. Open the official Firmware Library package and find the folder of the Firmware Library package we have prepared.
Stm32f10x_stdperiph_lib_v3.5.0 \ libraries \ stm32f10x_stdperiph_driver and below, copy the SRC and INC folders below the folder to the folder of stm32f10x_fwlib we just created. SRC stores the Firmware Library. c files and INC are stored accordingly. h file, you 'd better open these two file folders and view the files in them. Each peripheral has a corresponding one. c file and. h header file.


(9) below we will copy the startup files in the Firmware Library package to the core of our project folder.
Open the official Firmware Library package and go to the folder.
Stm32f10x_stdperiph_lib_v3.5.0 \ libraries \ cmsis \ cm3 \ coresupport and convert the file core_cm3.c and the file core_cm3.h to the core. Then, set the value to the directory stm32f10x_stdperiph_lib_v3.5.0 \ libraries \ cmsis \ cm3 \ devicesupport \ ST \ stm32f10x \ Startup \ arm and copy the startup_stm32f10x_hd.s file to the core file. Chips of different capacities use different boot files. Our chip stm32f103zet6 is a large-capacity chip, so select this boot file.
Now let's look at the files below our core directory:


(10) locate the folder:
Stm32f10x_stdperiph_lib_v3.5.0 \ libraries \ cmsis \ cm3 \ devicesupport \ ST \ stm32f10x and copy the three files stm32f10x. H, system_stm32f10x.c, and system_stm32f10x.h to the user folder. Then, four files under stm32f10x_stdperiph_lib_v3.5.0 \ project \ stm32f10x_stdperiph_template
Main. C, stm32f10x_conf.h, stm32f10x_it.c, and stm32f10x_it.h are copied to the user folder.


(11) In the first 10 steps, we copied the required Firmware Library files to the following folder of our project. Can we add these files below? In our project. Right-click target1 and choose manage components


(12) In the project targets column, we change the target name to the Organization Code, delete a sourcegroup1 field in the groups column, and create three groups: User, core, and fwlib. Click OK to view the target name and group information.


(13) which of the following can we add to the group? The files we need. Follow the steps in step 12 to right-click tempate and select Manage components. Then select add? The group of the file. Here we select fwlib for the first step, and then click Add files on the right side to set the path to the directory we just created: stm32f10x_fwlib/src, select all the files (CTRL + a), click Add, and close. the files list contains the following information? . Here we need to explain that for code writing, if we only use one of the peripherals, we don't need to join? Library files of peripherals that are not practical. For example, if I only use gpio, can I just add it? Stm32f10x_gpio.c while other functions do not need to be added ?. Here we all join? Come in for convenience. Don't join every time ?, Of course, this disadvantage is that the project is too large and the compilation speed is slow, so you can choose your own.



(15) Next we need to compile the project. Before compiling, We need to select to compile the intermediate file and store the folder. Click the magic wand and select folder for objects… under the "output" option ...", Then select the folder as the OBJ folder we created above.



16) Click compile button to compile the project. Many errors are reported because the library file cannot be found.


17) Below we will tell the MDK to find the required header file under which paths, that is, the header file folder. Return to the Project Main Menu, click the magic wand, and a menu is displayed. Then, click the C/C ++ option, and then click the button on the Right of include paths. Pop up a join? Path dialog box, then we add the three folders in the figure? Go in. Remember, Keil only searches for level-1 folders. If you still have subfolders under your folder, remember to find the level-1 subfolders in path. Then click OK.

18) Next, let's compile the project and we can see that many identical errors have been reported. Why ?? We can double-click the error and locate the error in the file stm32f10x. H. We can see the code: # If! Defined (stm32f10x_ld )&&! Defined (stm32f10x_ld_vl )&&! Defined (stm32f10x_md )&&! Defined (stm32f10x_md_vl )&&! Defined (stm32f10x_hd )&&! Defined (stm32f10x_hd_vl )&&! Defined (stm32f10x_xl )&&! Defined (stm32f10x_cl) # error "Please select first
Target stm32f10x device used in your application (in stm32f10x. h file) "# endif this is because the library function of version 3.5 selects the macro definition when configuring and selecting peripherals, therefore, we need to configure a general macro variable. In step 16, set the position to the C/C ++ interface, and then copy "stm32f10x_hd, use_stdperiph_driver" to the define input box. Here, we will explain that if you use medium capacity, you can change the stm32f10x_hd to stm32f10x_md, and the small capacity to stm32f10x_ld. then click OK.

19) before compilation, we should remember to Open main. C below the project usur and copy the following code to overwrite
Code is available and then compiled. (Remember to add a carriage return at the end of the Code, otherwise there will be a warning), you can see,
This compilation is successful.

# Include "stm32f10x. H"
Void delay (u32 count)
{
U32 I = 0;
For (; I <count; I ++ );
}
Int main (void)
{
Gpio_inittypedef gpio_initstructure;
Rcc_apb2periphclockcmd (rcc_apb2periph_gpiob |
Rcc_apb2periph_gpioe, enable); // enables Pb, PE port clock
Gpio_initstructure.gpio_pin = gpio_pin_5;
// Led0 --> pb.5 port configuration
Gpio_initstructure.gpio_mode = gpio_mode_out_pp;
// Push-pull output
Gpio_initstructure.gpio_speed = gpio_speed_50mhz;
// The IO port speed is 50 MHz.
Gpio_init (gpiob, & gpio_initstructure );
// Initialize gpiob.5 Based on the set number of workers
Gpio_setbits (gpiob, gpio_pin_5 );
// Pb.5 High Output
Gpio_initstructure.gpio_pin = gpio_pin_5; // led1 --> pe.5 port configuration, push and pull the output
Gpio_init (gpioe, & gpio_initstructure );
// Push-pull output with the IO port speed of 50 MHz
Gpio_setbits (gpioe, gpio_pin_5 );
// Pe.5 High Output
While (1)
{
Gpio_resetbits (gpiob, gpio_pin_5 );
Gpio_setbits (gpioe, gpio_pin_5 );
Delay (3000000 );
Gpio_setbits (gpiob, gpio_pin_5 );
Gpio_resetbits (gpioe, gpio_pin_5 );
Delay (3000000 );
}
}

20) the establishment of such a project template is complete. The following also requires configuration so that the Hex file can be generated after compilation. Same click
Magic wand, go to the configuration menu, and select output. Check the three options. In this example, create HEX file is the encoding method.
The Hex file is generated. browser information allows you to view variables and function definitions. And we have to choose
In which folder is the Hex file and project intermediate file produced, click "select folder for objects ..." Positioning
To the OBJ folder created above.


21) Compile the code again. We can see that the Hex file generated is under the OBJ folder. We use mcuisp to download this file.
To MCU.
Here, a Project template based on the Firmware Library v3.5 is created.


How to create a project library using stm32

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.