From 4fb8be61afa91e22204d1a266d006d324db13bbe Mon Sep 17 00:00:00 2001 From: Tristan Seifert Date: Fri, 13 Dec 2024 16:05:07 -0800 Subject: [PATCH] Fix shared ADC IRQs for STM32H7xx (#11) - ADC1/2 share an interrupt vectoron STM32H7xx; this wasn't properly implemented before. --- drivers/adc/Kconfig.stm32 | 2 +- drivers/adc/adc_stm32.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/adc/Kconfig.stm32 b/drivers/adc/Kconfig.stm32 index cb763cdf7fc1c3..724a702718fbb4 100644 --- a/drivers/adc/Kconfig.stm32 +++ b/drivers/adc/Kconfig.stm32 @@ -12,7 +12,7 @@ config ADC_STM32 help Enable the driver implementation for the stm32xx ADC -if SOC_SERIES_STM32F2X || SOC_SERIES_STM32F4X || SOC_SERIES_STM32F7X +if SOC_SERIES_STM32F2X || SOC_SERIES_STM32F4X || SOC_SERIES_STM32F7X || SOC_SERIES_STM32H7X config ADC_STM32_SHARED_IRQS bool "STM32 ADC shared interrupts" diff --git a/drivers/adc/adc_stm32.c b/drivers/adc/adc_stm32.c index d8b080a1feeae6..c7cf71137985dc 100644 --- a/drivers/adc/adc_stm32.c +++ b/drivers/adc/adc_stm32.c @@ -1162,10 +1162,17 @@ static const struct adc_driver_api api_stm32_driver_api = { bool adc_stm32_is_irq_active(ADC_TypeDef *adc) { +#ifdef LL_ADC_IsActiveFlag_EOCS return LL_ADC_IsActiveFlag_EOCS(adc) || LL_ADC_IsActiveFlag_OVR(adc) || LL_ADC_IsActiveFlag_JEOS(adc) || LL_ADC_IsActiveFlag_AWD1(adc); +#else + return LL_ADC_IsActiveFlag_EOC(adc) || + LL_ADC_IsActiveFlag_OVR(adc) || + LL_ADC_IsActiveFlag_JEOS(adc) || + LL_ADC_IsActiveFlag_AWD1(adc); +#endif } #define HANDLE_IRQS(index) \ @@ -1186,10 +1193,24 @@ static void adc_stm32_irq_init(void) { if (init_irq) { init_irq = false; + + // STM32H7: ADC1/2 share IRQ vector, ADC3 has its own vector +#ifdef CONFIG_SOC_SERIES_STM32H7X + IRQ_CONNECT(DT_IRQN(DT_NODELABEL(adc1)), + DT_IRQ(DT_NODELABEL(adc1), priority), + adc_stm32_shared_irq_handler, NULL, 0); + irq_enable(DT_IRQN(DT_NODELABEL(adc1))); + + IRQ_CONNECT(DT_IRQN(DT_NODELABEL(adc3)), + DT_IRQ(DT_NODELABEL(adc3), priority), + adc_stm32_shared_irq_handler, NULL, 0); + irq_enable(DT_IRQN(DT_NODELABEL(adc3))); +#else IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority), adc_stm32_shared_irq_handler, NULL, 0); irq_enable(DT_INST_IRQN(0)); +#endif } }