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);
Previous article:STM32F103ZET6 — TIM6/TIM7
Next article:STM32F103ZET6 Clock (2) - Code
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- I would like to ask if there is a PDF of the fourth edition of "The Definitive Guide to Operational Amplifiers"
- I need help from you guys, I need a chip that can boost 5V to 36V, thank you
- [Flower carving DIY] Interesting and fun music visualization series of small projects (15) - horizontal LED square tube lights
- TI - Improving the design of smart speakers
- Analysis of typical problems in the development of ARM+DSP dual-core architecture
- Electromagnetic Compatibility Design and Testing (4th Edition)
- Software requirements for legally controlling microcontrollers remotely via Android phones
- How to Meet the Testing Challenges of Multi-Antenna Systems
- Award-winning live broadcast: STMicroelectronics SiC products and industrial application guide, please watch at 10:00 on September 10~
- A new user uses Quartus for the first time