From abc97c2a1ebdbeb3f43324e6e01248d240e9996d Mon Sep 17 00:00:00 2001
From: Alexandre Abadie <alexandre.abadie@inria.fr>
Date: Mon, 7 Jan 2019 15:16:07 +0100
Subject: [PATCH] boards/nucleo-l152re: configure and use DMA

---
 boards/nucleo-l152re/Makefile.dep          |  2 +
 boards/nucleo-l152re/Makefile.features     |  1 +
 boards/nucleo-l152re/include/periph_conf.h | 47 ++++++++++++++++++++--
 3 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/boards/nucleo-l152re/Makefile.dep b/boards/nucleo-l152re/Makefile.dep
index 7294858272..a7e11adb3c 100644
--- a/boards/nucleo-l152re/Makefile.dep
+++ b/boards/nucleo-l152re/Makefile.dep
@@ -1 +1,3 @@
+FEATURES_REQUIRED += periph_dma
+
 include $(RIOTBOARD)/common/nucleo/Makefile.dep
diff --git a/boards/nucleo-l152re/Makefile.features b/boards/nucleo-l152re/Makefile.features
index 8a47023499..4b2f75949d 100644
--- a/boards/nucleo-l152re/Makefile.features
+++ b/boards/nucleo-l152re/Makefile.features
@@ -1,6 +1,7 @@
 # Put defined MCU peripherals here (in alphabetical order)
 FEATURES_PROVIDED += periph_adc
 FEATURES_PROVIDED += periph_dac
+FEATURES_PROVIDED += periph_dma
 FEATURES_PROVIDED += periph_i2c
 FEATURES_PROVIDED += periph_pwm
 FEATURES_PROVIDED += periph_rtc
diff --git a/boards/nucleo-l152re/include/periph_conf.h b/boards/nucleo-l152re/include/periph_conf.h
index 307ac2d59a..68729981fb 100644
--- a/boards/nucleo-l152re/include/periph_conf.h
+++ b/boards/nucleo-l152re/include/periph_conf.h
@@ -62,6 +62,27 @@ extern "C" {
 #define CLOCK_APB1          (CLOCK_CORECLOCK / 1)
 /** @} */
 
+/**
+ * @name    DMA streams configuration
+ * @{
+ */
+#ifdef MODULE_PERIPH_DMA
+static const dma_conf_t dma_config[] = {
+    { .stream = 1 },    /* DMA1 Channel 2 - SPI1_RX / USART3_TX */
+    { .stream = 2 },    /* DMA1 Channel 3 - SPI1_TX */
+    { .stream = 6 },    /* DMA1 Channel 7 - USART2_TX */
+    { .stream = 4 },    /* DMA1 Channel 4 - USART1_TX */
+};
+
+#define DMA_0_ISR  isr_dma1_ch2
+#define DMA_1_ISR  isr_dma1_ch3
+#define DMA_2_ISR  isr_dma1_ch7
+#define DMA_3_ISR  isr_dma1_ch4
+
+#define DMA_NUMOF           (sizeof(dma_config) / sizeof(dma_config[0]))
+#endif
+/** @} */
+
 /**
  * @name   Timer configuration
  * @{
@@ -101,7 +122,11 @@ static const uart_conf_t uart_config[] = {
         .rx_af    = GPIO_AF7,
         .tx_af    = GPIO_AF7,
         .bus      = APB1,
-        .irqn     = USART2_IRQn
+        .irqn     = USART2_IRQn,
+#ifdef MODULE_PERIPH_DMA
+        .dma        = 2,
+        .dma_chan   = 2
+#endif
     },
     {
         .dev      = USART1,
@@ -111,7 +136,11 @@ static const uart_conf_t uart_config[] = {
         .rx_af    = GPIO_AF7,
         .tx_af    = GPIO_AF7,
         .bus      = APB2,
-        .irqn     = USART1_IRQn
+        .irqn     = USART1_IRQn,
+#ifdef MODULE_PERIPH_DMA
+        .dma        = 3,
+        .dma_chan   = 2
+#endif
     },
     {
         .dev      = USART3,
@@ -121,7 +150,11 @@ static const uart_conf_t uart_config[] = {
         .rx_af    = GPIO_AF7,
         .tx_af    = GPIO_AF7,
         .bus      = APB1,
-        .irqn     = USART3_IRQn
+        .irqn     = USART3_IRQn,
+#ifdef MODULE_PERIPH_DMA
+        .dma        = 0,
+        .dma_chan   = 2
+#endif
     },
 };
 
@@ -195,7 +228,13 @@ static const spi_conf_t spi_config[] = {
         .cs_pin   = GPIO_UNDEF,
         .af       = GPIO_AF5,
         .rccmask  = RCC_APB2ENR_SPI1EN,
-        .apbbus   = APB2
+        .apbbus   = APB2,
+#ifdef MODULE_PERIPH_DMA
+        .tx_dma   = 1,
+        .tx_dma_chan = 1,
+        .rx_dma   = 0,
+        .rx_dma_chan = 1,
+#endif
     }
 };
 
-- 
GitLab