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 3c18debc8c..73d6d75f9b 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 4d145bb3dc..a08d2fc358 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 38a5a4a38c..5e19665cc4 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 * @{ 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 }