Skip to content

Commit 764ce97

Browse files
mathieuchopstmaescolar
authored andcommitted
drivers: dma: stm32: add support for STM32WB0
Add support for STM32WB0 series in the relevant drivers and Kconfig. Signed-off-by: Mathieu Choplain <[email protected]>
1 parent c532702 commit 764ce97

File tree

2 files changed

+48
-40
lines changed

2 files changed

+48
-40
lines changed

drivers/dma/Kconfig.stm32

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ config DMA_STM32_SHARED_IRQS
5555
bool
5656
default y
5757
depends on SOC_SERIES_STM32C0X || SOC_SERIES_STM32F0X || \
58-
SOC_SERIES_STM32G0X || SOC_SERIES_STM32L0X
58+
SOC_SERIES_STM32G0X || SOC_SERIES_STM32L0X || \
59+
SOC_SERIES_STM32WB0X
5960
help
6061
Enable shared IRQ support on devices where channels share 1 IRQ.
6162

drivers/dma/dma_stm32.c

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ DEVICE_DT_INST_DEFINE(index, \
725725

726726
#define DMA_STM32_DEFINE_IRQ_HANDLER(dma, chan) /* nothing */
727727

728+
/** Connect and enable IRQ @p chan of DMA instance @p dma */
728729
#define DMA_STM32_IRQ_CONNECT(dma, chan) \
729730
do { \
730731
IRQ_CONNECT(DT_INST_IRQ_BY_IDX(dma, chan, irq), \
@@ -743,8 +744,12 @@ static void dma_stm32_irq_##dma##_##chan(const struct device *dev) \
743744
dma_stm32_irq_handler(dev, chan); \
744745
}
745746

746-
747-
#define DMA_STM32_IRQ_CONNECT(dma, chan) \
747+
/**
748+
* Connect and enable IRQ @p chan of DMA instance @p dma
749+
*
750+
* @note Arguments order is reversed for compatibility with LISTIFY!
751+
*/
752+
#define DMA_STM32_IRQ_CONNECT(chan, dma) \
748753
do { \
749754
IRQ_CONNECT(DT_INST_IRQ_BY_IDX(dma, chan, irq), \
750755
DT_INST_IRQ_BY_IDX(dma, chan, priority), \
@@ -779,27 +784,37 @@ static void dma_stm32_config_irq_0(const struct device *dev)
779784
{
780785
ARG_UNUSED(dev);
781786

787+
#if !defined(CONFIG_DMA_STM32_SHARED_IRQS)
788+
/* No shared IRQs: call IRQ_CONNECT for each IRQn in DTS */
789+
LISTIFY(
790+
DT_INST_NUM_IRQS(0),
791+
DMA_STM32_IRQ_CONNECT,
792+
(;), /* instance: */ 0
793+
);
794+
#else
795+
/* All DMAs have at least one IRQ line */
782796
DMA_STM32_IRQ_CONNECT(0, 0);
797+
798+
/* On STM32WB0 series, there is a single IRQ line for all channels */
799+
#if !defined(CONFIG_SOC_SERIES_STM32WB0X)
800+
/* On other series, the sharing follows a pattern:
801+
* IRQn (X+0) is not shared (assigned to DMA1 channel 1)
802+
* IRQn (X+1) is shared by DMA1 channels 2 and 3
803+
* IRQn (X+2) is shared by DMA1 channels >= 4
804+
*
805+
* If present, DMA2 channels may also share IRQn (X+1) and (X+2);
806+
* this works fine because shared ISR checks all channels of all DMAs.
807+
*/
808+
809+
/* Connect IRQ line shared by CH2 and CH3 */
783810
DMA_STM32_IRQ_CONNECT(0, 1);
784-
#ifndef CONFIG_DMA_STM32_SHARED_IRQS
785-
DMA_STM32_IRQ_CONNECT(0, 2);
786-
#endif /* CONFIG_DMA_STM32_SHARED_IRQS */
811+
812+
/* If DMA has more than 3 channels, connect IRQ line shared by CH4+ */
787813
#if DT_INST_IRQ_HAS_IDX(0, 3)
788814
DMA_STM32_IRQ_CONNECT(0, 3);
789-
#ifndef CONFIG_DMA_STM32_SHARED_IRQS
790-
DMA_STM32_IRQ_CONNECT(0, 4);
791-
#if DT_INST_IRQ_HAS_IDX(0, 5)
792-
DMA_STM32_IRQ_CONNECT(0, 5);
793-
#if DT_INST_IRQ_HAS_IDX(0, 6)
794-
DMA_STM32_IRQ_CONNECT(0, 6);
795-
#if DT_INST_IRQ_HAS_IDX(0, 7)
796-
DMA_STM32_IRQ_CONNECT(0, 7);
797815
#endif /* DT_INST_IRQ_HAS_IDX(0, 3) */
798-
#endif /* DT_INST_IRQ_HAS_IDX(0, 5) */
799-
#endif /* DT_INST_IRQ_HAS_IDX(0, 6) */
800-
#endif /* DT_INST_IRQ_HAS_IDX(0, 7) */
801-
#endif /* CONFIG_DMA_STM32_SHARED_IRQS */
802-
/* Either 3 or 5 or 6 or 7 or 8 channels for DMA across all stm32 series. */
816+
#endif /* !CONFIG_SOC_SERIES_STM32WB0X */
817+
#endif /* !CONFIG_DMA_STM32_SHARED_IRQS */
803818
}
804819

805820
DMA_STM32_INIT_DEV(0);
@@ -831,27 +846,19 @@ static void dma_stm32_config_irq_1(const struct device *dev)
831846
ARG_UNUSED(dev);
832847

833848
#ifndef CONFIG_DMA_STM32_SHARED_IRQS
834-
DMA_STM32_IRQ_CONNECT(1, 0);
835-
DMA_STM32_IRQ_CONNECT(1, 1);
836-
DMA_STM32_IRQ_CONNECT(1, 2);
837-
DMA_STM32_IRQ_CONNECT(1, 3);
838-
#if DT_INST_IRQ_HAS_IDX(1, 4)
839-
DMA_STM32_IRQ_CONNECT(1, 4);
840-
#if DT_INST_IRQ_HAS_IDX(1, 5)
841-
DMA_STM32_IRQ_CONNECT(1, 5);
842-
#if DT_INST_IRQ_HAS_IDX(1, 6)
843-
DMA_STM32_IRQ_CONNECT(1, 6);
844-
#if DT_INST_IRQ_HAS_IDX(1, 7)
845-
DMA_STM32_IRQ_CONNECT(1, 7);
846-
#endif /* DT_INST_IRQ_HAS_IDX(1, 4) */
847-
#endif /* DT_INST_IRQ_HAS_IDX(1, 5) */
848-
#endif /* DT_INST_IRQ_HAS_IDX(1, 6) */
849-
#endif /* DT_INST_IRQ_HAS_IDX(1, 7) */
850-
#endif /* CONFIG_DMA_STM32_SHARED_IRQS */
851-
/*
852-
* Either 5 or 6 or 7 or 8 channels for DMA across all stm32 series.
853-
* STM32F0 and STM32G0: if dma2 exits, the channel interrupts overlap with dma1
854-
*/
849+
/* No shared IRQs: call IRQ_CONNECT for each IRQn in DTS */
850+
LISTIFY(
851+
DT_INST_NUM_IRQS(1),
852+
DMA_STM32_IRQ_CONNECT,
853+
(;), /* instance: */ 1
854+
);
855+
#else
856+
/**
857+
* Series with 2 DMAs and SHARED_IRQS are STM32F0 and STM32G0.
858+
* On both of these series, the DMA2 interrupt lines are shared with DMA1,
859+
* so they have already been IRQ_CONNECT()'ed and there's nothing to do here.
860+
*/
861+
#endif /* !CONFIG_DMA_STM32_SHARED_IRQS */
855862
}
856863

857864
DMA_STM32_INIT_DEV(1);

0 commit comments

Comments
 (0)