ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ST HAL库 GPIO例程学习

2022-07-08 10:34:27  阅读:135  来源: 互联网

标签:HAL 引脚 例程 ++ mode InitTypeDef GPIO


首先,查看文件 stm32f4xx_hal_gpio.c 关于如何使用GPIO外设的说明。

                     ##### How to use this driver #####
  ==============================================================================  
  [..]
    (#) Enable the GPIO AHB clock using the following function: __HAL_RCC_GPIOx_CLK_ENABLE(). 

    (#) Configure the GPIO pin(s) using HAL_GPIO_Init().
        (++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure
        (++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef 
             structure.
        (++) In case of Output or alternate function mode selection: the speed is 
             configured through "Speed" member from GPIO_InitTypeDef structure.
        (++) In alternate mode is selection, the alternate function connected to the IO
             is configured through "Alternate" member from GPIO_InitTypeDef structure.
        (++) Analog mode is required when a pin is to be used as ADC channel 
             or DAC output.
        (++) In case of external interrupt/event selection the "Mode" member from 
             GPIO_InitTypeDef structure select the type (interrupt or event) and 
             the corresponding trigger event (rising or falling or both).

    (#) In case of external interrupt/event mode selection, configure NVIC IRQ priority 
        mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using
        HAL_NVIC_EnableIRQ().
         
    (#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin().
            
    (#) To set/reset the level of a pin configured in output mode use 
        HAL_GPIO_WritePin()/HAL_GPIO_TogglePin().
    
    (#) To lock pin configuration until next reset use HAL_GPIO_LockPin().

                 
    (#) During and just after reset, the alternate functions are not 
        active and the GPIO pins are configured in input floating mode (except JTAG
        pins).
  
    (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose 
        (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has 
        priority over the GPIO function.
  
    (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as 
        general purpose PH0 and PH1, respectively, when the HSE oscillator is off. 
        The HSE has priority over the GPIO function.
  

(#)使用 __HAL_RCC_GPIOx_CLK_ENABLE() 函数使能GPIO AHB时钟

(#)使用 HAL_GPIO_Init() 函数配置GPIO引脚

  (++)使用 GPIO_InitTypeDef 结构体的 Mode 成员,配置 IO 模式

  (++)使用 GPIO_InitTypeDef 结构体的 Pull 成员,配置 上拉/下拉操作

  (++)使用 GPIO_InitTypeDef 结构体的 Speed 成员,配置 IO 速度(仅限输出模式和复用功能模式)

  (++)使用 GPIO_InitTypeDef 结构体的 Alternate 成员,配置 IO 连接的复用功能(仅限复用功能模式)

  (++)当引脚作为 ADC 或 DAC 功能使用时,需要配置为 Analog 模式

  (++)在外部中断或事件模式下,使用 GPIO_InitTypeDef 结构体的 Mode 成员,选择类型(中断或事件)和对应的触发事件(上升沿或下降沿)

(#)在外部中断或事件模式下,使用 HAL_NVIC_SetPriority() 函数和 HAL_NVIC_EnableIRQ() 函数,设置映射到 NVIC line 上的 NVIC IRQ 优先级

(#)在输入模式下,使用 HAL_GPIO_ReadPin() 函数获取引脚上的电平

(#)在输出模式下,使用 HAL_GPIO_WritePin() 或 HAL_GPIO_TogglePin() 函数配置引脚电平

(#)使用 HAL_GPIO_LockPin() 函数,引脚将被锁住,直到下一次复位

(#)在复位操作和复位操作刚完成后,复用功能无效,所有的引脚配置为输入浮空模式(除了 JTAG 引脚)

(#)当内部 LSE oscillator 关闭时,可以使用 OSC32_IN 和 OSC32_OUT 引脚外接 LSE oscillator (此功能优先级高于GPIO功能)

(#)当内部 HSE oscillator 关闭时,可以使用 OSC_IN 和 OSC_OUT 引脚外接 HSE oscillator(此功能优先级高于GPIO功能)

标签:HAL,引脚,例程,++,mode,InitTypeDef,GPIO
来源: https://www.cnblogs.com/xing-2/p/16457316.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有