Skip to content

Commit 190d120

Browse files
hw/bsp/nrf53: Add syscfg for LFXO frequency
This allows to run nRF53 with 32000Hz LFXO.
1 parent 98ea2b5 commit 190d120

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed

hw/mcu/nordic/nrf5340/src/hal_os_tick.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
#error The OS scheduler requires a low-frequency timer; configure MCU_LFCLK_SOURCE
3030
#endif
3131

32-
#define RTC_FREQ 32768 /* in Hz */
32+
#if MYNEWT_VAL_CHOICE(MCU_LFCLK_SOURCE, LFXO)
33+
#define RTC_FREQ (MYNEWT_VAL(MCU_LFXO_FREQ))
34+
#else
35+
#define RTC_FREQ (32768) /* Hz */
36+
#endif
3337
#define OS_TICK_TIMER NRF_RTC1
3438
#define OS_TICK_IRQ RTC1_IRQn
3539
#define OS_TICK_CMPREG 3

hw/mcu/nordic/nrf5340/src/hal_timer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ typedef void (*hal_timer_irq_handler_t)(void);
4343
/* Maximum timer frequency */
4444
#define NRF5340_MAX_TIMER_FREQ (16000000)
4545

46+
#if MYNEWT_VAL_CHOICE(MCU_LFCLK_SOURCE, LFXO)
47+
#define LFCLK_FREQ (MYNEWT_VAL(MCU_LFXO_FREQ))
48+
#else
49+
#define LFCLK_FREQ (32768) /* Hz */
50+
#endif
51+
4652
struct nrf5340_hal_timer {
4753
uint8_t tmr_enabled;
4854
uint8_t tmr_irq_num;
@@ -539,8 +545,8 @@ hal_timer_config(int timer_num, uint32_t freq_hz)
539545

540546
#if (MYNEWT_VAL(TIMER_3) || MYNEWT_VAL(TIMER_4))
541547
if ((timer_num == 3) || (timer_num == 4)) {
542-
/* NOTE: we only allow the RTC frequency to be set at 32768 */
543-
if (bsptimer->tmr_enabled || (freq_hz != 32768) ||
548+
/* NOTE: we only allow the RTC frequency to be set to LFCLK freq */
549+
if (bsptimer->tmr_enabled || (freq_hz != LFCLK_FREQ) ||
544550
(bsptimer->tmr_reg == NULL)) {
545551
rc = EINVAL;
546552
goto err;

hw/mcu/nordic/nrf5340/syscfg.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ syscfg.defs:
6565
- c7pf # 7pF internal load capacitance
6666
- c9pf # 9pF internal load capacitance
6767

68+
MCU_LFXO_FREQ:
69+
description: >
70+
Frequency of LFXO oscillator.
71+
value: 32768
72+
6873
MCU_HFXO_INTCAP:
6974
description: >
7075
Control usage of internal load capacitors for 32 MHz crystal

hw/mcu/nordic/nrf5340_net/src/hal_os_tick.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
#error The OS scheduler requires a low-frequency timer; configure MCU_LFCLK_SOURCE
2929
#endif
3030

31-
#define RTC_FREQ 32768 /* in Hz */
31+
#if MYNEWT_VAL_CHOICE(MCU_LFCLK_SOURCE, LFXO)
32+
#define RTC_FREQ (MYNEWT_VAL(MCU_LFXO_FREQ))
33+
#else
34+
#define RTC_FREQ (32768) /* Hz */
35+
#endif
3236
#define OS_TICK_TIMER NRF_RTC1_NS
3337
#define OS_TICK_IRQ RTC1_IRQn
3438
#define OS_TICK_CMPREG 3

hw/mcu/nordic/nrf5340_net/src/hal_timer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ typedef void (*hal_timer_irq_handler_t)(void);
4343
/* Maximum timer frequency */
4444
#define NRF5340_MAX_TIMER_FREQ (16000000)
4545

46+
#if MYNEWT_VAL_CHOICE(MCU_LFCLK_SOURCE, LFXO)
47+
#define LFCLK_FREQ (MYNEWT_VAL(MCU_LFXO_FREQ))
48+
#else
49+
#define LFCLK_FREQ (32768) /* Hz */
50+
#endif
51+
4652
struct nrf5340_hal_timer {
4753
uint8_t tmr_enabled;
4854
uint8_t tmr_irq_num;
@@ -539,8 +545,8 @@ hal_timer_config(int timer_num, uint32_t freq_hz)
539545

540546
#if (MYNEWT_VAL(TIMER_3) || MYNEWT_VAL(TIMER_4))
541547
if ((timer_num == 3) || (timer_num == 4)) {
542-
/* NOTE: we only allow the RTC frequency to be set at 32768 */
543-
if (bsptimer->tmr_enabled || (freq_hz != 32768) ||
548+
/* NOTE: we only allow the RTC frequency to be set at LFCLK freq */
549+
if (bsptimer->tmr_enabled || (freq_hz != LFCLK_FREQ) ||
544550
(bsptimer->tmr_reg == NULL)) {
545551
rc = EINVAL;
546552
goto err;

hw/mcu/nordic/nrf5340_net/syscfg.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ syscfg.defs:
4949
- LFXO # 32.768 kHz crystal oscillator
5050
- LFSYNTH # 32.768 kHz synthesized from HFCLK
5151

52+
MCU_LFXO_FREQ:
53+
description: >
54+
Frequency of LFXO oscillator.
55+
value: 32768
56+
5257
MCU_GPIO_USE_PORT_EVENT:
5358
description: >
5459
When enabled, hal_gpio will use GPIOTE PORT event instead of PIN

0 commit comments

Comments
 (0)