diff --git a/include/libopencm3/stm32/common/dma_common_csel.h b/include/libopencm3/stm32/common/dma_common_csel.h index 04d93caf..755bb1df 100644 --- a/include/libopencm3/stm32/common/dma_common_csel.h +++ b/include/libopencm3/stm32/common/dma_common_csel.h @@ -43,6 +43,8 @@ specific memorymap.h header before including this header file.*/ BEGIN_DECLS +void dma_set_channel_request(uint32_t dma, uint8_t channel, uint8_t request); + END_DECLS /** @cond */ diff --git a/lib/stm32/common/dma_common_csel.c b/lib/stm32/common/dma_common_csel.c new file mode 100644 index 00000000..4cf1fca9 --- /dev/null +++ b/lib/stm32/common/dma_common_csel.c @@ -0,0 +1,46 @@ +/** @addtogroup dma_file DMA peripheral API +@ingroup peripheral_apis + +LGPL License Terms @ref lgpl_license + */ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2019 Guillaume Revaillot + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +/**@{*/ + +#include + +/*---------------------------------------------------------------------------*/ +/** @brief DMA Channel Set Request Selection + +Set DMA request mapping selection for given channel. Refer to datasheet for channel +request mapping tables. + +@param[in] dma DMA controller base address: DMA1 or DMA2 +@param[in] channel Channel number: 1-7 for DMA1 or 1-5 for DMA2 +@param[in] request DMA request mapping. +*/ + +void dma_set_channel_request(uint32_t dma, uint8_t channel, uint8_t request) +{ + uint32_t reg32 = DMA_CSELR(dma) & ~(DMA_CSELR_CxS_MASK << DMA_CSELR_CxS_SHIFT(channel)); + DMA_CSELR(dma) = reg32 | ((DMA_CSELR_CxS_MASK & request) << DMA_CSELR_CxS_SHIFT(channel)); +} + +/**@}*/ diff --git a/lib/stm32/f0/Makefile b/lib/stm32/f0/Makefile index 4480ff2f..9aeb71e5 100644 --- a/lib/stm32/f0/Makefile +++ b/lib/stm32/f0/Makefile @@ -39,7 +39,8 @@ OBJS = can.o flash.o rcc.o comparator.o \ OBJS += gpio_common_all.o gpio_common_f0234.o crc_common_all.o crc_v2.o \ pwr_common_v1.o iwdg_common_all.o rtc_common_l1f024.o \ - dma_common_l1f013.o exti_common_all.o \ + dma_common_l1f013.o dma_common_csel.o \ + exti_common_all.o \ dac_common_all.o \ timer_common_all.o timer_common_f0234.o rcc_common_all.o diff --git a/lib/stm32/l0/Makefile b/lib/stm32/l0/Makefile index facaa8dd..3cad62eb 100644 --- a/lib/stm32/l0/Makefile +++ b/lib/stm32/l0/Makefile @@ -42,7 +42,7 @@ OBJS += spi_common_all.o spi_common_v1.o spi_common_v1_frf.o OBJS += gpio_common_all.o gpio_common_f0234.o rcc_common_all.o OBJS += adc_common_v2.o OBJS += crs_common_all.o -OBJS += dma_common_l1f013.o +OBJS += dma_common_l1f013.o dma_common_csel.o OBJS += exti_common_all.o OBJS += flash_common_all.o flash_common_l01.o OBJS += i2c_common_v2.o diff --git a/lib/stm32/l4/Makefile b/lib/stm32/l4/Makefile index 43f4c831..dd834031 100644 --- a/lib/stm32/l4/Makefile +++ b/lib/stm32/l4/Makefile @@ -50,7 +50,7 @@ OBJS += rng_common_v1.o OBJS += timer_common_all.o OBJS += i2c_common_v2.o OBJS += usart_common_all.o usart_common_v2.o -OBJS += dma_common_l1f013.o +OBJS += dma_common_l1f013.o dma_common_csel.o OBJS += iwdg_common_all.o OBJS += rtc_common_l1f024.o OBJS += spi_common_all.o spi_common_v2.o