From 2278e729523a14ed6a0ac3ff0cab7899c6e6da5e Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 12 Nov 2014 13:17:13 +0100 Subject: [PATCH 1/2] cpu/nrf51822: added HFCLK initialization --- cpu/nrf51822/cpu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cpu/nrf51822/cpu.c b/cpu/nrf51822/cpu.c index 8707095364..ff85420a35 100644 --- a/cpu/nrf51822/cpu.c +++ b/cpu/nrf51822/cpu.c @@ -18,6 +18,7 @@ */ #include "cpu.h" +#include "periph_conf.h" /** * @brief Initialize the CPU, set IRQ priorities @@ -26,4 +27,17 @@ void cpu_init(void) { /* set pendSV interrupt to lowest possible priority */ NVIC_SetPriority(PendSV_IRQn, 0xff); + + /* set the correct clock source for HFCLK */ +#if CLOCK_CRYSTAL == 32 + NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_32MHz; + NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; + NRF_CLOCK->TASKS_HFCLKSTART = 1; + while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0); +#elif CLOCK_CRYSTAL == 16 + NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz; + NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; + NRF_CLOCK->TASKS_HFCLKSTART = 1; + while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0); +#endif } From edea23299b2ef8951dbc7f6b8f6546a8dd684fa1 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 12 Nov 2014 13:17:41 +0100 Subject: [PATCH 2/2] boards: added CLOCK defines to NRF based boards --- boards/airfy-beacon/include/periph_conf.h | 14 ++++++++++++++ boards/pca10000/include/periph_conf.h | 13 +++++++++++++ boards/pca10005/include/periph_conf.h | 13 +++++++++++++ boards/yunjia-nrf51822/include/periph_conf.h | 13 +++++++++++++ 4 files changed, 53 insertions(+) diff --git a/boards/airfy-beacon/include/periph_conf.h b/boards/airfy-beacon/include/periph_conf.h index 16de55f925..bda397d326 100644 --- a/boards/airfy-beacon/include/periph_conf.h +++ b/boards/airfy-beacon/include/periph_conf.h @@ -14,6 +14,7 @@ * @brief Peripheral MCU configuration for the Airfy Beacon board * * @author Christian Mehlis + * @author Hauke Petersen */ #ifndef __PERIPH_CONF_H @@ -23,6 +24,19 @@ extern "C" { #endif +/** + * @name Clock configuration + * + * @note: the radio will not work with the internal RC oscillator! + * + * @{ + */ +#define CLOCK_CORECLOCK (16000000U) /* fixed for all NRF51822 */ +#define CLOCK_CRYSTAL (16U) /* set to 0: internal RC oscillator + 16: 16MHz crystal + 32: 32MHz crystal */ +/** @} */ + /** * @name Timer configuration * @{ diff --git a/boards/pca10000/include/periph_conf.h b/boards/pca10000/include/periph_conf.h index e2868aa10f..1d127a7d36 100644 --- a/boards/pca10000/include/periph_conf.h +++ b/boards/pca10000/include/periph_conf.h @@ -25,6 +25,19 @@ extern "C" { #endif +/** + * @name Clock configuration + * + * @note: the radio will not work with the internal RC oscillator! + * + * @{ + */ +#define CLOCK_CORECLOCK (16000000U) /* fixed for all NRF51822 */ +#define CLOCK_CRYSTAL (16U) /* set to 0: internal RC oscillator + 16: 16MHz crystal + 32: 32MHz crystal */ +/** @} */ + /** * @name Timer configuration * @{ diff --git a/boards/pca10005/include/periph_conf.h b/boards/pca10005/include/periph_conf.h index bfe53b7b43..1b800139ab 100644 --- a/boards/pca10005/include/periph_conf.h +++ b/boards/pca10005/include/periph_conf.h @@ -25,6 +25,19 @@ extern "C" { #endif +/** + * @name Clock configuration + * + * @note: the radio will not work with the internal RC oscillator! + * + * @{ + */ +#define CLOCK_CORECLOCK (16000000U) /* fixed for all NRF51822 */ +#define CLOCK_CRYSTAL (16U) /* set to 0: internal RC oscillator + 16: 16MHz crystal + 32: 32MHz crystal */ +/** @} */ + /** * @name Timer configuration * @{ diff --git a/boards/yunjia-nrf51822/include/periph_conf.h b/boards/yunjia-nrf51822/include/periph_conf.h index 259d8fadf3..32b85d7da0 100644 --- a/boards/yunjia-nrf51822/include/periph_conf.h +++ b/boards/yunjia-nrf51822/include/periph_conf.h @@ -23,6 +23,19 @@ extern "C" { #endif +/** + * @name Clock configuration + * + * @note: the radio will not work with the internal RC oscillator! + * + * @{ + */ +#define CLOCK_CORECLOCK (16000000U) /* fixed for all NRF51822 */ +#define CLOCK_CRYSTAL (16U) /* set to 0: internal RC oscillator + 16: 16MHz crystal + 32: 32MHz crystal */ +/** @} */ + /** * @name Timer configuration * @{