STM32F103ZET6 — Port Remap

Publisher:WhisperingWindLatest update time:2018-08-14 Source: eefocusKeywords:STM32F103ZET6 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

When I was about to play with the advanced timer TIM1 / TIM8 on STM32F103ZET6, I suddenly found some port multiplexing problems:

The pins of TIM1 are as follows:


The pins of USART2 are as follows:


The default value of the remap register AFIO is 0x0000 0000

This means that the above-mentioned PA9 and PA10 are used by both USART2 and TIM1. This makes me very confused. What are the functions of these pins and how to configure them?

I found some relevant instructions on the Internet, but I dare not keep them to myself, so I quickly posted them here:


In order to save IO resources, the microcontroller will reuse many functions on one IO. Generally, after using one function, the microcontroller can use two external multiplexed functions. This reflects the powerful function of STM32 GPIO. We use the remapping method to map one of the peripherals to other IO pins, so that we can make full use of the on-chip resources!

1. It is a misunderstanding that you must turn on the AFIO clock if you use IO multiplexing.

The most commonly used USART1, if your board uses PA9 and PA10 as the TX and TX of USART1 by default, then there is no remapping, No Remap. In this case, there is no need to turn on the AFIO clock, just turn on the USART1 peripheral clock. This experiment is very simple, you will know it by trying it yourself


2. In STM32, CTS, RTS, TX, RX of USART2 and CH1~CH4 of TIM2 are all on PA0~PA3. How to select these two functions?


If you want to use USART2, start the USART2 peripheral clock. If you want to use TIM2, start the TIM2 peripheral clock. If you start both at the same time, I don't know what will happen. You can try it yourself. I think neither of them should work. If you must use these two functions on PA0~PA3, you can only use time division multiplexing.

The correct way to use USART2 and TIM2 at the same time is to use the AFIO_Remap register mentioned above to remap one of them to other IOs. Of course, you cannot enable the multiplexing function of other IOs.


If you don't do Remap, you can't use these two peripherals on PA0~PA3 at the same time. Now you have two solutions:

1. Keep USART2 on the PA port and fully remap TIM2 to other IOs. Or, if you do not use the hardware flow control of RTS and CTS, the corresponding CH1 and CH2 on PA0 (CTS) and PA1 (RTS) do not need to be remapped. You only need to change Bit9:8 to 10, that is, remap CH3 and CH4 to PB10 and PB11, while CH1 and CH2 continue to remain on PA0 and PA1. However, in this case, I2C2 and USART3 on PB10 and PB11 cannot be used.

2. Keep TIM2 on the PA port and remap USART2 to the PD port. Obviously, when TIM2 is not remapped at all, the only signal line required by USART2, the Clock, is not affected. In this case, there is no partial mapping. USART2 must be completely remapped to PD3~PD7. Similarly, FSMC cannot be used in this case.


Remapping configuration steps

1. Turn on the remapped clock and the USART remapped I/O port pin clock

for example:


RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);

2. I/O port remapping is enabled:


for example:


GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);

3. Configure the remapped pins. Here you only need to configure the remapped I/O, and the original ones do not need to be configured. (For pins with different functions, refer to different pin configuration methods)

for example:


Wait for the form,

Code example:

    // PA9 As TXD

    stGpioInit.GPIO_Pin = GPIO_Pin_9;

    stGpioInit.GPIO_Speed = GPIO_Speed_50MHz;

    stGpioInit.GPIO_Mode = GPIO_Mode_AF_PP; 

    GPIO_Init(GPIOA, &stGpioInit);

   

    // PA10 As RXD

    stGpioInit.GPIO_Pin = GPIO_Pin_10;

    stGpioInit.GPIO_Mode = GPIO_Mode_IN_FLOATING;

    GPIO_Init(GPIOA, &stGpioInit);


Keywords:STM32F103ZET6 Reference address:STM32F103ZET6 — Port Remap

Previous article:STM32F103ZET6 — TIM6/TIM7
Next article:STM32F103ZET6 Clock (2) - Code

Latest Microcontroller Articles
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号