KW45/MCXW71 Changing Clocking peripherals from FRO6M to other clock sources

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

KW45/MCXW71 Changing Clocking peripherals from FRO6M to other clock sources

KW45/MCXW71 Changing Clocking peripherals from FRO6M to other clock sources

In modern embedded systems, precise and reliable clocking is fundamental to the correct operation of digital peripherals. Microcontrollers like NXP’s KW45 and MCXW71 rely on internal oscillators to provide timing references for peripherals such as UART, SPI, timers, and ADCs. One such oscillator is the 6 MHz Free Running Oscillator (FRO6M), which is commonly used as a default clock source.

This article provides a comprehensive guide to:

Selecting and configuring alternative clock sources

Choosing an alternative clock source


The KW45/MCXW71 microcontroller offers several alternatives, including the Free Running Osilator 192Mhz (FRO192), the RF_OSC , and external crystal oscillators. Each option has its own advantages: FRO192 is stable and available, and external oscillators provide long-term accuracy. The choice of clock source should be based on the peripheral’s timing requirements, power constraints, and the availability of the clock in the current operating mode.

Reconfiguring Peripheral Clock Sources
Reconfiguring a peripheral’s clock source in KW45 is straightforward using the SDK’s clock management APIs. The function CLOCK_SetIpSrc() allows developers to assign a new clock source to a specific peripheral.
Example on changing a UART clocking from FRO6M to other clocksource.

  • UART peripheral connected to FRO6M

 

    uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ;

    CLOCK_SetIpSrc(kCLOCK_Lpuart1, kCLOCK_IpSrcFro6M);

    DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);

 


For example, to switch a UART from FRO6M to FRO-192M, the following code can be used:

//Replace kCLOCK_Lpuart1 for your peripheral for clicking
CLOCK_SetIpSrc(kCLOCK_Lpuart1, kCLOCK_IpSrcFro192M);

Also in the example above we would have to set the  uint32_t uartClkSrcFreq  variable to the correct freq value corresponding to the FRO192M as it is being used as clock source, but the same logic applies to any other clock source for the peripheral.

 

Other clocking changes for modules can be done as shown in this examples:

//Change clock source for LPIT 0 module from 6M FRO to other clocksources
/* Iniital source for the LPIT module */
CLOCK_SetIpSrc(kCLOCK_Lpit0, kCLOCK_IpSrcFro6M);
/* Set the new source for the LPIT 0 module */
CLOCK_SetIpSrc(kCLOCK_Lpit0, kCLOCK_IpSrcFro192M);
/* Set the corresponding divider for application, need to be decided by developer*/
CLOCK_SetIpSrcDiv(kCLOCK_Lpit0, 15U);


/* Set the source for the TPM 0 module */
CLOCK_SetIpSrc(kCLOCK_Tpm0, kCLOCK_IpSrcFro6M);
/* Set the source for the TPM 0 module */
CLOCK_SetIpSrc(kCLOCK_Tpm0, kCLOCK_IpSrcFro192M);
/* Set the corresponding divider for application, need to be decided by developer*/
CLOCK_SetIpSrcDiv(kCLOCK_Tpm0, 3U);

//Change clock source for Luart 1 module from 6M FRO to other clocksources
CLOCK_SetIpSrc(kCLOCK_Lpuart1, kCLOCK_IpSrcFro6M);
/* Set the source for the Lpuart 1 module */
CLOCK_SetIpSrc(kCLOCK_Lpuart1, kCLOCK_IpSrcFro192M);
uartClkSrcFreq = CLOCK_GetIpFreq(kCLOCK_Lpuart1);
DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);

After changing the clock source, it is important to reinitialize the peripheral to ensure that timing parameters such as baud rate, prescaler, or sampling intervals are correctly recalculated. This step ensures that the peripheral operates reliably with the new clock configuration.

Those were some examples on changing clock sources for some peripherals, but the same logic can be applied to any other module or peripheral, those examples were taken from SDK 2.16.00 as an example on how a module configured with a clock source can be switched to another.

評価なし
バージョン履歴
最終更新日:
木曜日
更新者: