From 462d1568218f8ef166a9eaaebe7f29f0241d320c Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 16 Mar 2016 12:13:47 +0100 Subject: [PATCH] cpu/stm32_common: added periph clk en/dis functions --- cpu/stm32_common/cpu_common.c | 39 ++++++++++++++++++++ cpu/stm32_common/include/periph_cpu_common.h | 20 +++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 cpu/stm32_common/cpu_common.c diff --git a/cpu/stm32_common/cpu_common.c b/cpu/stm32_common/cpu_common.c new file mode 100644 index 0000000000..7f6b0320a7 --- /dev/null +++ b/cpu/stm32_common/cpu_common.c @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2016 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_cortexm_common + * @{ + * + * @file + * @brief Shared CPU specific function for the STM32 CPU family + * + * @author Hauke Petersen + * + * @} + */ + +#include "periph_cpu_common.h" + +void periph_clk_en(uint8_t bus, uint32_t mask) +{ + if (bus == APB1) { + RCC->APB1ENR |= mask; + } else { + RCC->APB2ENR |= mask; + } +} + +void periph_clk_dis(uint8_t bus, uint32_t mask) +{ + if (bus == APB1) { + RCC->APB1ENR &= ~(mask); + } else { + RCC->APB2ENR &= ~(mask); + } +} diff --git a/cpu/stm32_common/include/periph_cpu_common.h b/cpu/stm32_common/include/periph_cpu_common.h index 9d521a9bc9..1e287a0053 100644 --- a/cpu/stm32_common/include/periph_cpu_common.h +++ b/cpu/stm32_common/include/periph_cpu_common.h @@ -43,10 +43,26 @@ extern "C" { * @brief Available peripheral buses */ enum { - APB1, - APB2 + APB1, /**< APB1 bus */ + APB2 /**< APB2 bus */ }; +/** + * @brief Enable the given peripheral clock + * + * @param[in] bus bus the peripheral is connected to + * @param[in] mask bit in the RCC enable register + */ +void periph_clk_en(uint8_t bus, uint32_t mask); + +/** + * @brief Disable the given peripheral clock + * + * @param[in] bus bus the peripheral is connected to + * @param[in] mask bit in the RCC enable register + */ +void periph_clk_dis(uint8_t bus, uint32_t mask); + #ifdef __cplusplus } #endif