STM32 AFIO

Publisher:VS821001Latest update time:2016-10-05 Source: eefocusKeywords:STM32  AFIO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Maybe you think IO and AFIO are very simple. In fact, there are several misunderstandings that many people may not have noticed. When you only use a ready-made development board to learn, others have already helped you allocate resources, and all peripheral function learning is done according to the routines given to you by others, so you don’t feel strange.

First ask yourself a question: In STM32, USART2 and TIM2 share the same IO, how do you decide whether these IOs are used for USART2 or TIM2? What if you want to use USART2 and TIM2 at the same time?

1. It does not mean that you must start the RCC_APB2Periph_AFIO Clock when using the IO multiplexing function. Refer to the figure below

The AFIO clock needs to be turned on only when the AFIO event control register, AFIO remapping function and external interrupt (EXTI) control register are used. The STM32 reference manual never says that the AFIO clock must be turned on when using the IO multiplexing function. This is a misunderstanding.

For example, the most commonly used USART1 is shown below. If your board uses PA9 and PA10 as TX and TX of USART1 by default, then there is no remapping. In this case, you don't need to turn on the AFIO clock at all. You only need to turn on the USART1 peripheral clock. This experiment is very simple. You will know it by trying it yourself.

2. From the above figure, you can see that USART1 can be placed on PB6 and PB7, but almost all schematic packages will not mark the multiplexing function of PB6 and PB7 as USART1. After all, there are too many cases of remapping, and almost all peripherals can be remapped. It would be very confusing to mark each one.

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.

Back to the previous question, 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.

Keywords:STM32  AFIO Reference address:STM32 AFIO

Previous article:STM32 printf issue
Next article:STM32F103RBT6 program download settings

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号