Skip to main content
Graduate II
March 4, 2025
Solved

GPIO & EXTI: switching between input & output

  • March 4, 2025
  • 4 replies
  • 1368 views

Heyho,

I'm currently using a GPIO on a STM32L031 for a custom 1-wire interface, which means it's switching all the time between input and output mode (open drain).

So far I have learned that the EXTI interrupt only works with GPIOs in input mode.

My question:

Once I have enabled the EXTI for a certain GPIO in input mode, then change the GPIO mode to output, then back to input, do I have to re-enable the EXTI somehow, or is it still working as before?

Thanks in advance!

    This topic has been closed for replies.
    Best answer by waclawek.jan

    > in non-input mode the GPIO simply doesn't trigger the EXTI

    No. "EXTI is independent from GPIO" means, that no matter how the pin is set in GPIO (except for Analog, when the digital input is disconnected entirely), EXTI works out of the edges it sees at given pin.

    In other words, if you set a pin to trigger EXTI, and you set that pin as Output in GPIO, then if you by that output generate an edge for which EXTI is set up, that edge *will* trigger EXTI.

    JW

    4 replies

    LCEAuthor
    Graduate II
    March 4, 2025

    I think I found the answer here, in Jan's reply (thanks!):
    How to change GPIO pin mode efficiently - STMicroelectronics Community

    EXTI and GPIO are completely independent, so in non-input mode the GPIO simply doesn't trigger the EXTI.

    Then I have to look elsewhere for my precious bugs... ;)

    Super User
    March 4, 2025

    > in non-input mode the GPIO simply doesn't trigger the EXTI

    No. "EXTI is independent from GPIO" means, that no matter how the pin is set in GPIO (except for Analog, when the digital input is disconnected entirely), EXTI works out of the edges it sees at given pin.

    In other words, if you set a pin to trigger EXTI, and you set that pin as Output in GPIO, then if you by that output generate an edge for which EXTI is set up, that edge *will* trigger EXTI.

    JW

    LCEAuthor
    Graduate II
    March 4, 2025

    somehow the browser didn't refresh...

    anyway, thanks for the clarification!

    LCEAuthor
    Graduate II
    March 4, 2025

    So far, not so good:

    after a lot of testing I'm pretty sure that:

    either the EXTI is triggered with the GPIO not only in input mode,

    or there's kinda race condition, meaning that output is switched to output before EXTI knows GPIO is not in input mode anymore.

    1) GPIO is in input mode + pull-up -> line is high (verified on the scope)

    2) then GPIO is switched to low output / open drain, pulling the line low (verified on the scope)

    3) EXTI is triggered: falling edge

    That a known issue?

    LCEAuthor
    Graduate II
    March 4, 2025

    Then ST should change this in the Ref Manual (RM0377 for L0x1):

    LCE_0-1741107550125.png

    It's at least ambiguous.