Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
da1469x/clock: Add missing services
This commit adds the missing services to the driver API. It also makes the
actual calibration of the XTAL32K clock a syscfg option, defaulting to 0.
  • Loading branch information
apc067 committed Oct 29, 2024
commit 5f2b136ae442a4b589b5d72f73f354c26c9f63c2
40 changes: 40 additions & 0 deletions hw/mcu/dialog/da1469x/include/mcu/da1469x_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ void da1469x_clock_sys_xtal32m_switch_safe(void);
*/
void da1469x_clock_sys_rc32m_disable(void);

/**
* Enable RC32M
*/
void da1469x_clock_sys_rc32m_enable(void);

/**
* Switch sys_clk to RC32M
*/
void da1469x_clock_sys_rc32m_switch(void);

/**
* Disable XTAL32K
*/
void da1469x_clock_lp_xtal32k_disable(void);

/**
* Enable XTAL32K
*/
Expand All @@ -73,6 +88,21 @@ void da1469x_clock_lp_xtal32k_enable(void);
*/
void da1469x_clock_lp_xtal32k_switch(void);

/**
* Disable RC32K
*/
void da1469x_clock_lp_rc32k_disable(void);

/**
* Enable RC32K
*/
void da1469x_clock_lp_rc32k_enable(void);

/**
* Switch lp_clk to RC32K
*/
void da1469x_clock_lp_rc32k_switch(void);

/**
* Enable RCX
*/
Expand All @@ -95,6 +125,11 @@ void da1469x_clock_lp_rcx_calibrate(void);
*/
void da1469x_clock_lp_rc32k_calibrate(void);

/**
* Calibrate XTAL32K
*/
void da1469x_clock_lp_xtal32k_calibrate(void);

/**
* Calibrate RC32M
*/
Expand All @@ -110,6 +145,11 @@ uint32_t da1469x_clock_lp_rcx_freq_get(void);
*/
uint32_t da1469x_clock_lp_rc32k_freq_get(void);

/**
* Get calibrated XTAL32K frequency
*/
uint32_t da1469x_clock_lp_xtal32k_freq_get(void);

/**
* Get calibrated (measured) RC32M frequency
*/
Expand Down
71 changes: 70 additions & 1 deletion hw/mcu/dialog/da1469x/src/da1469x_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

static uint32_t g_mcu_clock_rcx_freq;
static uint32_t g_mcu_clock_rc32k_freq;
static uint32_t g_mcu_clock_rc32m_freq;
static uint32_t g_mcu_clock_rc32m_freq = RC32M_FREQ;
static uint32_t g_mcu_clock_xtal32k_freq;

uint32_t SystemCoreClock = RC32M_FREQ;

Expand Down Expand Up @@ -129,6 +130,30 @@ da1469x_clock_sys_rc32m_disable(void)
CRG_TOP->CLK_RC32M_REG &= ~CRG_TOP_CLK_RC32M_REG_RC32M_ENABLE_Msk;
}

void
da1469x_clock_sys_rc32m_enable(void)
{
CRG_TOP->CLK_RC32M_REG |= CRG_TOP_CLK_RC32M_REG_RC32M_ENABLE_Msk;
}

void
da1469x_clock_sys_rc32m_switch(void)
{
CRG_TOP->CLK_CTRL_REG = (CRG_TOP->CLK_CTRL_REG &
~CRG_TOP_CLK_CTRL_REG_SYS_CLK_SEL_Msk) |
(1 << CRG_TOP_CLK_CTRL_REG_SYS_CLK_SEL_Pos);

while (!(CRG_TOP->CLK_CTRL_REG & CRG_TOP_CLK_CTRL_REG_RUNNING_AT_RC32M_Msk));

SystemCoreClock = g_mcu_clock_rc32m_freq;
}

void
da1469x_clock_lp_xtal32k_disable(void)
{
CRG_TOP->CLK_XTAL32K_REG &= ~CRG_TOP_CLK_XTAL32K_REG_XTAL32K_ENABLE_Msk;
}

void
da1469x_clock_lp_xtal32k_enable(void)
{
Expand All @@ -147,6 +172,31 @@ da1469x_clock_lp_xtal32k_switch(void)
}
}

void
da1469x_clock_lp_rc32k_disable(void)
{
CRG_TOP->CLK_RC32K_REG &= ~CRG_TOP_CLK_RC32K_REG_RC32K_ENABLE_Msk;
}

void
da1469x_clock_lp_rc32k_enable(void)
{
CRG_TOP->CLK_RC32K_REG |= CRG_TOP_CLK_RC32K_REG_RC32K_ENABLE_Msk;
}

void
da1469x_clock_lp_rc32k_switch(void)
{
CRG_TOP->CLK_CTRL_REG = (CRG_TOP->CLK_CTRL_REG &
~CRG_TOP_CLK_CTRL_REG_LP_CLK_SEL_Msk) |
(0 << CRG_TOP_CLK_CTRL_REG_LP_CLK_SEL_Pos);

/* If system is running on LP clock update SystemCoreClock */
if (CRG_TOP->CLK_CTRL_REG & CRG_TOP_CLK_CTRL_REG_RUNNING_AT_LP_CLK_Msk) {
SystemCoreClock = g_mcu_clock_rc32k_freq;
}
}

void
da1469x_clock_lp_rcx_enable(void)
{
Expand Down Expand Up @@ -286,6 +336,17 @@ da1469x_clock_lp_rc32k_calibrate(void)
g_mcu_clock_rc32k_freq = freq;
}

void
da1469x_clock_lp_xtal32k_calibrate(void)
{
#if MYNEWT_VAL(MCU_CLOCK_XTAL32K_ALLOW_CALIB)
g_mcu_clock_xtal32k_freq =
da1469x_clock_calibrate(2, MYNEWT_VAL(MCU_CLOCK_RCX_CAL_REF_CNT));
#else
g_mcu_clock_xtal32k_freq = XTAL32K_FREQ;
#endif
}

void
da1469x_clock_lp_rc32m_calibrate(void)
{
Expand All @@ -308,6 +369,14 @@ da1469x_clock_lp_rc32k_freq_get(void)
return g_mcu_clock_rc32k_freq;
}

uint32_t
da1469x_clock_lp_xtal32k_freq_get(void)
{
assert(g_mcu_clock_xtal32k_freq);

return g_mcu_clock_xtal32k_freq;
}

uint32_t
da1469x_clock_lp_rc32m_freq_get(void)
{
Expand Down
5 changes: 5 additions & 0 deletions hw/mcu/dialog/da1469x/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ syscfg.defs:
Specifies settling time [ms] of 32K crystal oscillator.
value: 8000

MCU_CLOCK_XTAL32K_ALLOW_CALIB:
description: >
Specifies that the 32K crystal oscillator should be calibrated.
value: 0

MCU_CLOCK_RCX_CAL_REF_CNT:
description: >
Reference count value for calibration of RCX clock. The higher
Expand Down