cancel
Showing results for 
Search instead for 
Did you mean: 

Changing GPIO mode at runtime

BP1
Associate II

I'm trying to change GPIO mode at runtime, i could able to change mode from input to output and vice versa. But once configuring GPIO as EXTI i'm not able to change it to any other mode. and even if i try to change, ISR is getting executed.

5 REPLIES 5
Pavel A.
Evangelist III

Don't wan to receive the interrupt temporarily? Disable it in NVIC.

-- pa

S.Ma
Principal

To avoid any glitch, better write directly in the GPIO HW registers.

You can also use sometime when relevant output open drain with high level which would be equivalent to turn as input, maybe without glitches. EXTI on alternate function is not natively supported by HAL nor CubeMX: Write directly in the registers to enable EXTI on alternate function if this is the next development step from where you are. Changing alternate function of a GPIO dynamically also works when done properly. (what happen if you activate 2 UART1 RX GPIOs?)

In case you do still have EXTI glitch, disable EXTI interrupt, change the GPIO mode, clear the EXTI PR flag and reactivate EXTI.

i tried disabling nvic and also DeInit the GPIO and Init it again as output, but didn't work.

BP1
Associate II

I'm using HAL so i dont know how to access registers..

can u please tell me how to access EXTI registers, i'm using SW4STM32

Thank you

S.Ma
Principal

As long as the GPIO is not an alternate function, you can use HAL or LL EXTI functions.

search for something like stm32l4xx_ll_exti.c