cancel
Showing results for 
Search instead for 
Did you mean: 

Same pin as timer input and GPIO input

AJame.1
Associate II

If I configure a pin as a timer input capture channel input, can I also read the state of that pin as a GPIO input?

I'd like configure the timer channel as an input capture channel, and I'd like to capture both rising and falling edges. But when the edge is detected, how can I determine whether it was the rising or falling edge? Can I also enable the GPIO input stage for that pin and read its state after the edge is detected? I don't see any way to do this in STM32CubeMX. Is there some other way to determine whether the timer detected a rising or falling edge?

3 REPLIES 3
TDK
Guru

> If I configure a pin as a timer input capture channel input, can I also read the state of that pin as a GPIO input?

Yes, GPIO_IDR works even in AF mode. At least on the STM32F4, probably also works on your unspecified chip. Use HAL_GPIO_ReadPin.

If you feel a post has answered your question, please click "Accept as Solution".
AJame.1
Associate II

Thanks! I got it working on my NUCLEO board.

The only piece I was missing was that I have to call HAL_GPIO_ReadPin() using the generic port and pin definitions in the HAL GPIO header file [e.g. HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)] since STMCubeMX doesn't use the user label I applied to that pin in the GUI to create #defines for that port and pin in the main.h that it generates.

AJame.1
Associate II

P.S. I just figured out I can enable "Pin Stacking" for that pin in STMCubeMX to select both TIMx_CHy and GPIO_Input for that pin.

FYI, after enabling "Pin Stacking" for that pin and clicking on GPIO_Input in the pop-up list of pin functions, it wipes out my user label, the settings for my timer channel, turns TIMx_CHy Yellow in the pop-up list of pin functions, and turns GPIO_Input green. Once I click back on TIMx_CHy in the pop-up list, it then turns it green again and turns GPIO_Input yellow. I also have to re-enter my user label and timer settings. But once I do all that, it does create #defines for that port and pin in main.h.