From 90bb98e83daf714f22eb3f8af6ae57ec4078ee32 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 6 Apr 2018 01:04:08 +0200 Subject: [PATCH] stm32/dac: Add support for H7 MCUs. Includes a fix for H7 DAC DMA requests. --- ports/stm32/dac.c | 10 ++++++++++ ports/stm32/dma.c | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ports/stm32/dac.c b/ports/stm32/dac.c index 9d8d7a872f..bce30dbc7e 100644 --- a/ports/stm32/dac.c +++ b/ports/stm32/dac.c @@ -65,6 +65,10 @@ #if defined(MICROPY_HW_ENABLE_DAC) && MICROPY_HW_ENABLE_DAC +#if defined(STM32H7) +#define DAC DAC1 +#endif + STATIC DAC_HandleTypeDef DAC_Handle; void dac_init(void) { @@ -160,6 +164,8 @@ STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, size_t n_args, const mp // DAC peripheral clock #if defined(STM32F4) || defined(STM32F7) __DAC_CLK_ENABLE(); + #elif defined(STM32H7) + __HAL_RCC_DAC12_CLK_ENABLE(); #elif defined(STM32L4) __HAL_RCC_DAC1_CLK_ENABLE(); #else @@ -256,10 +262,14 @@ STATIC mp_obj_t pyb_dac_deinit(mp_obj_t self_in) { pyb_dac_obj_t *self = self_in; if (self->dac_channel == DAC_CHANNEL_1) { DAC_Handle.Instance->CR &= ~DAC_CR_EN1; + #ifndef STM32H7 DAC_Handle.Instance->CR |= DAC_CR_BOFF1; + #endif } else { DAC_Handle.Instance->CR &= ~DAC_CR_EN2; + #ifndef STM32H7 DAC_Handle.Instance->CR |= DAC_CR_BOFF2; + #endif } return mp_const_none; } diff --git a/ports/stm32/dma.c b/ports/stm32/dma.c index b0efd2a938..7ea2eaa3b4 100644 --- a/ports/stm32/dma.c +++ b/ports/stm32/dma.c @@ -336,8 +336,8 @@ const dma_descr_t dma_SPI_2_TX = { DMA1_Stream4, DMA_REQUEST_SPI2_TX, DMA_MEMORY const dma_descr_t dma_I2C_3_TX = { DMA1_Stream4, DMA_REQUEST_I2C3_TX, DMA_MEMORY_TO_PERIPH, dma_id_4, &dma_init_struct_spi_i2c }; const dma_descr_t dma_I2C_4_TX = { DMA1_Stream5, BDMA_REQUEST_I2C4_TX, DMA_MEMORY_TO_PERIPH, dma_id_5, &dma_init_struct_spi_i2c }; #if defined(MICROPY_HW_ENABLE_DAC) && MICROPY_HW_ENABLE_DAC -const dma_descr_t dma_DAC_1_TX = { DMA1_Stream5, DMA_REQUEST_DAC1_TX, DMA_MEMORY_TO_PERIPH, dma_id_5, &dma_init_struct_dac }; -const dma_descr_t dma_DAC_2_TX = { DMA1_Stream6, DMA_REQUEST_DAC2_TX, DMA_MEMORY_TO_PERIPH, dma_id_6, &dma_init_struct_dac }; +const dma_descr_t dma_DAC_1_TX = { DMA1_Stream5, DMA_REQUEST_DAC1_CH1, DMA_MEMORY_TO_PERIPH, dma_id_5, &dma_init_struct_dac }; +const dma_descr_t dma_DAC_2_TX = { DMA1_Stream6, DMA_REQUEST_DAC1_CH2, DMA_MEMORY_TO_PERIPH, dma_id_6, &dma_init_struct_dac }; #endif const dma_descr_t dma_SPI_3_TX = { DMA1_Stream7, DMA_REQUEST_SPI3_TX, DMA_MEMORY_TO_PERIPH, dma_id_7, &dma_init_struct_spi_i2c }; const dma_descr_t dma_I2C_1_TX = { DMA1_Stream7, DMA_REQUEST_I2C1_TX, DMA_MEMORY_TO_PERIPH, dma_id_7, &dma_init_struct_spi_i2c };