Getting Started Tutorial Using HAL Library, STM32CubeMX and Keil 5 Development (Part 1)

Publisher:devilcoreLatest update time:2018-05-06 Source: eefocusKeywords:STM32CubeMX  Keil Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This article is reproduced from http://blog.csdn.net/charmingsun/article/details/50802267. This tutorial aims to light up an LED lamp to demonstrate the general method of developing STM32 programs using STM32CubeMX, Keil, and ST-Link.

STM32F4xx HAL driver instructions

2. Create a new STM32CubeMX project

Open STM32CubeMX and click New Project: 
Open STM32CubeMX and click *New Project*
Select Series, Lines, Package, then select the model of your MCU and click OK: (My MCU is STM32F411RE, 64-pin LQFP package) 
Select *Series*, *Lines*, *Package*, then select the model of your MCU and click *OK*. (My MCU is STM32F411RE, 64-pin LQFP package) 
Now a STM32CubeMX project has been created: 
At this point, a STM32CubeMX project has been created

3. Configure the corresponding pins and then generate the Keil project

Open the development board schematic and check the pins corresponding to the LED light: (As shown in the figure, let the PA5 pin output a high level to light up the LED) 
Open the development board schematic and check the pins corresponding to the LED lights. 
Click Pinout, then click the pin corresponding to the LED light, and select the GPIO_Output mode: (Set PA5 to the output mode of the general input and output port. For details, please refer to the GPIO introduction in the Reference manual) 
Click *Pinout*, then click the pin corresponding to the LED light, and select *GPIO_Output* mode
Since this routine does not require the configuration of clocks, middleware and peripherals, nor does it require the calculation  of power consumption, the Clock Configuration, Configuration, and Power Consumption Caculator remain default.
Click Project->Settings in the menu bar, enter the STM32CubeMX project name, save path, and your own tool chain/integrated compilation environment, keep the settings in Code Generator as default, and then click OK: (My STM32CubeMX project name is LD2, the save path is the desktop, and the integrated compilation environment is Keil 5) 
Click *Project*->*Settings* in the menu bar, enter the STM32CubeMX project name, save path, and your own tool chain/integrated compilation environment, keep the settings in *Code Generator* as default, and then click *OK* 
Then click Project->Generate Code in the menu bar, or click Generate Code shortcutthe shortcut key to generate a Keil project containing the HAL library and initialization code. At this time, a folder named after the STM32CubeMX project name will appear on the corresponding path. Open the folder on the corresponding path. The file with .ioc extension is the STM32CubeMX project file. The folder named with the integrated compilation environment contains the project file of this integrated compilation environment with the name of the STM32CubeMX project. The Drivers directory contains the driver, the Inc directory contains the header file, and the Src directory contains the source code: (LD2.ioc file is the STM32CubeMX project just created, and the LD2.uvprojx file in the MDK-ARM folder is the Keil project just generated) 
Contains Keil project of HAL library and initialization code

4. Add your own code to the Keil project, then compile and download

Open the Keil project and find the place to add code according to the comments. Please do not add code outside the prompt, otherwise it will be deleted when you generate the STM32CubeMX project again: (Because STM32CubeMX has generated the initialization code for us, we only need to add a sentence between /* USER CODE BEGIN 2 / and / USER CODE END 2 */ to make PA5 output high level) 
Open the Keil project and find the place to add code according to the comments. Please do not add code outside the prompts, otherwise it will be deleted when you generate the STM32CubeMX project again.
Open the HAL driver manual to find the API we need, and then add code according to the instructions: (According to the instructions, the code to make PA5 output high level is HAL_GPIO_WritePin (GPIOA, GPIO_PIN_5, GPIO_PIN_SET);) 
Open the HAL driver manual to find the API we need, and then add the code according to the instructions. 
Add code to the project, then click CompileCompile, and click Download after connecting the computer and development board with ST-Link download
Add code to the project, then compile and download

5. After the download is complete, reset the development board, and then the LD2 (green light) of the development board lights up.

After the download is complete, reset the development board, and then the LD2 (green light) of the development board lights up.


Keywords:STM32CubeMX  Keil Reference address:Getting Started Tutorial Using HAL Library, STM32CubeMX and Keil 5 Development (Part 1)

Previous article:In-depth understanding of STM32 memory and bus architecture 1 (based on STM32F411)
Next article:Getting Started Tutorial Using HAL Library, STM32CubeMX and Keil 5 Development (Part 2): GPIO

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号