diff --git a/boards/nucleo-l053/Makefile.features b/boards/nucleo-l053/Makefile.features index ae8430d7d..682b38069 100644 --- a/boards/nucleo-l053/Makefile.features +++ b/boards/nucleo-l053/Makefile.features @@ -1,6 +1,7 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_gpio +FEATURES_PROVIDED += periph_hwrng FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_spi FEATURES_PROVIDED += periph_timer diff --git a/boards/nucleo-l073/Makefile.features b/boards/nucleo-l073/Makefile.features index ae8430d7d..682b38069 100644 --- a/boards/nucleo-l073/Makefile.features +++ b/boards/nucleo-l073/Makefile.features @@ -1,6 +1,7 @@ # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_gpio +FEATURES_PROVIDED += periph_hwrng FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_spi FEATURES_PROVIDED += periph_timer diff --git a/cpu/stm32f4/periph/hwrng.c b/cpu/stm32_common/periph/hwrng.c similarity index 82% rename from cpu/stm32f4/periph/hwrng.c rename to cpu/stm32_common/periph/hwrng.c index 641d334f5..98409479a 100644 --- a/cpu/stm32f4/periph/hwrng.c +++ b/cpu/stm32_common/periph/hwrng.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2014-2016 Freie Universität Berlin + * Copyright (C) 2014-2017 Freie Universität Berlin + * 2016 OTA keys S.A. * * 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 @@ -7,13 +8,14 @@ */ /** - * @ingroup cpu_stm32f4 + * @ingroup cpu_stm32_common * @{ * * @file * @brief Low-level random number generator driver implementation * * @author Hauke Petersen + * @author Aurelien Gonce * * @} */ @@ -38,6 +40,8 @@ void hwrng_read(void *buf, unsigned int num) /* power on and enable the device */ #if defined(CPU_MODEL_STM32F410RB) periph_clk_en(AHB1, RCC_AHB1ENR_RNGEN); +#elif defined(CPU_FAM_STM32L0) + periph_clk_en(AHB, RCC_AHBENR_RNGEN); #else periph_clk_en(AHB2, RCC_AHB2ENR_RNGEN); #endif @@ -60,6 +64,8 @@ void hwrng_read(void *buf, unsigned int num) RNG->CR = 0; #if defined(CPU_MODEL_STM32F410RB) periph_clk_dis(AHB1, RCC_AHB1ENR_RNGEN); +#elif defined(CPU_FAM_STM32L0) + periph_clk_dis(AHB, RCC_AHBENR_RNGEN); #else periph_clk_dis(AHB2, RCC_AHB2ENR_RNGEN); #endif diff --git a/cpu/stm32f2/periph/hwrng.c b/cpu/stm32f2/periph/hwrng.c deleted file mode 100644 index 52bf752ac..000000000 --- a/cpu/stm32f2/periph/hwrng.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin - * Copyright (C) 2016 OTA keys S.A. - * - * 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_stm32f2 - * @{ - * - * @file - * @brief Low-level random number generator driver implementation - * - * @author Hauke Petersen - * @author Aurelien Gonce - * - * @} - */ - -#include "cpu.h" -#include "periph/hwrng.h" -#include "periph_conf.h" - -/* ignore file in case no RNG device is defined */ -#ifdef RNG - -void hwrng_init(void) -{ - /* enable RNG reset state */ - periph_clk_en(AHB2, RCC_AHB2ENR_RNGEN); - /* release RNG from reset state */ - periph_clk_dis(AHB2, RCC_AHB2ENR_RNGEN); -} - - -void hwrng_read(void *buf, unsigned int num) -{ - /* cppcheck-suppress variableScope */ - uint32_t tmp; - unsigned int count = 0; - uint8_t *b = (uint8_t *)buf; - - /* enable RNG reset state */ - periph_clk_en(AHB2, RCC_AHB2ENR_RNGEN); - /* enable the RNG */ - RNG->CR |= RNG_CR_RNGEN; - - while (count < num) { - /* wait for random data to be ready to read */ - while (!(RNG->SR & RNG_SR_DRDY)); - /* read next 4 bytes */ - tmp = RNG->DR; - /* copy data into result vector */ - for (int i = 0; i < 4 && count < num; i++) { - b[count++] = (uint8_t)tmp; - tmp = tmp >> 8; - } - } - - /* disable the RNG */ - RNG->CR &= ~RNG_CR_RNGEN; - /* release RNG from reset state */ - periph_clk_dis(AHB2, RCC_AHB2ENR_RNGEN); -} - -#endif /* RANDOM_NUMOF */