From 5010c175396df934f8b71dca38da016b83420d92 Mon Sep 17 00:00:00 2001 From: Diamond Rivero Date: Sat, 12 Oct 2024 15:35:09 +0800 Subject: [PATCH] move `GPIO_InitStruct` variable inside to `PIN_IRQ_ENABLE`. thanks to @mysterywolf --- bsp/stm32/libraries/HAL_Drivers/drivers/drv_gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drivers/drv_gpio.c b/bsp/stm32/libraries/HAL_Drivers/drivers/drv_gpio.c index 20b9e40591..c3f398539e 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drivers/drv_gpio.c +++ b/bsp/stm32/libraries/HAL_Drivers/drivers/drv_gpio.c @@ -394,8 +394,6 @@ static rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin, const struct pin_irq_map *irqmap; rt_base_t level; rt_int32_t irqindex = -1; - GPIO_InitTypeDef GPIO_InitStruct; - HAL_GPIO_Init(PIN_STPORT(pin), &GPIO_InitStruct); if (PIN_PORT(pin) >= PIN_STPORT_MAX) { @@ -419,6 +417,7 @@ static rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin, } irqmap = &pin_irq_map[irqindex]; + GPIO_InitTypeDef GPIO_InitStruct; /* Configure GPIO_InitStructure */ GPIO_InitStruct.Pin = PIN_STPIN(pin); @@ -438,6 +437,7 @@ static rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin, GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; break; } + HAL_GPIO_Init(PIN_STPORT(pin), &GPIO_InitStruct); HAL_NVIC_SetPriority(irqmap->irqno, 5, 0); HAL_NVIC_EnableIRQ(irqmap->irqno);