Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the different GPIO drivers for STM32

Shulou Source: shulou.com Published: 2022-06-01 07:44:15 09月26日 Update

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 / /!

Tags: Code register input output driver different content peripheral standard article configuration value interest function base base address boy buddy that is commonly used Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux Redmi Shulou Information vpn