Unable to change VBAT0 OSCCTLA/OSCCTLB registers

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Unable to change VBAT0 OSCCTLA/OSCCTLB registers

2,118件の閲覧回数
Vagni
Contributor IV

On the MCXN547 MCU I need to change run-time and enable the internal capacitor banks on the EXTAL and XTAL pins for tuning the OSC32kHz. But writing to VBAT0 OSCCTLA/OSCCTLB registers seems to not work: I get the same initial value when I read out the registers after writing a new value.

I tried to use the SDK VBAT_SetOscConfig() driver function, but I get the OSCCTLA/OSCCTLB registers unchanged.

Then I tried my own writing sequence:

 

 

/* unlock the OSC32K registers */
VBAT0->OSCLCKA &= ~VBAT_OSCLCKA_LOCK_MASK;
VBAT0->OSCLCKB |= VBAT_OSCLCKB_LOCK_MASK;

/* tmp32 is previously set with the new register value */
VBAT0->OSCCTLA =    tmp32 & 0x000FFFFFUL;
VBAT0->OSCCTLB = (~tmp32) & 0x000FFFFFUL;

/* Wait for STATUSA[OSC_RDY] to set. */
while ((VBAT0->STATUSA & VBAT_STATUSA_OSC_RDY_MASK) == 0U)
{
}

/* lock the OSC32K registers */
VBAT0->OSCLCKA |= VBAT_OSCLCKA_LOCK_MASK;
VBAT0->OSCLCKB &= ~VBAT_OSCLCKB_LOCK_MASK; 

 

 

My code is executed without errors, OSC32K keeps running, but again I get the OSCCTLA/OSCCTLB registers unchanged.

What is the right sequence to change OSCCTLA/OSCCTLB registers?

 

ラベル(2)
タグ(2)
0 件の賞賛
返信
3 返答(返信)

2,059件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls refer to the section

/**

* @brief Initialize the OSC 32K.

* @param id : OSC 32 kHz output clock to specified modules

* @return returns success or fail status.

*/

status_t CLOCK_SetupOsc32KClocking(uint32_t id)

{

/* Enable LDO */

SCG0->LDOCSR |= SCG_LDOCSR_LDOEN_MASK | SCG_LDOCSR_VOUT_OK_MASK;

 

VBAT0->OSCCTLA =

(VBAT0->OSCCTLA & ~(VBAT_OSCCTLA_MODE_EN_MASK | VBAT_OSCCTLA_CAP_SEL_EN_MASK | VBAT_OSCCTLA_OSC_EN_MASK)) |

VBAT_OSCCTLA_MODE_EN(0x2) | VBAT_OSCCTLA_OSC_EN_MASK | VBAT_OSCCTLA_OSC_EN_MASK;

VBAT0->OSCCTLB = VBAT_OSCCTLB_INVERSE(0xDFF7E);

/* Wait for STATUSA[OSC_RDY] to set. */

while ((VBAT0->STATUSA & VBAT_STATUSA_OSC_RDY_MASK) == 0U)

{

}

VBAT0->OSCLCKA = VBAT_OSCLCKA_LOCK_MASK;

VBAT0->OSCLCKB &= ~VBAT_OSCLCKA_LOCK_MASK;

 

VBAT0->OSCCLKE |= VBAT_OSCCLKE_CLKE(id);

 

/* De-initializes the SCG ROSC */

SCG0->ROSCCSR = SCG_ROSCCSR_ROSCERR_MASK;

 

/* Unlock ROSCCSR */

SCG0->ROSCCSR &= ~SCG_ROSCCSR_LK_MASK;

 

/* Enable SOSC clock monitor and Enable ROSC */

SCG0->ROSCCSR |= SCG_ROSCCSR_ROSCCM_MASK;

 

/* Wait for ROSC clock to be valid. */

while ((SCG0->ROSCCSR & SCG_ROSCCSR_ROSCVLD_MASK) == 0U)

{

}

 

s_Xtal32_Freq = 32768U;

 

return kStatus_Success;

}

 

Hope it can help you

BR

XiangJun Rong

0 件の賞賛
返信

1,930件の閲覧回数
Vagni
Contributor IV

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?

 

0 件の賞賛
返信

1,905件の閲覧回数
Vagni
Contributor IV

From the MCXN Reference Manual  I see VBAT registers can be locked until the next power-on reset (POR). Only after a POR the VBAT registers are unlocked. If the VBAT registers are locked, they cannot be unlocked writing the LOCK bit in the xxxLCKA/xxxLCKB registers.

You can write the LOCK bit in the xxxLCKA/xxxLCKB registers only for locking.

The SDK VBAT driver functions lock the VBAT registers, so the VBAT registers cannot be changed afterwards.

Then, I remarked the OSCCTLA/OSCCTLB registers locking in the CLOCK_SetupOsc32KClocking()  function and now every call to VBAT_SetOscConfig() can successfully change the Crystal Load Capacitance.

 

0 件の賞賛
返信