Merge pull request #2005 from haukepetersen/fix_nrf_enablehfclk

cpu/nrf51822: added HFCLK initialization
This commit is contained in:
Christian Mehlis 2014-11-25 23:41:34 +01:00
commit 3cd370ff6b
5 changed files with 67 additions and 0 deletions

View File

@ -14,6 +14,7 @@
* @brief Peripheral MCU configuration for the Airfy Beacon board * @brief Peripheral MCU configuration for the Airfy Beacon board
* *
* @author Christian Mehlis <mehlis@inf.fu-berlin.de> * @author Christian Mehlis <mehlis@inf.fu-berlin.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/ */
#ifndef __PERIPH_CONF_H #ifndef __PERIPH_CONF_H
@ -23,6 +24,19 @@
extern "C" { extern "C" {
#endif #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 * @name Timer configuration
* @{ * @{

View File

@ -25,6 +25,19 @@
extern "C" { extern "C" {
#endif #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 * @name Timer configuration
* @{ * @{

View File

@ -25,6 +25,19 @@
extern "C" { extern "C" {
#endif #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 * @name Timer configuration
* @{ * @{

View File

@ -23,6 +23,19 @@
extern "C" { extern "C" {
#endif #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 * @name Timer configuration
* @{ * @{

View File

@ -18,6 +18,7 @@
*/ */
#include "cpu.h" #include "cpu.h"
#include "periph_conf.h"
/** /**
* @brief Initialize the CPU, set IRQ priorities * @brief Initialize the CPU, set IRQ priorities
@ -26,4 +27,17 @@ void cpu_init(void)
{ {
/* set pendSV interrupt to lowest possible priority */ /* set pendSV interrupt to lowest possible priority */
NVIC_SetPriority(PendSV_IRQn, 0xff); 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
} }