From bc2f468948050fbb51361223c575e35c2480a13e Mon Sep 17 00:00:00 2001 From: Daniel Fekete Date: Mon, 26 Jun 2017 21:32:07 +0200 Subject: [PATCH] spi: Add DMA settings for L0 / L4 --- STM32/libraries/SDIO/src/SDIO.h | 5 +++ STM32/libraries/stm32_dma/src/stm32_dma.c | 4 +++ STM32/libraries/stm32_dma/src/stm32_dma_L0.h | 34 +++++++++++++++++++ STM32/libraries/stm32_dma/src/stm32_dma_L4.h | 35 ++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 STM32/libraries/stm32_dma/src/stm32_dma_L0.h create mode 100644 STM32/libraries/stm32_dma/src/stm32_dma_L4.h diff --git a/STM32/libraries/SDIO/src/SDIO.h b/STM32/libraries/SDIO/src/SDIO.h index d8784ed..7f59549 100644 --- a/STM32/libraries/SDIO/src/SDIO.h +++ b/STM32/libraries/SDIO/src/SDIO.h @@ -42,6 +42,11 @@ #define SDIO_IRQHandler SDMMC1_IRQHandler #endif +// Fix typo for L4 +#ifndef HAL_SD_CardStateTypeDef +#define HAL_SD_CardStateTypeDef HAL_SD_CardStateTypedef +#define HAL_SD_CardStatusTypeDef HAL_SD_CardStatusTypedef +#endif /* * Aux function. Doesn't exist in HAL. Allows to pre-erase blocks when the count of blocks to write is known. diff --git a/STM32/libraries/stm32_dma/src/stm32_dma.c b/STM32/libraries/stm32_dma/src/stm32_dma.c index e7a918b..04dbde5 100644 --- a/STM32/libraries/stm32_dma/src/stm32_dma.c +++ b/STM32/libraries/stm32_dma/src/stm32_dma.c @@ -27,6 +27,10 @@ #include "stm32_dma_F2F4F7.h" #elif defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32L1) #include "stm32_dma_F0F1F3L1.h" +#elif defined(STM32L0) +#include "stm32_dma_L0.h" +#elif defined(STM32L4) +#include "stm32_dma_L4.h" #else #error "Unknown chip" #endif diff --git a/STM32/libraries/stm32_dma/src/stm32_dma_L0.h b/STM32/libraries/stm32_dma/src/stm32_dma_L0.h new file mode 100644 index 0000000..18ba2f0 --- /dev/null +++ b/STM32/libraries/stm32_dma/src/stm32_dma_L0.h @@ -0,0 +1,34 @@ +#define DMA1_Channel2_IRQn DMA1_Channel2_3_IRQn +#define DMA1_Channel3_IRQn DMA1_Channel2_3_IRQn + +#define DMA1_Channel4_IRQn DMA1_Channel4_5_6_7_IRQn +#define DMA1_Channel5_IRQn DMA1_Channel4_5_6_7_IRQn +#define DMA1_Channel6_IRQn DMA1_Channel4_5_6_7_IRQn +#define DMA1_Channel7_IRQn DMA1_Channel4_5_6_7_IRQn + + +typedef struct { + void *periphInstance; + dmaRequest request; + DMA_Channel_TypeDef *dmaInstance; + uint8_t dmaHandlesIndex; + uint8_t requestNumber; + uint8_t irqN; +} dma_request_to_instance_t; + +const dma_request_to_instance_t dmaRequestToStream[] = { + + {SPI1, SPI_TX, DMA1_Channel3, 3, 1, DMA1_Channel3_IRQn}, + {SPI1, SPI_RX, DMA1_Channel2, 2, 1, DMA1_Channel2_IRQn}, + +#ifdef SPI2 + {SPI2, SPI_TX, DMA1_Channel5, 5, 2, DMA1_Channel5_IRQn}, + {SPI2, SPI_RX, DMA1_Channel4, 4, 2, DMA1_Channel4_IRQn}, +#endif + +}; + +inline static void setDmaInstance(DMA_HandleTypeDef *handle, dma_request_to_instance_t dmaRequestToStream) { + handle->Instance = dmaRequestToStream.dmaInstance; + handle->Init.Request = dmaRequestToStream.requestNumber; +} diff --git a/STM32/libraries/stm32_dma/src/stm32_dma_L4.h b/STM32/libraries/stm32_dma/src/stm32_dma_L4.h new file mode 100644 index 0000000..cebc4a5 --- /dev/null +++ b/STM32/libraries/stm32_dma/src/stm32_dma_L4.h @@ -0,0 +1,35 @@ +typedef struct { + void *periphInstance; + dmaRequest request; + DMA_Channel_TypeDef *dmaInstance; + uint8_t dmaHandlesIndex; + uint8_t requestNumber; + uint8_t irqN; +} dma_request_to_instance_t; + +const dma_request_to_instance_t dmaRequestToStream[] = { + + {SPI1, SPI_TX, DMA1_Channel3, 3, 1, DMA1_Channel3_IRQn}, + {SPI1, SPI_RX, DMA1_Channel2, 2, 1, DMA1_Channel2_IRQn}, + +#ifdef SPI2 + {SPI2, SPI_TX, DMA1_Channel5, 5, 1, DMA1_Channel5_IRQn}, + {SPI2, SPI_RX, DMA1_Channel4, 4, 1, DMA1_Channel4_IRQn}, +#endif + +#ifdef SPI3 + {SPI3, SPI_TX, DMA2_Channel2, 2 + 8, 3, DMA2_Channel2_IRQn}, + {SPI3, SPI_RX, DMA2_Channel1, 1 + 8, 3, DMA2_Channel1_IRQn}, +#endif + +#if defined(SDMMC1) && defined(SD_InitTypeDef) + {SDMMC1, SDIO_RXTX, DMA2_Channel4, 6 + 8, 7, DMA2_Channel4_IRQn}, + {SDMMC1, SDIO_RXTX, DMA2_Channel5, 3 + 8, 7, DMA2_Channel5_IRQn}, +#endif + +}; + +inline static void setDmaInstance(DMA_HandleTypeDef *handle, dma_request_to_instance_t dmaRequestToStream) { + handle->Instance = dmaRequestToStream.dmaInstance; + handle->Init.Request = dmaRequestToStream.requestNumber; +}