Hi XiangJun Rong,
I do call CLOCK_SetupOsc32KClocking() to init the OSC32K, then run-time I need to call VBAT_SetOscConfig() to config the Crystal Load Capacitance.
CLOCK_SetupOsc32KClocking() locks OSCCTLA/OSCCTLB registers after its writing, without any previous unlock. VBAT_SetOscConfig() does not unlock/lock those registers.
I think CLOCK_SetupOsc32KClocking() works only because OSCCTLA/OSCTLB start unlocked after the reset. The same for the CLOCK_SetupClk16KClocking() function.
So, after the very first OSCCTLA/OSCCTLB registers lock, how to unlock them for a changing?
Is it right to do the following unlock sequence prior any registers write access?
/* Unlock */
VBAT0->OSCLCKA &= ~VBAT_OSCLCKA_LOCK_MASK;
VBAT0->OSCLCKB |= VBAT_OSCLCKB_LOCK_MASK;
After my registers writing, should I check STATUSA[CONFIG_DET] flag for any VBAT configuration error?