当前位置:网站首页>Port multiplexing and re imaging
Port multiplexing and re imaging
2022-07-07 09:07:00 【A big cat 1201】
author : A big cat 1201
special column :《STM32 Study 》
Maxim : You just try to , Leave the rest to time !
Port reuse and remapping
describe
Let's take a look at one STM32 Simple structure diagram of 
You can see that in the diagram , Except for the kernel ( That is to say CPU), Another part is built-in peripherals . There are many kinds of built-in peripherals , The number of built-in peripherals of different types of chips is also different , As used by benmew STM32F103ZET6 The serial port of the chip has 5 individual . These built-in peripherals are through GPIO Of Port multiplexing and Remapping To input and output signals
Port multiplexing
Concept :
One GPIO If it can be reused as a function pin of the built-in peripheral , So when this GPIO When used as a built-in peripheral , It's called reuse .
With USART1( A serial port 1) Take port multiplexing as an example .

This is a STM32F103ZET6《 Data manual 》 A partial screenshot of the pin information description table in .
You can see
- PA9 and PA10 The main functions of PA9 and PA10. That is, general input and output function .
- Among the selectable functions, the default reuse function is USART1_TX( A serial port 1 Send pin ) and USART1_RX( A serial port 1 Receive pin ).
At this point we can say ,USART1_TX and USART1_RX Is reused in GPIO Of PA9 and PA10 Oral .
Configuration process of port multiplexing
After we know what class port reuse is, we need to configure it , How else can the chip know GPIO Is the port used as a general input and output port or a port multiplexing port ?
- GPIO Clock enable
Port reuse is still used in the final analysis GPIO, Therefore, it is necessary to check the corresponding GPIO Carry out enabling . With USART1 For example , We know that it reuses GPIO yes PA Of the group IO mouth , So you need to GPIOA Carry out enabling .
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
In this meow's article STM32 Our clock system As mentioned in GPIO Is attached to APB2 Under the bus , So this function is used .
- Multiplex peripheral clock enable
No matter what peripherals are used , Not only does it use GPIO, And the peripheral itself should also be used , Therefore, when using built-in peripherals, it is also necessary to enable . With USART1 For example
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
USART1( A serial port 1) It is also attached to APB2 On the bus .
- Port mode configuration
Will be GPIO and USAR1 Enable later , Next we need to tell CPU The IO The port uses the port multiplexing function .
stay STM32F103ZET6 Chip 《 Chinese Reference Manual 》 In the reuse function configuration table , Lists in detail when port multiplexing ,GPIO How to configure . That is to say GPIO The initialization .
With USART1_TX and USART1_RX For example :
USART1_TX( The sender )
- In full duplex mode ,GPIO It needs to be configured into push-pull multiplexing output mode .
USART1_RX( The receiver )
- In full duplex mode ,GPIO It needs to be configured as floating input or pull-up input .
In the code
GPIO_TypeDef GPIO_InitStructyre;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9// Multiplexing push pull output
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10 PA.10 Floating input
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;// Floating input
GPIO_Init(GPIOA, &GPIO_InitStructure);
The above is based on USART1 For example , The whole process of port multiplexing configuration . After the above configuration ,PA9 and PA10 And it became USART1_TX and USART1_RX The pin of , It is no longer a general input and output port .
Port reimage
Port remapping is actually similar to port multiplexing , Port multiplexing is built-in peripherals, and the multiplexing port is fixed , It is necessary to find the multiplexing corresponding to different peripherals through the pin description in the data manual GPIO mouth .
The mapped port of port remapping is also fixed , It also needs to be found by looking up the table , The mapping port and multiplexing port are not the same .
Concept :
- The pin of a peripheral has a default port , You can also set the remapping register , Map the pins of this peripheral to other ports .
Purpose :
- In order to allow design engineers to better arrange the direction and function of pins , Potentially reduce the cross interference of signals .

This is a STM32F103ZET6 chip 《 Chinese Reference Manual 》 Re image configuration table in . With USART1 For example , The table shows ,USART1_TX and USART1_RX After remapping GPIO The mouth is PB6 and PB7.
It can also be done through 《 Data manual 》 See in the pin description table in ,PB6 and PB7 Among the selectable functions , After remapping, the corresponding is USART1_TX and USART1_RX.
Port remapping is also divided into incomplete remapping and complete remapping
Partial re image and full re image

With USART3 For example , stay 《 Chinese Reference Manual 》 In the re image configuration table of ,USART3 A common need 5 One pin , Namely USART3_TX,USART3_RX,USART3_CK,USART3_CTS,USART3_RTS.
When there is no re image
- This 5 Ports use the port multiplexing function by default , They correspond to PB10 To PB14.
When partially reimaging
- among USART3_TX,USART3_RX,USART3_CK These three ports are no longer port multiplexed PB10 To PB12, But the remake became PC10 To PC12, and USART3_CTS and USART3_RTS It still corresponds to port multiplexing PB13 and PB14.
Complete remapping
- USART3 Of 5 All ports are reimagined to the new port , Corresponding PD8 To PD12 Five ports .
in general , Partial remapping refers to the remapping of some pins of built-in peripherals , There are also some pins corresponding to the default port multiplexing . Full remapping means that all pins of built-in peripherals are remapped .
The configuration process of re image
After knowing what is re image , We are going to use it .
- Enable remapped GPIO.
After remapping, the new GPIO, So it is necessary to enable , Only after enabling, should IO Eloquence will be opened . With USART3 For example :
When partially reimaging :
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
After partial remapping, two groups are used IO mouth , So you need to GPIOC and GPIOB Are enabled
Complete remapping
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
After completely remapping ,USART3 Of 5 All pins are remapped to GPIOD Of the group IO On the mouth , So just enable GPIOD that will do .
- Enable built-in peripherals
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
In the article on clock system, Ben meow mentioned ,USART3 It's mounted on APB1 On the bus , So the function used is this .
- Can make AFIO The clock
For registers AFIO_MAPR,AFIO_EXTICRX and AFIO_EVCR Before reading and writing , Should be opened first AFIO The clock .
- AFIO_MAPR: Configure reuse function remapping
AFIO_EXTICRX: Configure external breakline mapping
AFIO_EVCR: To configure EVENTOUT Event output
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
AFIO The function auxiliary register is generally mounted in APB2 On the bus , So use this function .
- Turn on the re image
After enabling the required registers, we go to the last step , Configure reimage .
We started with GPIO Find the function to open the re image in the relevant functions GPIO_PinRemapConfig().
The first parameter of this function has many , As shown in the above figure , Pass the parameters representing the peripherals corresponding to the re image and the re image mode to the start re image function .
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);// Partial remapping
GPIO_PinRemapConfig(GPIO_FullRemap_USART3,ENABLE);// Complete remapping
The second parameter only ENABLE and DISABLE, That is, decide whether to enable the re image .
After the above 4 Step by step, you will succeed USART3 Some ports of are remapped to PC10 To PC12, Or all ports are remapped to PD8 To PD12 On .
summary
Whether it is port multiplexing or port re imaging , All for the purpose of using the built-in peripherals of the chip , Only through port multiplexing or re imaging GPIO To connect with built-in peripherals , Deliver information to peripherals . Generally, port multiplexing is enough for us .
边栏推荐
- LeetCode 715. Range 模块
- 硬件大熊原创合集(2022/06更新)
- STM32串口寄存器库函数配置方法
- Vagrant failed to mount directory mount: unknown filesystem type 'vboxsf'
- Common operating commands of Linux
- 面板显示技术:LCD与OLED
- Ppt template and material download website (pure dry goods, recommended Collection)
- 5A summary: seven stages of PMP learning
- ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
- 个人力扣题目分类记录
猜你喜欢

串口实验——简单数据收发

H3C VXLAN配置

E-commerce campaign Guide

Druid monitoring - Introduction to JMX usage and principle

Mountaineering team (DFS)

Serial port experiment - simple data sending and receiving

Recommended by Alibaba P8, the test coverage tool - Jacobo is very practical

Unityshader introduction essentials personal summary -- Basic chapter (I)

硬核分享:硬件工程师常用工具包

PMP Exam Preparation experience systematically improve project management knowledge through learning
随机推荐
Why is access to the external network prohibited for internal services of the company?
Uniapp wechat applet monitoring network
Problems encountered in the use of go micro
Pointer advanced, string function
Three updates to build applications for different types of devices | 2022 i/o key review
Un salaire annuel de 50 W Ali P8 vous montrera comment passer du test
测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
个人力扣题目分类记录
Screen automatically generates database documents
Redis fault handling "can't save in background: fork: cannot allocate memory“
年薪50w阿里P8亲自下场,教你如何从测试进阶
串口實驗——簡單數據收發
PMP Exam Preparation experience systematically improve project management knowledge through learning
2020 year end summary
Count the number of words C language
OpenGL三维图形绘制
What is the use of PMP certificate?
面试题:高速PCB一般布局、布线原则
Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
[MySQL] detailed explanation of trigger content of database advanced
