关于网站建设的图片素材,图片免费转链接,wordpress怎么变中文,湖南移动官网网站建设文章目录 前言一、GPIO_HAL库源码分析1.1 初始化GPIO1.2 HAL_GPIO_Init源码分析GPIO_InitTypeDef初始化结构体HAL_GPIO_Init函数 总结 前言
提示#xff1a;这里可以添加本文要记录的大概内容#xff1a;
例如#xff1a;随着人工智能的不断发展#xff0c;机器学习这门技… 文章目录 前言一、GPIO_HAL库源码分析1.1 初始化GPIO1.2 HAL_GPIO_Init源码分析GPIO_InitTypeDef初始化结构体HAL_GPIO_Init函数 总结 前言
提示这里可以添加本文要记录的大概内容
例如随着人工智能的不断发展机器学习这门技术也越来越重要很多人都开启了学习机器学习本文就介绍了机器学习的基础内容。 一、GPIO_HAL库源码分析
1.1 初始化GPIO
void MX_GPIO_Init(void)
{GPIO_InitTypeDef GPIO_InitStruct {0};/* GPIO Ports Clock Enable */__HAL_RCC_GPIOB_CLK_ENABLE();/*Configure GPIO pin Output Level */HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);/*Configure GPIO pin : PB5 */GPIO_InitStruct.Pin GPIO_PIN_5;GPIO_InitStruct.Mode GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull GPIO_NOPULL;GPIO_InitStruct.Speed GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOB, GPIO_InitStruct);
}上面这个代码是初始化GPIOB的pin5引脚 在这里设置哪个引脚GPIO_InitStruct.Pin GPIO_PIN_5; 设置模式GPIO_InitStruct.ModeGPIO_MODE_OUTPUT_PP为推挽输出 除了推挽输出他还有下面这些
#define GPIO_MODE_OUTPUT_PP 0x00000001u /*推挽输出 */
#define GPIO_MODE_OUTPUT_OD 0x00000011u /*开漏输出 */在这里GPIO_InitStruct.Pull我们是设置是否有上下拉电阻他有以下这些值
#define GPIO_NOPULL 0x00000000u /*! No Pull-up or Pull-down activation */
#define GPIO_PULLUP 0x00000001u /*! Pull-up activation */
#define GPIO_PULLDOWN 0x00000002u /*! Pull-down activation */其中就是无上下拉电阻上拉、下拉电阻的设置
在我们主函数的while循环如下
while (1)
{
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5,GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5,GPIO_PIN_RESET);
HAL_Delay(500);/* USER CODE END WHILE *//* USER CODE BEGIN 3 */
}他就只是对GPIOB pin5输出高低电平点灯
我们主要需要看一下HAL_GPIO_Init函数是如何实现的
1.2 HAL_GPIO_Init源码分析
GPIO_InitTypeDef初始化结构体
GPIO_InitTypeDef这个结构体是用来对于某一个引脚进行初始化存储的结构体 他长下面这样
typedef struct
{uint32_t Pin; /*! Specifies the GPIO pins to be configured.This parameter can be any value of ref GPIO_pins_define */uint32_t Mode; /*! Specifies the operating mode for the selected pins.This parameter can be a value of ref GPIO_mode_define */uint32_t Pull; /*! Specifies the Pull-up or Pull-Down activation for the selected pins.This parameter can be a value of ref GPIO_pull_define */uint32_t Speed; /*! Specifies the speed for the selected pins.This parameter can be a value of ref GPIO_speed_define */
} GPIO_InitTypeDef;第一个成员为pinpin这样表示
#define GPIO_PIN_0 ((uint16_t)0x0001) /* Pin 0 selected */
#define GPIO_PIN_1 ((uint16_t)0x0002) /* Pin 1 selected */
#define GPIO_PIN_2 ((uint16_t)0x0004) /* Pin 2 selected */
#define GPIO_PIN_3 ((uint16_t)0x0008) /* Pin 3 selected */
#define GPIO_PIN_4 ((uint16_t)0x0010) /* Pin 4 selected */
#define GPIO_PIN_5 ((uint16_t)0x0020) /* Pin 5 selected */
#define GPIO_PIN_6 ((uint16_t)0x0040) /* Pin 6 selected */
#define GPIO_PIN_7 ((uint16_t)0x0080) /* Pin 7 selected */
#define GPIO_PIN_8 ((uint16_t)0x0100) /* Pin 8 selected */
#define GPIO_PIN_9 ((uint16_t)0x0200) /* Pin 9 selected */
#define GPIO_PIN_10 ((uint16_t)0x0400) /* Pin 10 selected */
#define GPIO_PIN_11 ((uint16_t)0x0800) /* Pin 11 selected */
#define GPIO_PIN_12 ((uint16_t)0x1000) /* Pin 12 selected */
#define GPIO_PIN_13 ((uint16_t)0x2000) /* Pin 13 selected */
#define GPIO_PIN_14 ((uint16_t)0x4000) /* Pin 14 selected */
#define GPIO_PIN_15 ((uint16_t)0x8000) /* Pin 15 selected */
#define GPIO_PIN_All ((uint16_t)0xFFFF) /* All pins selected */比如GPIO5他变成二进制如下 他的bit5为1是不是和我们上两节课的寄存器联系起来了 如果没有看过的同学可以进入HAL库的本质是操作寄存器来进行学习
接下来看Speed成员 他可以有以下取值
#define GPIO_SPEED_FREQ_LOW (GPIO_CRL_MODE0_1) /*! Low speed */
#define GPIO_SPEED_FREQ_MEDIUM (GPIO_CRL_MODE0_0) /*! Medium speed */
#define GPIO_SPEED_FREQ_HIGH (GPIO_CRL_MODE0) /*! High speed */其中有低速中速和高速 其中低速为2M中速10M高速50M
HAL_GPIO_Init函数
这个函数有两个参数。一个为组号另一个为初始化结构体 首先第一个参数他有如下取值
#define GPIOA ((GPIO_TypeDef *)GPIOA_BASE)
#define GPIOB ((GPIO_TypeDef *)GPIOB_BASE)
#define GPIOC ((GPIO_TypeDef *)GPIOC_BASE)
#define GPIOD ((GPIO_TypeDef *)GPIOD_BASE)
#define GPIOE ((GPIO_TypeDef *)GPIOE_BASE)
#define GPIOF ((GPIO_TypeDef *)GPIOF_BASE)
#define GPIOG ((GPIO_TypeDef *)GPIOG_BASE)
//。。。。。。GPIOx_Base如下
#define GPIOA_BASE (APB2PERIPH_BASE 0x00000800UL)
#define GPIOB_BASE (APB2PERIPH_BASE 0x00000C00UL)
#define GPIOC_BASE (APB2PERIPH_BASE 0x00001000UL)
#define GPIOD_BASE (APB2PERIPH_BASE 0x00001400UL)这些就一起定义了一个组的基地址是什么
接下来我们看HAL_GPIO_Init源码
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
{uint32_t position 0x00u;uint32_t ioposition;uint32_t iocurrent;uint32_t temp;uint32_t config 0x00u;__IO uint32_t *configregister; /* Store the address of CRL or CRH register based on pin number */uint32_t registeroffset; /* offset used during computation of CNF and MODE bits placement inside CRL or CRH register *//* Check the parameters */assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));assert_param(IS_GPIO_PIN(GPIO_Init-Pin));assert_param(IS_GPIO_MODE(GPIO_Init-Mode));/* Configure the port pins */while (((GPIO_Init-Pin) position) ! 0x00u){/* Get the IO position */ioposition (0x01uL position);/* Get the current IO position */iocurrent (uint32_t)(GPIO_Init-Pin) ioposition;if (iocurrent ioposition){/* Check the Alternate function parameters */assert_param(IS_GPIO_AF_INSTANCE(GPIOx));/* Based on the required mode, filling config variable with MODEy[1:0] and CNFy[3:2] corresponding bits */switch (GPIO_Init-Mode){/* If we are configuring the pin in OUTPUT push-pull mode */case GPIO_MODE_OUTPUT_PP:/* Check the GPIO speed parameter */assert_param(IS_GPIO_SPEED(GPIO_Init-Speed));config GPIO_Init-Speed GPIO_CR_CNF_GP_OUTPUT_PP;break;/* If we are configuring the pin in OUTPUT open-drain mode */case GPIO_MODE_OUTPUT_OD:/* Check the GPIO speed parameter */assert_param(IS_GPIO_SPEED(GPIO_Init-Speed));config GPIO_Init-Speed GPIO_CR_CNF_GP_OUTPUT_OD;break;/* If we are configuring the pin in ALTERNATE FUNCTION push-pull mode */case GPIO_MODE_AF_PP:/* Check the GPIO speed parameter */assert_param(IS_GPIO_SPEED(GPIO_Init-Speed));config GPIO_Init-Speed GPIO_CR_CNF_AF_OUTPUT_PP;break;/* If we are configuring the pin in ALTERNATE FUNCTION open-drain mode */case GPIO_MODE_AF_OD:/* Check the GPIO speed parameter */assert_param(IS_GPIO_SPEED(GPIO_Init-Speed));config GPIO_Init-Speed GPIO_CR_CNF_AF_OUTPUT_OD;break;/* If we are configuring the pin in INPUT (also applicable to EVENT and IT mode) */case GPIO_MODE_INPUT:case GPIO_MODE_IT_RISING:case GPIO_MODE_IT_FALLING:case GPIO_MODE_IT_RISING_FALLING:case GPIO_MODE_EVT_RISING:case GPIO_MODE_EVT_FALLING:case GPIO_MODE_EVT_RISING_FALLING:/* Check the GPIO pull parameter */assert_param(IS_GPIO_PULL(GPIO_Init-Pull));if (GPIO_Init-Pull GPIO_NOPULL){config GPIO_CR_MODE_INPUT GPIO_CR_CNF_INPUT_FLOATING;}else if (GPIO_Init-Pull GPIO_PULLUP){config GPIO_CR_MODE_INPUT GPIO_CR_CNF_INPUT_PU_PD;/* Set the corresponding ODR bit */GPIOx-BSRR ioposition;}else /* GPIO_PULLDOWN */{config GPIO_CR_MODE_INPUT GPIO_CR_CNF_INPUT_PU_PD;/* Reset the corresponding ODR bit */GPIOx-BRR ioposition;}break;/* If we are configuring the pin in INPUT analog mode */case GPIO_MODE_ANALOG:config GPIO_CR_MODE_INPUT GPIO_CR_CNF_ANALOG;break;/* Parameters are checked with assert_param */default:break;}//code..................
}这些功能太复杂我们只分析怎么把传入的参数变成输出引脚 他根据mode来进行具体的设置 然后他把数据存储到了config变量中 接下来我们看MODIFY_REG修改寄存器他需要修改指定寄存器并且其他寄存器不被破坏
#define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) (~(CLEARMASK))) | (SETMASK)))在这里WRITE_REG((REG), (((READ_REG(REG)) (~(CLEARMASK))) | (SETMASK)))他要写寄存器REG 他写什么呢首先把寄存器的值读出来 (~(CLEARMASK))清除掉某些位 | (SETMASK)设置某些位这样就达到了修改寄存器且不破坏其他位
在这里configregister (iocurrent GPIO_PIN_8) ? GPIOx-CRL : GPIOx-CRH;他会去确定某个寄存器 总结
提示这里对文章进行总结 例如以上就是今天要讲的内容本文仅仅简单介绍了pandas的使用而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。