Establishment of STM32F4XX template based on Nucleo Development Board and configuration of St-link

Source: Internet
Author: User

This article will build an engineering template based on the Nucleo Development Board and KEIL5.14, consisting of a few parts:

1, the establishment of the project template2, the Stlink set and the Forever water lamp
1, the establishment of the project template1) before building the project, first set up a folder to store the template files, we call it template。 Then set up 6 subfolders: Doc,libraries,listing,output,project,user, set up cmsis and Fwlib folders in Libraries, set up startup in Cmsis, The names of these folders can be arbitrarily taken, so the name is only for easy identification. There will be a description of what files these folders are used to hold. The new directory structure is as shown in 1.1. Figure 1.1    file directory Structure2) Next open Keil, click the Keil menu; Project->new project, and then locate the directory under the project folder that you just created. While the project name is saved as template Click, our project files are placed under the project folder. The operating procedure is shown in 1.2Figure 1.2Engineering Establishment3) Next there will be a choice of device interface, that is, we choose the specific CPU chip model, for our board, we choose Stm32f411re, the process must choose the correct. Figure 1.3Chip Model SelectionClick OK,MDK will pop upManage run-time Environmentdialog box, shown in 1.4. This is a new feature of MDK5, where we can add the components we need to make it easier to build a development environment where we don't introduce more. So in Figure 1.4 we just click Cancel. Figure 1.4    Manage run-time Environment Interface 4)below we are going to copy the source code from the official firmware repository into our catalog folder. FindStm32f4xx_dsp_stdperiph_lib\libraries\stm32f4xx_stdperiph_driver, copy the Src,inc folder under its directory to the Fwlib folder we just created, SRC stores the. c files for the firmware Library, and Inc stores the corresponding. h files, as shown in 1.5. 1.5Official Library source folder5) Below we copy the boot-related code from the firmware library into our project catalog core.
Open the official firmware package and navigate to the directory. \stm32f4xx_dsp_stdperiph_lib\libraries\cmsis\device\st\stm32f4xx\source\templates\arm, will Startup_ STM32F411XE.S Copy to the Startup folder under the CMSIS folder, and then navigate to the directory Stm32f4xx_dsp_stdperiph_lib\libraries\cmsis\include, where the core_ Cm4.h, Core_cmfunc.h, core_cminstr.h, core_cmsimd.h Copy to the Cmsis folder1.6files under the Cmsis folder        6)next Copy the project template requires some additional header files and source files to the project. Navigate to the directory first:Stm32f4xx_dsp_stdperiph_lib\libraries\cmsis\device\st\stm32f4xx\include will be inside the two header files Stm32f4xx.h, system_ Stm32f4xx.hcopy under the Cmsis folder. Re-entrystm32f4xx_dsp_stdperiph_lib\project\stm32f4xx_stdperiph_templates, put one of themain.c, Stm32f4xx_conf.h, stm32f4xx_it.c, stm32f4xx_it.h, system_stm32f4xx.c are copied to the user folder. 7)after the first 6 steps we copied the contents of the firmware library into the project catalog and now add them to the project. Open the project, right-click Target1, select Manage Compoments, in Project targets column, we will change Target1 name to template,groups column to delete the source Group1, Build 5 Groups:as shown in Doc, CMSIS, Fwlib, USER, startup,1.7Figure 1.7New Groups    8) To groups to add files to the folder we created before, for the code we generally only need to use some of these peripherals, just add those peripherals can be created here to create a template, so all add, easy to modify later. In addition STM32F4XX_FSMC.C, STM32F4XX_CEC.CTM32F4XX_FMC.C, STM32F4XX_FMPI2C.C, STM32F4XX_QSPI.Cstm32f4xx_spdifrx.cneed to be removed, otherwise compile error, 1.8Figure 1.8do not delete library causes compilation error . Figure 1.9add files to Fwlib9)next to set the header file storage path, is to tell MDK where to find the header file, if not set the error will occur. Operation 1.10, figure 1.11 shows.
Figure 1.10    Set header file path 
Figure 1.11 Setting the header file pathhere we want to add the path of the header file to \libraries\fwlib\inc, \user, \libraries\cmsis, note is \libraries\fwlib\inc, not\libraries\fwlib\src, don't make a mistake.10) Next we want to compile the project, before compiling we have to choose to compile the intermediate file compiled after the directory. By clicking on the Magic Wand and selecting "Output" under "Select folders of objects ..."Then select the new output for us, and the Create hex file is selected. "Listing" is alsothe "Select folders of objects ..."Choose the new listing for us. 1. As shown in 12.     Figure 1.12selection of compiled output folder 11) Replace the MAIN.C with the content before compiling
  1. 1#include"stm32f4xx.h"2 Voiddelay (__io uint32_t ncount);3 Voiddelay (__io uint32_t ncount)4 {5      while(ncount--);6 }7 intMainvoid)8 {9     gpio_inittypedef gpio_initstructure;Ten    Rcc_ahb1periphclockcmd (rcc_ahb1periph_gpioa,enable); OneGpio_initstructure.gpio_pin =gpio_pin_5; AGpio_initstructure.gpio_mode =gpio_mode_out; -Gpio_initstructure.gpio_otype =gpio_otype_pp; -Gpio_initstructure.gpio_speed =Gpio_speed_100mhz; theGPIO_INITSTRUCTURE.GPIO_PUPD =gpio_pupd_up; -Gpio_init (gpioa,&gpio_initstructure); -     while(1) -   { +    gpio_setbits (gpioa,gpio_pin_5); -Delay (0x7fffff); + gpio_resetbits (gpioa,gpio_pin_5); ADelay (0x7fffff); at}
    24}
At the same time, we want to talk about the contents of the stm43f4xx_it.c file below the user group, or delete the contents of the Systick_handler functions of the # include "Main.h" and 144 rows of the 32 rows. The compilation will then see if there are any errors and the final compilation succeeds. This template has been established successfully 2, the St-link set and the Forever water lamp1) Tap the Magic Wand, choose Debug, select St-link Debugger in the drop-down menu, and set Ort to SWD in the setting menu, speed Select 4MHZ and then click Flash Download to program, Verify and reset and run selected, Action 2.1, figure 2.2, figure 2.3
Figure 2.1Settings for St-link 
Figure 2.2st-link Debug Settings 
Figure 2.3settings for Flash download2) After the completion of the download button can be clicked, you can see the light on the board is flashing, not each.
 Attach specific code



From for notes (Wiz)



List of attachments
    • 00.png
    • 00_2.png
    • 01.png
    • 02.png
    • 03.png
    • 04.png

Establishment of STM32F4XX template based on Nucleo Development Board and configuration of St-link

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.