* arch/arm/src/kl/kl_clockconfig.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <arch/board/board.h>
#include "arm_internal.h"
#include "chip.h"
#include "kl_gpio.h"
#include "hardware/kl_mcg.h"
#include "hardware/kl_sim.h"
#include "hardware/kl_osc.h"
#include "hardware/kl_fmc.h"
#include "hardware/kl_llwu.h"
#include "hardware/kl_pinmux.h"
* Private Data
****************************************************************************/
* Public Data
****************************************************************************/
* Private Functions
****************************************************************************/
* Name: kl_portclocks
*
* Description:
* Enable all of the port clocks
*
****************************************************************************/
static inline void kl_portclocks(void)
{
uint32_t regval;
regval = getreg32(KL_SIM_SCGC5);
regval |= (SIM_SCGC5_PORTA | SIM_SCGC5_PORTB | SIM_SCGC5_PORTC |
SIM_SCGC5_PORTD | SIM_SCGC5_PORTE);
putreg32(regval, KL_SIM_SCGC5);
}
* Name: kl_pllconfig
*
* Description:
* Initialize the PLL using the settings in board.h. This assumes that
* the MCG is in default FLL Engaged Internal (FEI mode) out of reset.
*
****************************************************************************/
void kl_pllconfig(void)
{
uint32_t regval32;
uint8_t regval8;
regval32 = getreg32(KL_SIM_SCGC5);
regval32 |= SIM_SCGC5_PORTA;
putreg32(regval32, KL_SIM_SCGC5);
* settings in the board.h header file.
*/
regval32 = (SIM_CLKDIV1_OUTDIV1(BOARD_OUTDIV1) |
SIM_CLKDIV1_OUTDIV4(BOARD_OUTDIV4));
putreg32(regval32, KL_SIM_CLKDIV1);
* (OSC32KSEL=0)
*/
regval32 = getreg32(KL_SIM_SOPT1);
regval32 &= ~(SIM_SOPT1_OSC32KSEL_MASK);
putreg32(regval32, KL_SIM_SOPT1);
* Clock source for TPM counter clock is MCGFLLCLK or MCGPLLCLK/2
*/
regval32 = getreg32(KL_SIM_SOPT2);
regval32 |= SIM_SOPT2_PLLFLLSEL;
putreg32(regval32, KL_SIM_SOPT2);
regval32 = (regval32 & ~(SIM_SOPT2_TPMSRC_OCSERCLK)) |
SIM_SOPT2_TPMSRC_MCGCLK;
putreg32(regval32, KL_SIM_SOPT2);
regval32 = getreg32(KL_PORTA_PCR18);
regval32 &= ~(PORT_PCR_ISF | PORT_PCR_MUX_ALT7);
putreg32(regval32, KL_PORTA_PCR18);
regval32 = getreg32(KL_PORTA_PCR19);
regval32 &= ~(PORT_PCR_ISF | PORT_PCR_MUX_ALT7);
putreg32(regval32, KL_PORTA_PCR19);
* ??=0, EREFSTEN=0, ??=0, SC2P=0, SC4P=0, SC8P=0, SC16P=0
*/
putreg8(0, KL_OSC_CR);
regval8 = (MCG_C2_RANGE_VHIGH | MCG_C2_EREFS);
putreg8(regval8, KL_MCG_C2);
regval8 = (MCG_C1_CLKS_EXTREF | MCG_C1_FRDIV_R0DIV8);
putreg8(regval8, KL_MCG_C1);
regval8 = getreg8(KL_MCG_C4);
regval8 &= ~(MCG_C4_DMX32 | MCG_C4_DRST_DRS_MASK);
putreg8(regval8, KL_MCG_C4);
* settings in the board.h header file.
*/
regval8 = MCG_C5_PRDIV(BOARD_PRDIV0);
putreg8(regval8, KL_MCG_C5);
* settings in the board.h header file.
*/
putreg8(MCG_C6_VDIV(BOARD_VDIV0), KL_MCG_C6);
* reference clock.
*/
while ((getreg8(KL_MCG_S) & MCG_S_IREFST) != 0)
;
while ((getreg8(KL_MCG_S) & MCG_S_CLKST_MASK) != 8)
;
* Select PLL as MCG source (PLLS=1)
*/
putreg8(MCG_C6_PLLS, KL_MCG_C6);
while ((getreg8(KL_MCG_S) & MCG_S_LOCK) == 0)
;
* Select PLL output (CLKS=0)
* FLL external reference divider (FRDIV=3)
* External reference clock for FLL (IREFS=0)
*/
putreg8(MCG_C1_FRDIV_R0DIV8, KL_MCG_C1);
while ((getreg8(KL_MCG_S) & MCG_S_CLKST_MASK) != 0x0c);
}
* Public Functions
****************************************************************************/
* Name: kl_clockconfig
*
* Description:
* Called to initialize the Kinetis chip. This does whatever setup is
* needed to put the MCU in a usable state. This includes the
* initialization of clocking using the settings in board.h.
*
****************************************************************************/
void kl_clockconfig(void)
{
kl_portclocks();
kl_pllconfig();
* the FlexBus clock.
*/
}