STM32 UART remapping

Publisher:科技独行者Latest update time:2016-07-30 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
When designing the schematic diagram, I found that there was a conflict between the pin allocations and needed to remap the pins. I learned from the manual that there are many I/O ports on STM32, and there are also many built-in peripherals such as I2C, ADC, ISP, USART, etc. In order to save lead pins, these built-in peripherals basically share pins with I/O ports, that is, the multiplexing function of I/O pins. However, STM32 has another special feature: many I/O pins of multiplexed built-in peripherals can be led out from different I/O pins through the remapping function, that is, the pins of the multiplexing function can be changed through the program.

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.

Keywords:STM32 Reference address:STM32 UART remapping

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

Use of stm32-afio
1. Features of AFIO     To optimize the number of peripherals in a 64-pin or 100-pin package, you can remap some alternate functions to other pins. Set the alternate remapping and debug I/O configuration register (AFIO_MAPR) to achieve pin remapping. In this case, the alternate functions are no longer mapped to their
[Microcontroller]
Use of stm32-afio
STM32: ADC data collection example (using DMA mode)
SOC:STM32F103RCT6 Software platform: STM official library V3.5.0 Development tools: Keil 1. Summary   This article will give the code for STM32F103RCT6 to control AT24C02. If you have any questions or errors, please leave a message. 2. Hardware Connection AT24C02 uses I2C for data access, and the board uses ST
[Microcontroller]
How to deal with STM32 external 12MHz crystal oscillator
How to deal with STM32 external 12MHz crystal oscillator http://www.amobbs.com/thread-4478412-1-1.html (Source: amoBBS Amo Electronics Forum) Since the STM32F10x library officially uses the default external 8MHz crystal, many users also use the 8MHz crystal. However, the 8MHz crystal is not necessary, and other freque
[Microcontroller]
STM32 enters STOP mode and wakes up the experiment summary
The project requires the low power consumption of the device to be realized. Several problems were encountered during the implementation process, and this is recorded and summarized. (stm32f103ret6) Question 1: After executing PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);, the program continues to exe
[Microcontroller]
STM32 enters STOP mode and wakes up the experiment summary
STM32 learning notes 1: selection and pin description
Selection classification   STM32 naming method How to assign schematic pins How to find the pin function description Pin Function Interpretation
[Microcontroller]
STM32 learning notes 1: selection and pin description
STM32-What Beginners Must Know
The core Cortex-M3 processor of STM32 is a standardized microcontroller structure. I hope you will think about what standardization means. In short, the Cortex-M3 processor has a 32-bit CPU, a parallel bus structure, a nested interrupt vector control unit, a debugging system, and a standard memory map. The Nested Vect
[Microcontroller]
[STM32 motor square wave] Record 3——TIM1 time base initialization configuration
Timer classification: In the STM32F1x series, except for the interconnected products, there are a total of 8 timers, which are divided into basic timers, general timers and advanced timers. The basic timer TIM6 and TIM7 are 16-bit timers that can only count up and have no external IO. The general timer TIM2/3/4/5 is a
[Microcontroller]
[STM32 motor square wave] Record 3——TIM1 time base initialization configuration
STM32 interrupt and nested NVIC quick introduction
//================================================ ==== // STM32 interrupt and nested NVIC quick start // netjob 2008-8-1 //================================================ ==== STM32 interrupt and nested NVIC quick introduction I also understood it by reading this book: The Definitive Guide to Cortex-M3
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号