The first time I did this, I felt unsure, so I implemented it on the STM32F103RBT6 board for USART1. The following is the relevant test code:
/****************************************************** ******************************
//Function name: void Uart1_Init(void)
//Function: Serial port (USART1) remapping initialization configuration function, TX PA9~PB6 RX PA10~~PB7
*************************************************** ***************************/
void Uart1_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE); //Enable port B and multiplex function clock
GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE); //Enable port remapping
GPIO_InitTypeDef GPIO_InitStructure;
//Uart GPIO remapping pin initialization PB6 usart1_TX PB7 USART_RX
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; //Push-pull output
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; //Floating input
GPIO_Init(GPIOB,&GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
USART_InitTypeDef USART_InitStructure;
//Serial port parameter configuration: 9600,8,1, no parity check, no hard flow control, enable sending and receiving
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE,ENABLE); //Serial port receive interrupt
USART_Cmd(USART1, ENABLE);
}
A brief analysis of the remapping steps is:
1. Turn on the remapped clock and the USART remapped I/O port pin clock,
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB |RC C_APB2Periph_AFIO,ENABLE);
2.I/O port remapping is enabled.
GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);
3. Configure the remapped pins. Here you only need to configure the remapped I/Os, and the original ones do not need to be configured.
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
Just follow these three steps to get it done easily.
Previous article:Research on one-key download circuit of CH340 in STM32
Next article:STM32 TIM remapping
Recommended ReadingLatest update time:2024-11-16 14:53
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Live broadcast with prizes: Enter the TI robot production class, starting on Friday, reservations are in progress! (Share 100% to get gifts)
- Explanation on DSP devices and general-purpose processors (GPP)
- About electromagnetic shielding
- About Phase Modulation
- I am confused about K60, hope for your advice
- Coding and decoding of MSP430 infrared remote control
- Graduation project help
- It is found that domestic manufacturers like to polish the logo and model outside the chip.
- [Qinheng Trial] CH559EVT Trial 2: Development Environment
- Application design using the FRAM-based MCU MSP430FR57xx series