Port multiplexing and remapping

Port multiplexing and remapping

STM32F1 has many built-in peripherals, and the external pins of these peripherals are multiplexed with GPIO. In other words, if a GPIO can be multiplexed as a function pin of a built-in peripheral, then when this GPIO is used as a built-in peripheral, it is called multiplexing.

Everyone knows that MCUs have serial ports, and STM32 has several serial ports.
For example, STM32F103RCT6 has 5 serial ports. We can check the manual to know that the IOs corresponding to the pins of serial port 1 are PA9 and PA10. Their default function is GPIO, so when PA9 and PA10 pins are used as TX and RX pins of serial port 1, it is port multiplexing.

insert image description here

configuration steps

  1. First of all, to use the IO multiplexing function, you must first turn on the corresponding IO clock and multiplexing function peripheral clock.
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_USART1_CLK_ENABLE();
__HAL_RCC_AFIO_CLK_ENABLE(); //使能辅助功能IO时钟
  1. Then configure the required IO as an alternate function in the GPIOx_MODER register.
  2. Finally, configure other parameters of the IO port, such as up/down and output speed.

In the above three steps, it is realized by HAL_GPIO_Init

GPIO_InitTypeDef GPIO_Initure;

GPIO_Initure.Pin = GPIO_PIN_9;
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
GPIO_Initure.Pull=GPIO_PULLUP; //上拉
GPIO_Initure.Speed=GPIO_SPEED_FREQ_HIGH;//高速
HAL_GPIO_Init(GPIOA,&GPIO_Initure);

Guess you like

Origin blog.csdn.net/Caramel_biscuit/article/details/131943757