STMicroelectronics / stm32l0xx_hal_driver

Provides the STM32Cube MCU Component "hal_driver" of the STM32L0 series.
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

Reordered EXTI reset code in HAL_GPIO_DeInit() #2

Closed jelledevleeschouwer closed 4 years ago

jelledevleeschouwer commented 4 years ago

Scenario: Firmware configures a GPIO for EXTI line interrupt on falling edge. In hardware the GPIO is pulled to Vdd by a pull-up resistor. After the falling edge is detected (single instance), the firmware reconfigures the GPIO pin for a different purpose.

Problem: EXTI line interrupt is triggered twice, while in fact only one falling edge is generated on the I/O pin.

Root cause: Improper EXTI reset order in HAL_GPIO_DeInit(). After the first time the EXTI line interrupt is fired, the firmware calls HAL_GPIO_DeInit() to de-initialize the GPIO pin because the resource is not needed anymore. Because the way the code is ordered in HAL_GPIO_DeInit(), '1'-to-'0' transition might be arise in the "Input data register" because the mode is reset to Analog High Impedance mode. This disable the internal Schmitt trigger, which continuously produces a '0' on its output. If the I/O was pulled high by pull-up resistor, a '1'-to-'0' transition triggers the EXTI line edge detector and fires the IRQ because the EXTI line configuration registers are not yet reset at this point in HAL_GPIO_DeInit().

Solution: Reorder the EXTI reset code in HAL_GPIO_DeInit() to disable the EXIT line interrupt before switching the value of EXTI line multiplexer and resetting the mode of the GPIO pin to analog high-impedance mode.

Fixes #1.

IMPORTANT INFORMATION

Contributor License Agreement (CLA)

jelledevleeschouwer commented 4 years ago

Hi @ALABSTM,

I cannot access https://cla.st.com/ at this moment to sign the CLA. The connection is reset by the server.

Best regards, Jelle

CCASTM commented 4 years ago

Hello Jelle, We have just updated our CONTRIBUTING rules (yesterday in fact!) but we omitted to mention that this service will be launched only from end of week 14. I am sorry about this confusion. Can you submit your Pull Request only after you will be able to approve the CLA as mentioned in the CONTRIBUTING.md file Thank you Christophe

jelledevleeschouwer commented 4 years ago

Hi @CCASTM, Thanks for letting me know! Can I leave the pull request open or shall I close it in the meantime?

CCASTM commented 4 years ago

Jelle, To facilitate our internal management, can you submit again a new Pull Request when you have been able to sign the CLA. Then close this one Thank you Christophe