STM32 learning experience 12: port multiplexing and remapping

Record it, easy to read after ~
main elements:
1) port complex;
2) port remapping;
official information: "the STM32 Chinese Reference Manual V10" Chapter 8 General and multiplexing functions IO (GPIO and AFIO)
1. port complex concept with
a lot of built-in peripheral STM32, these peripherals external pins are multiplexed with GPIO. In other words, if a GPIO can be reused as a built-in peripheral function pin, then when the time GPIO as built-in peripheral use, is called multiplexing.
Such as serial transmission and reception pin 1 is PA9 and PA10, when we put PA9 and PA10 is not used as GPIO, and used to send alternate function pin serial port 1 receiver, called port multiplexing.
Here Insert Picture Description
2. Port multiplex configuration process (to PA9, PA10 as serial port Example 1)
2.1 Clock enable the GPIO port (Port Clock Enable):

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

2.2 multiplexed with peripheral clock enable (To port PA9, PA10 multiplexed into a serial port, and therefore enable the serial port clock):

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

2.3 port mode configuration (GPIO port mode settings and look for "STM32 Chinese Reference Manual V10" Learn how to set up alternate function GPIO);
Here Insert Picture Description
2.4 above table shows that you want to configure a full-duplex serial port 1, a push-pull configuration USARTx_TX pins multiplexing output, USARTx_RX floating pins as input or pull-input, part of the code as follows:

//USART1_TX    PA.9 复用推挽输出// 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;              //PA.9// 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;      //速率50MHz//
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;        //复用推挽输出// 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
//USART1_RX    PA.10 浮空输入//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;             //PA10// 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  //浮空输入// 
GPIO_Init(GPIOA,&GPIO_InitStructure);   

3. Port remap the concept of
each peripheral has built a number of input and output pins, these pins output ports generally are fixed, in order to allow design engineers to better organize and function of the pin, STM32 concept was introduced in the peripheral pin remapping, i.e., a peripheral port pin addition to the default, but may also be provided by remapping register mode, this pin is mapped to the other peripheral port .
In order to package various peripheral devices IO functionality optimal number, some multiplexing function can be remapped to the other pins. STM32 has many built-in peripheral input and output pins having remapping (remap) function.
Thus remapping main features: 1) easy PCB design, reducing signal crosstalk; 2) to increase the number of ports.
4. STM32F103x LQFP100 remapping pin
Here Insert Picture Description
5. See "STM32F103ZET6" chip manual
still a serial port, for example, by default, the serial port receive pin 1 is PA9 and PA10 (second from right observation field), may be USART1_TX and remapping USART1_RX PB6 and PB7 pins to go above (as viewed from the right in the first column).
Here Insert Picture Description
6. Some remapping and remapping fully
part remapping : Some pin function peripheral remapping, there is a part of the original default pin pin; completely remap : function peripherals All pins are remapped. In Example 3 Serial:
Here Insert Picture Description
7 Port remapping configuration (to PB6, PB7 as serial port Example 1)
7.1 Clock enable the GPIO port (the port so that the clock can remap):

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

7.2 Enable function peripheral clock (To port PB6, PB7 multiplexed into a serial port, and therefore enable the serial port clock):

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

7.3 Enable AFIO clock (remapping must be enabled AFIO clock):

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE)

7.4 open remapping:

GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);
//根据第一个参数,确定部分重映射还是全部重映射,在stm32f10x_gpio.h文件中定义了取值范围为下面宏定义的标识符://
//#define GPIO_PartialRemap_USART3    ((uint32_t)0x00140010);  //  
//#define GPIO_FullRemap_USART3      ((uint32_t)0x00140030);   //
//若要使用 USART3 的部分重映射,调用函数方法为:                  //
//GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);        //

8. what circumstances need to open AFIO Accessibility clock?
Register before AFIO_MAPR, AFIO_EXTICRX AFIO_EVCR and read and write, it should first open AFIO clock:
. 1) AFIO_MAPR: remapping configuration multiplexing function;
2) AFIO_EXTICRX: external interrupt mapping configuration;
. 3) AFIO_EVCR: Configure EVENTOUT event output.
Knowledge Point
1) review GPIO configuration parameters based library functions, refer to STM32 learning experience three: GPIO experiment - based library functions

Published 24 original articles · won praise 2 · Views 4120

Guess you like

Origin blog.csdn.net/Leisure_ksj/article/details/105313702