From c51f27797e332cb9a73cfbde7b1370a8ca59684d Mon Sep 17 00:00:00 2001 From: HubretXie Date: Sun, 23 Dec 2018 21:04:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9GPIO=E5=85=B3=E4=B8=AD?= =?UTF-8?q?=E6=96=AD=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 因为STM32有些IO共用一个中断向量,关中断时不能直接关闭中断 --- bsp/stm32/libraries/HAL_Drivers/drv_gpio.c | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c b/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c index 0d71c06763..9ea8ce5313 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_gpio.c @@ -254,6 +254,7 @@ static struct rt_pin_irq_hdr pin_irq_hdr_tab[] = {-1, 0, RT_NULL, RT_NULL}, {-1, 0, RT_NULL, RT_NULL}, }; +static uint32_t pin_irq_enable_mask=0; #define ITEM_NUM(items) sizeof(items) / sizeof(items[0]) static const struct pin_index *get_pin(uint8_t pin) @@ -507,6 +508,7 @@ static rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin, HAL_NVIC_SetPriority(irqmap->irqno, 5, 0); HAL_NVIC_EnableIRQ(irqmap->irqno); + pin_irq_enable_mask |= irqmap->pinbit; rt_hw_interrupt_enable(level); } @@ -518,7 +520,30 @@ static rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin, return RT_ENOSYS; } - HAL_NVIC_DisableIRQ(irqmap->irqno); + level = rt_hw_interrupt_disable(); + + HAL_GPIO_DeInit(index->gpio, index->pin); + + pin_irq_enable_mask &= ~irqmap->pinbit; + if (( irqmap->pinbit>=GPIO_PIN_5 )&&( irqmap->pinbit<=GPIO_PIN_9 )) + { + if(!(pin_irq_enable_mask&(GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9))) + { + HAL_NVIC_DisableIRQ(irqmap->irqno); + } + } + else if (( irqmap->pinbit>=GPIO_PIN_10 )&&( irqmap->pinbit<=GPIO_PIN_15 )) + { + if(!(pin_irq_enable_mask&(GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15))) + { + HAL_NVIC_DisableIRQ(irqmap->irqno); + } + } + else + { + HAL_NVIC_DisableIRQ(irqmap->irqno); + } + rt_hw_interrupt_enable(level); } else {