From 87e16164882eb990498da604594d11f4eb3fdf27 Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Mon, 6 Mar 2017 20:06:47 +0100 Subject: [PATCH] nrf5/hal: Adding initialization of LFCLK if not already enabled in hal_rtc. --- nrf5/hal/hal_rtc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nrf5/hal/hal_rtc.c b/nrf5/hal/hal_rtc.c index 519de3eac1..bf10dfc8dc 100644 --- a/nrf5/hal/hal_rtc.c +++ b/nrf5/hal/hal_rtc.c @@ -39,6 +39,13 @@ void hal_rtc_callback_set(hal_rtc_app_callback callback) { void hal_rtc_init(hal_rtc_conf_t const * p_rtc_conf) { p_rtc_conf->p_instance->PRESCALER = (32768 / p_rtc_conf->frequency) - 1; // approx correct. hal_irq_priority(p_rtc_conf->irq_num, p_rtc_conf->irq_priority); + + // start LFCLK if not already started + if (NRF_CLOCK->LFCLKSTAT == 0) { + NRF_CLOCK->TASKS_LFCLKSTART = 1; + while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0); + NRF_CLOCK->EVENTS_LFCLKSTARTED = 0; + } } void hal_rtc_start(hal_rtc_conf_t const * p_rtc_conf, uint16_t period) {