Skip to content

Commit

Permalink
da1469x/clock: Protect register bitfields
Browse files Browse the repository at this point in the history
This commit adds masking to register bitfields, where a wrong syscfg value
may result in the inadvertent overrides of neighboring bitfields.
  • Loading branch information
apc067 committed Oct 29, 2024
1 parent 0baf5ae commit c4e9455
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions hw/mcu/dialog/da1469x/src/da1469x_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ da1469x_clock_sys_xtal32m_init(void)
*/
xtalrdy_cnt = MYNEWT_VAL(MCU_CLOCK_XTAL32M_SETTLE_TIME_US) * XTALRDY_IRQ_FREQ_MAX / 1000000;

CRG_XTAL->XTALRDY_CTRL_REG = (xtalrdy_cnt << CRG_XTAL_XTALRDY_CTRL_REG_XTALRDY_CNT_Pos) |
CRG_XTAL->XTALRDY_CTRL_REG = ((xtalrdy_cnt << CRG_XTAL_XTALRDY_CTRL_REG_XTALRDY_CNT_Pos) &
CRG_XTAL_XTALRDY_CTRL_REG_XTALRDY_CNT_Msk) |
(DA1469X_XTALRDY_CLK_SEL << CRG_XTAL_XTALRDY_CTRL_REG_XTALRDY_CLK_SEL_Pos);
}

Expand Down Expand Up @@ -294,7 +295,8 @@ da1469x_clock_calibrate(uint8_t clock_sel, uint16_t ref_cnt)
/* Select reference clock & calibrated clock */
ANAMISC_BIF->CLK_REF_SEL_REG =
(DA1469X_REF_SEL << ANAMISC_BIF_CLK_REF_SEL_REG_CAL_CLK_SEL_Pos) |
(clock_sel << ANAMISC_BIF_CLK_REF_SEL_REG_REF_CLK_SEL_Pos);
((clock_sel << ANAMISC_BIF_CLK_REF_SEL_REG_REF_CLK_SEL_Pos) &
ANAMISC_BIF_CLK_REF_SEL_REG_REF_CLK_SEL_Msk);

/* Start measurement */
ANAMISC_BIF->CLK_REF_SEL_REG |= ANAMISC_BIF_CLK_REF_SEL_REG_REF_CAL_START_Msk;
Expand Down Expand Up @@ -332,7 +334,7 @@ rc32k_trim_set(uint32_t trim)
{
CRG_TOP->CLK_RC32K_REG =
(CRG_TOP->CLK_RC32K_REG & ~CRG_TOP_CLK_RC32K_REG_RC32K_TRIM_Msk) |
(trim << CRG_TOP_CLK_RC32K_REG_RC32K_TRIM_Pos);
((trim << CRG_TOP_CLK_RC32K_REG_RC32K_TRIM_Pos) & CRG_TOP_CLK_RC32K_REG_RC32K_TRIM_Msk);
}

void
Expand Down

0 comments on commit c4e9455

Please sign in to comment.