EBU5476 Microprocessor System Design Knowledge Point Summary_5 GPIO

GPIO

General Purpose Input Output,

Memory-Mapped IO

Map device, control and other registers into memory. The advantage is that the way to access the device is the same as that of the memory, and there is no need to design complex IO circuits, which is convenient; the disadvantage is that it takes up memory space.

Peripheral-Mapped IO

IO has a dedicated storage area, which is different from memory, and there are also special circuit instructions to access IO. The advantage is to save memory space, and you can clearly know when IO occurs; the disadvantage is that the cost of development and design increases.

GPIO

The general-purpose IO can judge the high and low levels of the pins, and can assign high and low levels to the pins for control.

The stm32 has several groups of GPIOs, each with 16 Pins, which can be configured as modes such as input output pullin pullup, as well as functions such as timers, serial ports, and interrupts.

What is the pull-up mode? If it is not set to pull up and down, when the pin is floating (when the input is not set to high or low level), the floating pin may receive electromagnetic wave interference and other problems, resulting in uncertain input status, there are 0 and 1, Easy to make mistakes.

Pull-down: Transistor control defaults to ground, and defaults to low level when there is no input.

Pull-up: Transistor control is connected to Vdd chip working voltage by default.

1686742220470

Most of the pins have these two functions. When we initialize the GPIO, we choose one, and the register controls the corresponding circuit according to the value.

image-20230614193552367

Input and output signals can really be called "signals". The input is defined as 0-0.5 as low level, 0.5-Vdd as high level, and values ​​outside the range are invalid. The output current is only about 5mA, which is incapable of directly driving some devices. We can use some circuits such as triodes, amplifiers, etc., and the circuit receives a signal to know that "the drive current needs to be output" and then output a large current.

Control

Each GPIO port has:

4 * 32bit configuration registers: Configuration related information, such as in/out, pull-up and pull-down, open-drain output or push-pull output, output frequency, etc.

  • Push-pull output push-pull: can output high and low levels.
  • Open-drain output open-drain: no ability to output high level, if you want to output high level, you need to set up a pull-up circuit to output.

2 * 32bit data registers: Input and output data registers.

1 * 32bit set/reset registers: set or reset registers.

1 * 32bit locking registers: Locking registers.

2 * 32bit alternate function selection register.

Mode

As shown in the figure, there are 32 Pins, each with two bits to set 4 modes (in and out optional analog).

1686743308300

Pull

There are only 3 modes (no pull, pull up, pull down).

1686743360055

data

Input and output data registers are separated.

1686743538223

CMSIS

Let me talk about the definition of the test first:

CMSIS transforms memory mapped registers into C structs

#define PORT0 ((struct PORT*)0x2000030)

1686747214412

Let me talk about the understanding discussed with some embedded seniors. The following content is not allowed to be written in the exam:

Teacher Li Ken: A series of APIs and software components launched by arm-M, including core functions, DSP libraries, RTOS support, and debugging interfaces.

Teacher Li Ken: If the chip factory does not want to add another layer, CMSIS is enough; but some manufacturers will seal another layer on it, which may be called the driver layer.

Teacher Li Ken: In addition, CMSIS has a limitation, which is the ARM Cortex-M processor of ARM; although it is very common, not all processors have this core; this needs attention.

Sakaki: This kind of kernel-related files, such as startup files and kernel files, are stipulated by CMSIS.

a6953d9ebb72f2ecd6cc4dbf569d406

Sakaki: Comparing the startup files of STM32F103 and GD32E23, we will find that they are the same:

711dd8daa73cb3dd198e50f32f6f86a

Sakaki: What chip manufacturers need to do is to re-develop library functions according to the interface specified by this arm.

Mr. Li Ken’s C station account: Architect Li Ken’s Blog_CSDN Blog-Programming Life, Blogger in the Field of Fan Welfare

Mr. Sakaki’s C station account: Feng Zhenghao’s blog_CSDN blog-C language, MSP430F5529, Linux domain blogger

Usually Mr. Li Ken's exchange group will discuss a lot of embedded related issues, welcome interested students to learn [Doge] If you are interested, have
fun.

example:

typedef enum {
    
    
Reset, //!< Resets the pin-mode to the default value.
Input, //!< Sets the pin as an input with no pull-up or pull-down.
Output, //!< Sets the pin as a low impedance output.
PullUp, //!< Enables the internal pull-up resistor and sets as input.
PullDown //!< Enables the internal pull-down resistor and sets as input.
} PinMode;

gpio_set_mode(P1_10, Input);
gpio_set_mode(P2_8, Output);
int PBstatus=gpio_get(P1_10); 
gpio_set(P2_8, 1);

The above code is the driver provided by the teacher. The general idea is to select the pin and pass in specific parameters to set the mode and output.

If you are interested, you can take a look at my article. It is also possible to use the cmsis defined by arm to develop directly:

STM32 study notes_4 GPIO: LED, buzzer, button, sensor usage_Gray sea loose blog-CSDN blog

#include "stm32f10x.h"
int main(void){
    
    
    /* 控制gpio需要三个步骤:开启rcc时钟,初始化,输入输出函数控制 */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
    
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    
    GPIO_SetBits(GPIOA,GPIO_Pin_0);
    while(1){
    
    }
}

The secondary development of drivers can help simplify.

Of course, this paragraph is off topic. The exam is understood as "cmsis is a variable macro definition directly mapped to a register; drivers are to add further behavior to it".

Guess you like

Origin blog.csdn.net/jtwqwq/article/details/131215980