Commit 28811862 authored by Mathieu Choplain's avatar Mathieu Choplain Committed by Fabio Baltieri
Browse files

drivers: counter: stm32_timer: use "cc" interrupt if it exists



Currently, the STM32 TIM counter driver will always register itself as ISR
for interrupts[0] of the timer node. This works fine for timers which have
a single "global" interrupt but not for others (e.g., Advanced Timer) which
have separate IRQ lines for various events.

Borrow the pattern from PWM driver: use the "cc" interrupt if it exists on
timer node, otherwise use the "global" interrupt. If neither of those are
found, a build error is raised to ensure silent failures cannot occur.

Signed-off-by: default avatarMathieu Choplain <mathieu.choplain@st.com>
parent ee894501
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -641,6 +641,14 @@ void counter_stm32_irq_handler(const struct device *dev)
/** TIMx instance from DT */
#define TIM(idx) ((TIM_TypeDef *)DT_REG_ADDR(TIMER(idx)))

#define IRQ_CONNECT_AND_ENABLE_BY_NAME(index, name)				\
{										\
	IRQ_CONNECT(DT_IRQ_BY_NAME(TIMER(index), name, irq),			\
		    DT_IRQ_BY_NAME(TIMER(index), name, priority),		\
		    counter_stm32_irq_handler, DEVICE_DT_INST_GET(index), 0);	\
	irq_enable(DT_IRQ_BY_NAME(TIMER(index), name, irq));			\
}

#define COUNTER_DEVICE_INIT(idx)						  \
	BUILD_ASSERT(DT_PROP(TIMER(idx), st_prescaler) <= 0xFFFF,		  \
		     "TIMER prescaler out of range");				  \
@@ -652,12 +660,11 @@ void counter_stm32_irq_handler(const struct device *dev)
										  \
	static void counter_##idx##_stm32_irq_config(const struct device *dev)	  \
	{									  \
		IRQ_CONNECT(DT_IRQN(TIMER(idx)),				  \
			    DT_IRQ(TIMER(idx), priority),			  \
			    counter_stm32_irq_handler,				  \
			    DEVICE_DT_INST_GET(idx),				  \
			    0);							  \
		irq_enable(DT_IRQN(TIMER(idx)));				  \
		COND_CODE_1(DT_IRQ_HAS_NAME(TIMER(idx), cc),			  \
			(IRQ_CONNECT_AND_ENABLE_BY_NAME(idx, cc)),		  \
		(COND_CODE_1(DT_IRQ_HAS_NAME(TIMER(idx), global),		  \
			(IRQ_CONNECT_AND_ENABLE_BY_NAME(idx, global)),		  \
		(BUILD_ASSERT(0, "Timer has no 'cc' or 'global' interrupt!")))))  \
	}									  \
										  \
	static const struct counter_stm32_config counter##idx##_config = {	  \