Skip to main content
papageno
Associate III
September 17, 2021
Question

Switching alternate functions for on input pin

  • September 17, 2021
  • 5 replies
  • 2071 views

Hello experts,

I am using a stm32F446RET6 (HAL and C) and I am using the PA1 input pin for receiving a serial stream with the TIM2 Channel for frequency and logic detection. This Input capture timer works perfectly. But prior to decode the stream I first need to check if there is an active signal on that pin. So my question concerns the use of an alternate function on the PA1 pin, for example as EXTI or GPIO. Is it possible to switch from EXTI or GPIO input to the TIM2 CH2 without destroying all the settings that have been done. I read that there is a way to use the GPIOx_AFRL register.

i would be thankful to anybody who already did that. I tried several things and so far it s not working, it is not as trivial as expected obviously. The goal would be to use the PA1 pin as EXTI or GPIO input to detect if the signal is present and if positive switch the pin back to the TIM2 Channel for logic decoding.

Regards,

This topic has been closed for replies.

5 replies

waclawek.jan
Super User
September 17, 2021

You don't need to switch anything. While the pin is set for timer input capture, GPIO_IDR still reflects the input state of the pin and, if set up for that given pin, EXTI works, too.

JW

papageno
papagenoAuthor
Associate III
September 17, 2021

Thank you jan,

You mean that even if the pin was configured as TIM2_CH2 and not as GPIO_input, i can still read (GPIOA->IDR & pin) the value or trigger an exception without setting anything ? I will try that.

Regards,

pap

waclawek.jan
Super User
September 17, 2021

> You mean that even if the pin was configured as TIM2_CH2 and not as GPIO_input, i can still read (GPIOA->IDR & pin) the value

Yes.

> trigger an exception without setting anything

Well, you need to have the proper port selected in the respective SYSCFG_EXTICRx, but PAx is by default; and of course you have to have EXTI set up properly.

JW

papageno
papagenoAuthor
Associate III
September 17, 2021

thanks Jan,

i will give a try to EXTI later on, so far the port reading is satisfying.

regards,

Pap