(ix) The Afio of STM32

Source: Internet
Author: User

Perhaps you think Io and Afio is very simple, in fact there are a few misunderstandings may be many people have not noticed, when you only use the off-the-shelf Development Board to learn, others have helped you to do a good job of resource allocation, all the peripheral function learning is according to other people to do the routine to you, which did not make you feel strange.

Ask yourself a question: STM32, USART2 and TIM2 are shared with the same IO, how do you decide whether these Io are USART2 or do TIM2? What if you want to use both USART2 and TIM2?

1, not to say that the use of the re-use of the IO function must be started Rcc_apb2periph_afio clock , reference

only the Afio event control register, Afio remapping function, and external interrupt (EXTI) control registers are required to turn on the Afio clock , and the STM32 reference manual never said that the use of the IO multiplexing function would have to turn on the Afio clock, which is a myth.

For example, the following, the most commonly used USART1, if your board, the default is PA9 and PA10 the two IO as USART1 TX and Rx, then that 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. The experiment is very simple, you can see it by yourself.

2, from the above diagram you can see, the original USART1 can be placed on the PB6 and PB7 above, but almost all of the schematic package will not be in the PB6 and PB7 re-use function to mark it can be used as USART1, after all, this remapping is too much, almost all peripherals can be remapped, Each is marked out as confusing.

STM32, USART2 CTS, RTS, TX, RX and TIM2 Ch1~ch4 are all on the pa0~pa3 above, specifically how to choose these two functions?

If you want to use USART2, turn on the USART2 peripheral clock, if you want to use TIM2, turn on the TIM2 peripheral clock, if you open at the same time, I do not know what will happen, you can try it yourself, I think it should be two. If you must use these two functions on the PA0~PA3, it is only time-division multiplexing.

The correct use of both USART2 and TIM2 should be to use the Afio_remap registers mentioned above to map one of them to the other Io, of course, so that other IO's own reuse function you can not open.

Back to the previous question, if you don't do remap, you won't be able to simultaneously use both peripherals on PA0~PA3, and now you have two options:

One, retain the USART2 on the PA port, will TIM2 completely remap (full Remap) to other Io, or, if you do not have the RTS and CTS hardware flow control, PA0 (CTS) and PA1 (RTS) on the corresponding CH1 and CH2 can not be remap, You only need to change the bit9:8 to 10, that is, the CH3 and CH4 parts are mapped to PB10 and PB11, while CH1 and CH2 remain on PA0 and PA1. But in this case, PB10 and PB11 on the I2C2 and USART3 can not be used.

Second, the retention of TIM2 in the PA port, the USART2 remapping to the PD port, it is clear that when the TIM2 completely does not remap, the USART2 must be the signal line only clock is not affected, in this case there is no part of the mapping can be said, the USART2 must be completely remapped to the Pd3~pd7, Similarly, FSMC cannot be used in this case.

(ix) The Afio of STM32

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.