Skip to content

Commit 5644a08

Browse files
apc067kasjer
authored andcommitted
DA1469x: Fix crash when LPCLK is set to XTAL32K
Fix the root-cause of `g_mcu_clock_xtal32k_freq` not getting updated with a proper frequency value.
1 parent 0e7ff48 commit 5644a08

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

hw/mcu/dialog/da1469x/src/da1469x_clock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ enum da1469x_rtc_div_denom_sel {
8989
static uint32_t g_mcu_clock_rcx_freq;
9090
static uint32_t g_mcu_clock_rc32k_freq;
9191
static uint32_t g_mcu_clock_rc32m_freq = RC32M_FREQ;
92-
static uint32_t g_mcu_clock_xtal32k_freq;
92+
/* 32 kHz xtal freq, with nominal value until calibration */
93+
static uint32_t g_mcu_clock_xtal32k_freq = XTAL32K_FREQ;
9394

9495
uint32_t SystemCoreClock = RC32M_FREQ;
9596

hw/mcu/dialog/da1469x/src/da1469x_lpclk.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static void
3939
da1469x_lpclk_settle_tmr_cb(void *arg)
4040
{
4141
da1469x_clock_lp_xtal32k_switch();
42+
da1469x_clock_lp_xtal32k_calibrate();
4243
da1469x_lpclk_enabled();
4344
}
4445
#endif
@@ -87,12 +88,14 @@ da1469x_lpclk_rc_init(void)
8788
{
8889
#if MYNEWT_VAL_CHOICE(MCU_LPCLK_SOURCE, RCX)
8990
da1469x_clock_lp_rc32k_disable();
91+
da1469x_clock_lp_xtal32k_disable();
9092
da1469x_clock_lp_rcx_enable();
9193
da1469x_clock_lp_rcx_switch();
9294
da1469x_clock_lp_calibrate();
9395
da1469x_lpclk_enabled();
9496
#elif MYNEWT_VAL_CHOICE(MCU_LPCLK_SOURCE, RC32K)
9597
da1469x_clock_lp_rcx_disable();
98+
da1469x_clock_lp_xtal32k_disable();
9699
da1469x_clock_lp_rc32k_enable();
97100
da1469x_clock_lp_rc32k_switch();
98101
da1469x_clock_lp_calibrate();
@@ -102,8 +105,12 @@ da1469x_lpclk_rc_init(void)
102105
* We cannot switch lp_clk to XTAL32K here since it needs some time to
103106
* settle, so we just disable RCX (we don't need it) and then we'll handle
104107
* switch to XTAL32K from sysinit since we need os_cputime for this.
108+
*
109+
* Note: RC32K is still needed for the Watchdog timer.
105110
*/
106111
da1469x_clock_lp_rcx_disable();
112+
da1469x_clock_lp_rc32k_enable();
113+
da1469x_clock_lp_xtal32k_enable();
107114
#endif
108115
}
109116

@@ -112,7 +119,6 @@ da1469x_lpclk_init(void)
112119
{
113120
#if MYNEWT_VAL_CHOICE(MCU_LPCLK_SOURCE, XTAL32K)
114121
static struct hal_timer lpclk_settle_tmr;
115-
da1469x_clock_lp_xtal32k_enable();
116122
os_cputime_timer_init(&lpclk_settle_tmr, da1469x_lpclk_settle_tmr_cb, NULL);
117123
os_cputime_timer_relative(&lpclk_settle_tmr,
118124
MYNEWT_VAL(MCU_CLOCK_XTAL32K_SETTLE_TIME_MS) * 1000);

0 commit comments

Comments
 (0)