Skip to content

Commit

Permalink
hw/mcu/nordic/nrf52xxx: Using hfxo_request and release. Addresses apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
ncasaril committed Dec 16, 2020
1 parent 80f4f09 commit a86f9c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
12 changes: 2 additions & 10 deletions hw/mcu/nordic/nrf52xxx/src/hal_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "hal/hal_system.h"
#include "hal/hal_debug.h"
#include "nrf.h"
#include "mcu/nrf52_clock.h"

/**
* Function called at startup. Called after BSS and .data initialized but
Expand Down Expand Up @@ -92,16 +93,7 @@ hal_system_clock_start(void)

#if MYNEWT_VAL_CHOICE(MCU_LFCLK_SOURCE, LFSYNTH)
/* Must turn on HFLCK for synthesized 32768 crystal */
if ((NRF_CLOCK->HFCLKSTAT & CLOCK_HFCLKSTAT_STATE_Msk) !=
(CLOCK_HFCLKSTAT_STATE_Running << CLOCK_HFCLKSTAT_STATE_Pos)) {
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while (1) {
if ((NRF_CLOCK->EVENTS_HFCLKSTARTED) != 0) {
break;
}
}
}
nrf52_clock_hfxo_request();
#endif

/* Check if this clock source is already running */
Expand Down
16 changes: 5 additions & 11 deletions hw/mcu/nordic/nrf52xxx/src/hal_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "hal/hal_timer.h"
#include "nrf.h"
#include "mcu/nrf52_hal.h"
#include "mcu/nrf52_clock.h"

/* IRQ prototype */
typedef void (*hal_timer_irq_handler_t)(void);
Expand Down Expand Up @@ -652,17 +653,7 @@ hal_timer_config(int timer_num, uint32_t freq_hz)

#if MYNEWT_VAL_CHOICE(MCU_HFCLK_SOURCE, HFXO)
/* Make sure HFXO is started */
if ((NRF_CLOCK->HFCLKSTAT &
(CLOCK_HFCLKSTAT_SRC_Msk | CLOCK_HFCLKSTAT_STATE_Msk)) !=
(CLOCK_HFCLKSTAT_SRC_Msk | CLOCK_HFCLKSTAT_STATE_Msk)) {
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while (1) {
if ((NRF_CLOCK->EVENTS_HFCLKSTARTED) != 0) {
break;
}
}
}
nrf52_clock_hfxo_request();
#endif
hwtimer = bsptimer->tmr_reg;

Expand Down Expand Up @@ -723,6 +714,9 @@ hal_timer_deinit(int timer_num)
}
bsptimer->tmr_enabled = 0;
bsptimer->tmr_reg = NULL;
#if MYNEWT_VAL_CHOICE(MCU_HFCLK_SOURCE, HFXO)
nrf52_clock_hfxo_release();
#endif
__HAL_ENABLE_INTERRUPTS(ctx);

err:
Expand Down

0 comments on commit a86f9c7

Please sign in to comment.