Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the different GPIO drivers for STM32

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces what different GPIO drivers STM32 has, which is very detailed and has a certain reference value. Friends who are interested must finish it!

1 Library function version

The most commonly used version, using the ST standard peripheral library

Void Led_Key_Init (void) {GPIO_InitTypeDef GPIO_Init_s; RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOE, ENABLE); / / enable clock GPIO_Init_s.GPIO_Pin = GPIO_Pin_4; GPIO_Init_s.GPIO_Mode = GPIO_OType_PP; GPIO_Init_s.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init_s.GPIO_PuPd = GPIO_PuPd_UP GPIO_Init (GPIOE, & GPIO_Init_s);}

Open source code:

Https://github.com/strongercjd/STM32F207VCT6/tree/master/06-GPIO-Input-Output

2 register version

The register version actually copies the ST standard peripheral library, which can simplify some operations.

/ * use the register-start*///TP---PA15 # define TP_PORT GPIOA # define TP_PIN GPIO_Pin_15 # define TP_OUT () TP_PORT- > CRH&=0X0FFFFFFF; TP_PORT- > CRH | = 0X50000000; / /! IO output # define TP_IN () TP_PORT- > CRH&=0X0FFFFFFF; TP_PORT- > CRH | = 0X40000000 / /! IO enter # define TP_READ () ((TP_PORT- > IDR) > 15)? 1:0) / /! BSRR = TP_PIN;// write 1#define TP_CLR () TP_PORT- > BRR = TP_PIN / / write 0#define TP_DATA_SET () TP_SET () / / IO write 1#define TP_DATA_CLR () TP_CLR () / / IO write 0#define TP_DATA_OUT () TP_OUT () / / set IO to output # define TP_DATA_IN () TP_IN () / / set IO as input # define TP_DATA_READ () TP_READ () / / read the level of IO / * use registers-end*/

Open source code:

Https://github.com/strongercjd/STM32F207VCT6/tree/master/06-GPIO-Input-Output

3-bit segment version

Based on bit segment, easy to operate

/ * LED configuration-PE4*/#define GPIO_IDR_OFFSET (GPIOE_BASE+0x10-PERIPH_BASE) # define GPIO_ODR_OFFSET (GPIOE_BASE+0x14-PERIPH_BASE) # define GPIO_BitNumber 4#define GPIO_OUT_BB (PERIPH_BB_BASE + (GPIO_ODR_OFFSET * 32) + (GPIO_BitNumber * 4)) # define GPIO_OUT_DATA * (_ IO uint32_t *) GPIO_OUT_BB # define GPIO_ IN_BB (PERIPH_BB_BASE + (GPIO_IDR_OFFSET * 32) + (GPIO_BitNumber * 4)) # define GPIO_IN_DATA * (_ _ IO uint32_t *) GPIO_IN_BB # define GPIO_DIR_REG * (_ _ IO uint32_t *) (GPIOE_BASE+0X00) # define PE4_SET () GPIO_OUT_DATA = 1 / /! < IO write 1#define PE4_CLR () GPIO_OUT_DATA = 0 / /! < IO write 0#define PE4_OUT () GPIO_DIR_REG = (GPIO_DIR_REG) & 0xFFFFFCFF) | 0x00000100) / /! IO output # define PE4_IN () GPIO_DIR_REG = ((GPIO_DIR_REG) & 0xFFFFFCFF) /! IO input # define PE4_READ () GPIO_IN_DATA / /!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report