AnsweredAssumed Answered

lpc54618: XTAL crystal frequency not coming on CLKOUT

Question asked by Subodh Mankar on Nov 30, 2017

Hi,

 

I am using lpc54618 eval board, I was checking CLKOUT on oscilloscope using following code for BOARD_BootClockRUN but still was unable to see clock output on scope...

 

If I use :- CLOCK_AttachClk(kOSC32K_OSC_to_CLKOUT); /*!< Switch CLKOUT to OSC32K_OSC */

Or :- CLOCK_AttachClk(kMAIN_CLK_to_CLKOUT);

I get proper clkout on scope

 

 

I dont get output for :- CLOCK_AttachClk(kEXT_CLK_to_CLKOUT); /*!< Switch CLKOUT to EXT_CLK */

 

/*******************************************************************************

********************** Configuration BOARD_BootClockRUN ***********************

******************************************************************************/

/* clang-format off */

/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************

!!Configuration

name: BOARD_BootClockRUN

called_from_default_init: true

outputs:

- {id: CLKOUT_clock.outFreq, value: 12 MHz}

- {id: FRO12M_clock.outFreq, value: 12 MHz}

- {id: FROHF_clock.outFreq, value: 48 MHz}

- {id: FXCOMs_CLK32K_clock.outFreq, value: 32.768 kHz}

- {id: MAIN_clock.outFreq, value: 12 MHz}

- {id: System_clock.outFreq, value: 12 MHz}

settings:

- {id: SYSCON.CLKOUTSELA.sel, value: SYSCON._clk_in}

sources:

- {id: RTC.rtc_32k_osc.outFreq, value: 32.768 kHz, enabled: true}

- {id: SYSCON._clk_in.outFreq, value: 12 MHz, enabled: true}

* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/

/* clang-format on */

 

/*******************************************************************************

* Variables for BOARD_BootClockRUN configuration

******************************************************************************/

/*******************************************************************************

* Code for BOARD_BootClockRUN configuration

******************************************************************************/

void BOARD_BootClockRUN(void)

{

/*!< Set up the clock sources */

/*!< Set up FRO */

POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */

CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without accidentally

being below the voltage for current speed */

POWER_DisablePD(kPDRUNCFG_PD_SYS_OSC); /*!< Enable System Oscillator Power */

SYSCON->SYSOSCCTRL = ((SYSCON->SYSOSCCTRL & ~SYSCON_SYSOSCCTRL_FREQRANGE_MASK) | SYSCON_SYSOSCCTRL_FREQRANGE(0U)); /*!< Set system oscillator range */

POWER_SetVoltageForFreq(12000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */

CLOCK_SetFLASHAccessCyclesForFreq(12000000U); /*!< Set FLASH wait states for core */

 

/*!< Set up RTC OSC */

CLOCK_EnableClock(kCLOCK_Rtc); /*!< Enable the RTC peripheral clock */

RTC->CTRL &= ~RTC_CTRL_SWRESET_MASK; /*!< Make sure the reset bit is cleared */

RTC->CTRL &= ~RTC_CTRL_RTC_OSC_PD_MASK; /*!< Setup RTC oscillator */

SYSCON->RTCOSCCTRL = SYSCON_RTCOSCCTRL_EN_MASK; /*!< Setup RTC oscillator clock source availability to other modules */

 

 

/*!< Set up dividers */

CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Reset divider counter and set divider to value 1 */

CLOCK_SetClkDiv(kCLOCK_DivClkOut, 0U, true); /*!< Reset CLKOUTDIV divider counter and halt it */

CLOCK_SetClkDiv(kCLOCK_DivClkOut, 1U, false); /*!< Set CLKOUTDIV divider to value 1 */

 

/*!< Set up clock selectors - Attach clocks to the peripheries */

CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO12M */

CLOCK_AttachClk(kEXT_CLK_to_CLKOUT); /*!< Switch CLKOUT to EXT_CLK */

/* Set SystemCoreClock variable. */

SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;

}

 

In Main function following code is used

{......

CLOCK_DisableClock(kCLOCK_ClockOut);

CLOCK_EnableClock(kCLOCK_ClockOut);

 

sourceClockFreq = CLOCK_GetClockOutClkFreq();

 

//CLOCK_SetClkDiv(kCLOCK_DivSpifiClk, sourceClockFreq / EXAMPLE_SPI_BAUDRATE - 1U, false);

CLOCK_SetClkDiv(kCLOCK_DivClkOut, sourceClockFreq / EXAMPLE_CLKOUT_BAUDRATE, false);

......}

 

 

Please let me know any suggestions or modifications to code to get CLKOUT from external crystal.

Outcomes