diff --git a/drivers/interrupt_controller/exti_stm32.c b/drivers/interrupt_controller/exti_stm32.c index a815dfddfbf..ff72c804f7f 100644 --- a/drivers/interrupt_controller/exti_stm32.c +++ b/drivers/interrupt_controller/exti_stm32.c @@ -45,22 +45,6 @@ #define EXTI_LINES 40 #endif -/* 10.3.7 EXTI register map */ -struct stm32_exti { - /* EXTI_IMR */ - u32_t imr; - /* EXTI_EMR */ - u32_t emr; - /* EXTI_RTSR */ - u32_t rtsr; - /* EXTI_FTSR */ - u32_t ftsr; - /* EXTI_SWIER */ - u32_t swier; - /* EXTI_PR */ - u32_t pr; -}; - /* wrapper for user callback */ struct __exti_cb { stm32_exti_callback_t cb; @@ -73,30 +57,19 @@ struct stm32_exti_data { struct __exti_cb cb[EXTI_LINES]; }; -/* - * return the proper base addr based on the line number, also we adjust - * the line number to be relative to the base, we do this here to save - * a bit of code size - */ -static inline struct stm32_exti *get_exti_addr_adjust_line(int *line) -{ - struct stm32_exti *base = (struct stm32_exti *)EXTI_BASE; - -#if EXTI_LINES > 32 - if (*line > 31) { - *line -= 32; - return base + 1; - } -#endif - return base; -} - int stm32_exti_enable(int line) { - volatile struct stm32_exti *exti = get_exti_addr_adjust_line(&line); int irqnum = 0; - exti->imr |= 1 << line; + if (line < 32) { + LL_EXTI_EnableIT_0_31(1 << line); + } else { +#if EXTI_LINES > 32 + LL_EXTI_EnableIT_32_63(1 << (line - 32)); +#else + __ASSERT_NO_MSG(line); +#endif + } #if defined(CONFIG_SOC_SERIES_STM32F0X) || \ defined(CONFIG_SOC_SERIES_STM32L0X) @@ -182,9 +155,15 @@ int stm32_exti_enable(int line) void stm32_exti_disable(int line) { - volatile struct stm32_exti *exti = get_exti_addr_adjust_line(&line); - - exti->imr &= ~(1 << line); + if (line < 32) { + LL_EXTI_DisableIT_0_31(1 << line); + } else { +#if EXTI_LINES > 32 + LL_EXTI_DisableIT_32_63(1 << (line - 32)); +#else + __ASSERT_NO_MSG(line); +#endif + } } /** @@ -194,9 +173,16 @@ void stm32_exti_disable(int line) */ static inline int stm32_exti_is_pending(int line) { - volatile struct stm32_exti *exti = get_exti_addr_adjust_line(&line); - - return (exti->pr & (1 << line)) ? 1 : 0; + if (line < 32) { + return LL_EXTI_IsActiveFlag_0_31(1 << line); + } else { +#if EXTI_LINES > 32 + return LL_EXTI_IsActiveFlag_32_63(1 << (line - 32)); +#else + __ASSERT_NO_MSG(line); + return 0; +#endif + } } /** @@ -206,21 +192,41 @@ static inline int stm32_exti_is_pending(int line) */ static inline void stm32_exti_clear_pending(int line) { - volatile struct stm32_exti *exti = get_exti_addr_adjust_line(&line); - - exti->pr = 1 << line; + if (line < 32) { + LL_EXTI_ClearFlag_0_31(1 << line); + } else { +#if EXTI_LINES > 32 + LL_EXTI_ClearFlag_32_63(1 << (line - 32)); +#else + __ASSERT_NO_MSG(line); +#endif + } } void stm32_exti_trigger(int line, int trigger) { - volatile struct stm32_exti *exti = get_exti_addr_adjust_line(&line); - if (trigger & STM32_EXTI_TRIG_RISING) { - exti->rtsr |= 1 << line; + if (line < 32) { + LL_EXTI_EnableRisingTrig_0_31(1 << line); + } else { +#if EXTI_LINES > 32 + LL_EXTI_EnableRisingTrig_32_63(1 << (line - 32)); +#else + __ASSERT_NO_MSG(line); +#endif + } } if (trigger & STM32_EXTI_TRIG_FALLING) { - exti->ftsr |= 1 << line; + if (line < 32) { + LL_EXTI_EnableFallingTrig_0_31(1 << line); + } else { +#if EXTI_LINES > 32 + LL_EXTI_EnableFallingTrig_32_63(1 << (line - 32)); +#else + __ASSERT_NO_MSG(line); +#endif + } } } diff --git a/soc/arm/st_stm32/stm32f0/soc.h b/soc/arm/st_stm32/stm32f0/soc.h index 416171ae816..c57965f789c 100644 --- a/soc/arm/st_stm32/stm32f0/soc.h +++ b/soc/arm/st_stm32/stm32f0/soc.h @@ -28,6 +28,10 @@ */ #include +#ifdef CONFIG_EXTI_STM32 +#include +#endif + #ifdef CONFIG_SERIAL_HAS_DRIVER #include #endif diff --git a/soc/arm/st_stm32/stm32f1/soc.h b/soc/arm/st_stm32/stm32f1/soc.h index 88dabd93f4e..b12f359b507 100644 --- a/soc/arm/st_stm32/stm32f1/soc.h +++ b/soc/arm/st_stm32/stm32f1/soc.h @@ -28,6 +28,10 @@ */ #include +#ifdef CONFIG_EXTI_STM32 +#include +#endif + #ifdef CONFIG_SERIAL_HAS_DRIVER #include #endif diff --git a/soc/arm/st_stm32/stm32f2/soc.h b/soc/arm/st_stm32/stm32f2/soc.h index 1586485061c..9e15a70f2cf 100644 --- a/soc/arm/st_stm32/stm32f2/soc.h +++ b/soc/arm/st_stm32/stm32f2/soc.h @@ -27,6 +27,10 @@ */ #include +#ifdef CONFIG_EXTI_STM32 +#include +#endif + #ifdef CONFIG_CLOCK_CONTROL_STM32_CUBE #include #include diff --git a/soc/arm/st_stm32/stm32f3/soc.h b/soc/arm/st_stm32/stm32f3/soc.h index 673ed3bb3f5..31f58ff213a 100644 --- a/soc/arm/st_stm32/stm32f3/soc.h +++ b/soc/arm/st_stm32/stm32f3/soc.h @@ -29,6 +29,10 @@ */ #include +#ifdef CONFIG_EXTI_STM32 +#include +#endif + #ifdef CONFIG_SERIAL_HAS_DRIVER #include #endif diff --git a/soc/arm/st_stm32/stm32f4/soc.h b/soc/arm/st_stm32/stm32f4/soc.h index 5cd3436bff4..432b84ea059 100644 --- a/soc/arm/st_stm32/stm32f4/soc.h +++ b/soc/arm/st_stm32/stm32f4/soc.h @@ -28,6 +28,10 @@ */ #include +#ifdef CONFIG_EXTI_STM32 +#include +#endif + #ifdef CONFIG_CLOCK_CONTROL_STM32_CUBE #include #include diff --git a/soc/arm/st_stm32/stm32f7/soc.h b/soc/arm/st_stm32/stm32f7/soc.h index 5279bf3ab71..238711a30dc 100644 --- a/soc/arm/st_stm32/stm32f7/soc.h +++ b/soc/arm/st_stm32/stm32f7/soc.h @@ -27,6 +27,10 @@ */ #include +#ifdef CONFIG_EXTI_STM32 +#include +#endif + #ifdef CONFIG_CLOCK_CONTROL_STM32_CUBE #include #include diff --git a/soc/arm/st_stm32/stm32l0/soc.h b/soc/arm/st_stm32/stm32l0/soc.h index 43d2e892e5b..3e5387a1c51 100644 --- a/soc/arm/st_stm32/stm32l0/soc.h +++ b/soc/arm/st_stm32/stm32l0/soc.h @@ -29,6 +29,10 @@ #include +#ifdef CONFIG_EXTI_STM32 +#include +#endif + #ifdef CONFIG_SERIAL_HAS_DRIVER #include #include diff --git a/soc/arm/st_stm32/stm32l4/soc.h b/soc/arm/st_stm32/stm32l4/soc.h index f4fa0797d73..940a54b271a 100644 --- a/soc/arm/st_stm32/stm32l4/soc.h +++ b/soc/arm/st_stm32/stm32l4/soc.h @@ -30,6 +30,10 @@ */ #include +#ifdef CONFIG_EXTI_STM32 +#include +#endif + #ifdef CONFIG_GPIO_STM32 /* Required to enable VDDio2 for port G */ #include