Skip to content

Commit c2f31b2

Browse files
committed
drivers/can: add shared_irq support to can_stm32fd driver
This commit adds shared_irq support to can_stm32fd driver, such that two can instances can be used on stm32g0. Additinally to the necessary code changes, bindings are added to st,stm32-fdacn.yaml, and the SHARED_IRQ is automatically enabled in KConfig if the can devices define a shared-irqs phandle-array. Signed-off-by: Thomas Stranger <[email protected]>
1 parent 566df20 commit c2f31b2

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

drivers/can/can_stm32fd.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stm32_ll_rcc.h>
1111
#include "can_stm32fd.h"
1212
#include <pinmux/pinmux_stm32.h>
13+
#include <shared_irq.h>
1314

1415
#include <logging/log.h>
1516
LOG_MODULE_DECLARE(can_driver, CONFIG_CAN_LOG_LEVEL);
@@ -208,18 +209,22 @@ static const struct can_driver_api can_api_funcs = {
208209
#endif
209210
};
210211

212+
/*
213+
* If a shared-irq with matching name exists and has status okay use the
214+
* shared-irq driver, otherwise, connect to normal IRQ.
215+
*/
211216
#define CAN_STM32FD_IRQ_CFG_FUNCTION(inst) \
212217
static void config_can_##inst##_irq(void) \
213218
{ \
214219
LOG_DBG("Enable CAN" #inst " IRQ"); \
215-
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(inst, line_0, irq), \
216-
DT_INST_IRQ_BY_NAME(inst, line_0, priority), \
217-
can_stm32fd_line_0_isr, DEVICE_DT_INST_GET(inst), 0); \
218-
irq_enable(DT_INST_IRQ_BY_NAME(inst, line_0, irq)); \
219-
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(inst, line_1, irq), \
220-
DT_INST_IRQ_BY_NAME(inst, line_1, priority), \
221-
can_stm32fd_line_1_isr, DEVICE_DT_INST_GET(inst), 0); \
222-
irq_enable(DT_INST_IRQ_BY_NAME(inst, line_1, irq)); \
220+
SHARED_IRQ_CONNECT_IRQ_BY_NAME_COND(DT_DRV_INST(inst), line_0, \
221+
can_stm32fd_line_0_isr, \
222+
DEVICE_DT_INST_GET(inst), 0); \
223+
SHARED_IRQ_CONNECT_IRQ_BY_NAME_COND(DT_DRV_INST(inst), line_1, \
224+
can_stm32fd_line_1_isr, \
225+
DEVICE_DT_INST_GET(inst), 0); \
226+
SHARED_IRQ_ENABLE_BY_NAME_COND(DT_DRV_INST(inst), line_0); \
227+
SHARED_IRQ_ENABLE_BY_NAME_COND(DT_DRV_INST(inst), line_1); \
223228
}
224229

225230
#ifdef CONFIG_CAN_FD_MODE

dts/bindings/can/st,stm32-fdcan.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,22 @@ properties:
1414
1515
For example the can1 would be
1616
pinctrl-0 = <&fdcan1_rx_pa11 &fdcan1_tx_pa12>;
17+
18+
shared-irq-names:
19+
type: string-array
20+
required: false
21+
description: |
22+
Name of each shared-irq in shared-irqs.
23+
Required if shared-irqs are used and interrupts are chosen by name.
24+
25+
shared-irqs:
26+
type: phandle-array
27+
required: false
28+
description: |
29+
To avoid interrupt conflicts shared-irq nodes can be referenced.
30+
In case the referenced shared_irq phandles have status okay the driver
31+
registers the isr with the shared_irq instance instead of connecting to
32+
the irq.
33+
34+
Example for stm32g0 would be
35+
shared-irqs = <&shared_irq21 &shared_irq22>;

0 commit comments

Comments
 (0)