使用STM32CubeMX新建小熊派的STM32L431RCT6工程实现LED灯闪烁

作者介绍

刘懿宵,男,西安工程大学电子信息学院,2017级本科生。
专业:通信工程
电子邮件:yixiao_liu1999@163.com

工程生成步骤

双击打开软件

在这里插入图片描述

新建一个工程

在这里插入图片描述

芯片选型

本文以为小熊派的STM32L431RCT6为例
在这里插入图片描述

配置GPIO

本文配置GPIO_PC13为输出模式
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
基于开发板原理图,自定义PC13用户标签为LED
在这里插入图片描述

配置系统时钟

本文使用系统内部时钟,配置为最高频率80MHz
在这里插入图片描述

设置目录、工程名、编辑使用的IDE等

在这里插入图片描述

生成工程

在这里插入图片描述

打开工程

在这里插入图片描述

打开工程的小插曲:STM32 Keil新建工程报错“Loading PDSC Debug Description Failed for STMicroelectronics STM32Lxxxxxxx”

在这里插入图片描述
在这里插入图片描述

File       : d:\lanqiao\Keil_v5\ARM\PACK\Keil\STM32L4xx_DFP\2.2.0\Keil.STM32L4xx_DFP.pdsc 
Sequence   : CheckID 
Context    : Item #1: <control if="jep106id != 0x20">
                 Item #0: <block>::Line 2 
Expression : "              Message(2, "Not a genuine ST Device! Abort connection.");" 
----------------------------^ 
E203       : Undefined identifier - function 'Message'

解决方案

  • 进入路径d:\lanqiao\Keil_v5\ARM\PACK\Keil\STM32L4xx_DFP\2.2.0找到Keil.STM32L4xx_DFP.pdsc 文件
    在这里插入图片描述
  • 用记事本打开,找到Message(2, “Not a genuine ST Device! Abort connection.”);将其删除或屏蔽
    在这里插入图片描述
    在这里插入图片描述
  • 保存文件并关闭工程重新打开
    在这里插入图片描述
    可正常使用

代码编写

* 使用stm32l4xx_hal_gpio.h中的270行的GPIO相关函数
	******************************************************************************
  * @file    stm32l4xx_hal_gpio.h
  * @author  MCD Application Team
  * @brief   Header file of GPIO HAL module.
  ******************************************************************************
	* IO operation functions ****************************************************
	* GPIO_PinState     HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
		* @brief  Read the specified input port pin.																							
  	* @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L4 family		
  	* @param  GPIO_Pin specifies the port bit to read.																				
  	*         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).			
		* @retval The input port pin value.																												
		*@概述		读取指定的输入端口pin。
		*@参数		其中x可以是(A..H)来选择STM32L4系列的GPIO外围设备
		*@参数		指定要读取的端口位。此参数可以是GPIO_Pin_x的任意组合,其中x可以是(0..15)
		*@返回值	输入端口pin值
	* void              HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
		  * @brief  Set or clear the selected data port bit.
			*
			* @note   This function uses GPIOx_BSRR and GPIOx_BRR registers to allow atomic read/modify
			*         accesses. In this way, there is no risk of an IRQ occurring between
			*         the read and the modify access.
			*
			* @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L4 family
			* @param  GPIO_Pin specifies the port bit to be written.
			*         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
			* @param  PinState specifies the value to be written to the selected bit.
			*         This parameter can be one of the GPIO_PinState enum values:
			*            @arg GPIO_PIN_RESET: to clear the port pin
			*            @arg GPIO_PIN_SET: to set the port pin
			* @retval None
			*@概述		设置或清除选定的数据端口位。
			*@说明		此函数使用GPIOx\u BSRR和GPIOx\u BRR寄存器来允许原子读取/修改访问。这样,就不会有IRQ发生的风险读取和修改访问。
			*@参数		GPIOx,其中x可以是(A..H)来选择STM32L4系列的GPIO外围设备
			*@参数		GPIO\u Pin指定要写入的端口位。此参数可以是GPIO_Pin_x的任意组合,其中x可以是(0..15)。
			*@参数		 PinState指定要写入选定位的值。此参数可以是GPIO\U PinState枚举值之一:
			*@arg GPIO\u PIN\u RESET:清除端口PIN
			*@arg GPIO\u PIN\u 	 SET:设置端口PIN
			*@返回值	无
	* void              HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
		* @brief  Toggle the specified GPIO pin.
		* @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L4 family
		* @param  GPIO_Pin specifies the pin to be toggled.
		* @retval None
		*@概述		切换指定IO口的电平。
		*@参数		GPIOx,其中x可以是(A..H)来选择STM32L4系列的GPIO外围设备
		*@参数		GPIO\u Pin指定要切换的Pin此参数可以是GPIO_Pin_x的任意组合,其中x可以是(0..15)。
		*@返回值	无
	* HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
		* @brief  Lock GPIO Pins configuration registers.
		* @note   The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
		*         GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
		* @note   The configuration of the locked GPIO pins can no longer be modified
		*         until the next reset.
		* @param  GPIOx where x can be (A..H) to select the GPIO peripheral for STM32L4 family
		* @param  GPIO_Pin specifies the port bits to be locked.
		*         This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
		* @retval None
		*@概述 		Lock GPIO Pins配置寄存器。
		*@说明		锁定的寄存器是GPIOx\u MODER,GPIOx\u OTYPER,GPIOx\u ospeder,GPIOx\ U PUPDR、GPIOx\ U AFRL和GPIOx\ U AFRH。
		*@说明		锁定的GPIO引脚的配置不能再修改直到下一次复位。
		*@参数		GPIOx,其中x可以是(A..H)来选择STM32L4系列的GPIO外围设备
		*@参数		GPIO\u Pin指定要锁定的端口位。此参数可以是GPIO_Pin_x的任意组合,其中x可以是(0..15)。
		*@返回值	无
	* void              HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);
		* @brief  Handle EXTI interrupt request.
		* @param  GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
		* @retval None
		*@概述 		Handle EXTI中断请求 。
		*@参数		GPIO\u Pin指定连接到EXTI线的端口PIN
		*@返回值	无
	* void              HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
		* @brief  EXTI line detection callback.
		* @param  GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
		* @retval None
		*@概述 		EXTI line detection的回调。
		*@参数		GPIO\u Pin指定连接到EXTI线的端口PIN
		*@返回值	无
**/

程序下载

仿真器设置

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

效果

LED闪烁

往期回顾

2021物联网开发学习自学历程记录汇总


版权声明:本文为qq_42754570原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。