From 6d18a51769fa131f8d2e50e72c98cae31f4bc20d Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 23 Aug 2017 14:23:17 +0200 Subject: [PATCH] cpu:_stm32_common: #ifdef -> if --- cpu/stm32_common/stmclk_common.c | 51 +++++++++++++++++++------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/cpu/stm32_common/stmclk_common.c b/cpu/stm32_common/stmclk_common.c index b4cd347c8d..48361a427d 100644 --- a/cpu/stm32_common/stmclk_common.c +++ b/cpu/stm32_common/stmclk_common.c @@ -47,6 +47,13 @@ #define BIT_LSERDY RCC_BDCR_LSERDY #endif +#ifndef CLOCK_HSE +#define CLOCK_HSE (0U) +#endif +#ifndef CLOCK_LSE +#define CLOCK_LSE (0U) +#endif + void stmclk_enable_hsi(void) { RCC->CR |= RCC_CR_HSION; @@ -57,36 +64,38 @@ void stmclk_disable_hsi(void) { /* we only disable the HSI clock if not used as input for the PLL and if * not used directly as system clock */ -#if CLOCK_HSE - if ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI) { - RCC->CR &= ~(RCC_CR_HSION); + if (CLOCK_HSE) { + if ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI) { + RCC->CR &= ~(RCC_CR_HSION); + } } -#endif } void stmclk_enable_lfclk(void) { -#if CLOCK_LSE - stmclk_dbp_unlock(); - RCC->REG_LSE |= BIT_LSEON; - while (!(RCC->REG_LSE & BIT_LSERDY)) {} - stmclk_dbp_lock(); -#else - RCC->CSR |= RCC_CSR_LSION; - while (!(RCC->CSR & RCC_CSR_LSIRDY)) {} -#endif + if (CLOCK_LSE) { + stmclk_dbp_unlock(); + RCC->REG_LSE |= BIT_LSEON; + while (!(RCC->REG_LSE & BIT_LSERDY)) {} + stmclk_dbp_lock(); + } + else { + RCC->CSR |= RCC_CSR_LSION; + while (!(RCC->CSR & RCC_CSR_LSIRDY)) {} + } } void stmclk_disable_lfclk(void) { -#if CLOCK_LSE - stmclk_dbp_unlock(); - RCC->REG_LSE &= ~(BIT_LSEON); - while (!(RCC->REG_LSE & BIT_LSERDY)) {} - stmclk_dbp_lock(); -#else - RCC->CSR &= ~(RCC_CSR_LSION); -#endif + if (CLOCK_LSE) { + stmclk_dbp_unlock(); + RCC->REG_LSE &= ~(BIT_LSEON); + while (!(RCC->REG_LSE & BIT_LSERDY)) {} + stmclk_dbp_lock(); + } + else { + RCC->CSR &= ~(RCC_CSR_LSION); + } } void stmclk_dbp_unlock(void)