2024-09-02 22:09:54 +08:00
|
|
|
/* Copyright 2017, 2019-2024 NXP
|
2019-04-24 16:52:51 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief System/hardware module for nxp_lpc55s69 platform
|
|
|
|
*
|
|
|
|
* This module provides routines to initialize and support board-level
|
|
|
|
* hardware for the nxp_lpc55s69 platform.
|
|
|
|
*/
|
|
|
|
|
2022-05-06 11:11:04 +02:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/device.h>
|
|
|
|
#include <zephyr/init.h>
|
2019-04-24 16:52:51 +03:00
|
|
|
#include <soc.h>
|
2022-05-06 11:11:04 +02:00
|
|
|
#include <zephyr/drivers/uart.h>
|
|
|
|
#include <zephyr/linker/sections.h>
|
|
|
|
#include <zephyr/arch/cpu.h>
|
2023-12-08 09:21:58 -05:00
|
|
|
#include <cortex_m/exception.h>
|
2019-04-24 16:52:51 +03:00
|
|
|
#include <fsl_power.h>
|
|
|
|
#include <fsl_clock.h>
|
|
|
|
#include <fsl_common.h>
|
|
|
|
#include <fsl_device_registers.h>
|
2021-11-30 13:55:40 -06:00
|
|
|
#ifdef CONFIG_GPIO_MCUX_LPC
|
2019-08-08 14:17:29 +03:00
|
|
|
#include <fsl_pint.h>
|
2021-11-30 13:55:40 -06:00
|
|
|
#endif
|
2024-09-02 22:09:54 +08:00
|
|
|
#if CONFIG_USB_DC_NXP_LPCIP3511 || CONFIG_UDC_NXP_IP3511 || CONFIG_UHC_NXP_IP3516HS
|
2021-07-22 14:41:21 -05:00
|
|
|
#include "usb_phy.h"
|
2022-08-18 19:14:27 -05:00
|
|
|
#include "usb.h"
|
2021-07-22 14:41:21 -05:00
|
|
|
#endif
|
2023-09-07 16:38:44 +08:00
|
|
|
#if defined(CONFIG_SOC_LPC55S36) && (defined(CONFIG_ADC_MCUX_LPADC) \
|
|
|
|
|| defined(CONFIG_DAC_MCUX_LPDAC))
|
2023-04-04 16:00:25 -05:00
|
|
|
#include <fsl_vref.h>
|
|
|
|
#endif
|
2019-04-24 16:52:51 +03:00
|
|
|
|
2023-01-11 17:40:46 -06:00
|
|
|
/* System clock frequency */
|
|
|
|
extern uint32_t SystemCoreClock;
|
|
|
|
|
|
|
|
/*Should be in the range of 12MHz to 32MHz */
|
|
|
|
static uint32_t ExternalClockFrequency;
|
|
|
|
|
|
|
|
|
2021-08-10 17:04:20 +01:00
|
|
|
#define CTIMER_CLOCK_SOURCE(node_id) \
|
|
|
|
TO_CTIMER_CLOCK_SOURCE(DT_CLOCKS_CELL(node_id, name), DT_PROP(node_id, clk_source))
|
|
|
|
#define TO_CTIMER_CLOCK_SOURCE(inst, val) TO_CLOCK_ATTACH_ID(inst, val)
|
|
|
|
#define TO_CLOCK_ATTACH_ID(inst, val) MUX_A(CM_CTIMERCLKSEL##inst, val)
|
|
|
|
#define CTIMER_CLOCK_SETUP(node_id) CLOCK_AttachClk(CTIMER_CLOCK_SOURCE(node_id));
|
|
|
|
|
2021-08-27 08:36:17 -05:00
|
|
|
#ifdef CONFIG_INIT_PLL0
|
|
|
|
const pll_setup_t pll0Setup = {
|
|
|
|
.pllctrl = SYSCON_PLL0CTRL_CLKEN_MASK | SYSCON_PLL0CTRL_SELI(2U) |
|
2023-01-11 17:40:46 -06:00
|
|
|
SYSCON_PLL0CTRL_SELP(31U),
|
2021-08-27 08:36:17 -05:00
|
|
|
.pllndec = SYSCON_PLL0NDEC_NDIV(125U),
|
|
|
|
.pllpdec = SYSCON_PLL0PDEC_PDIV(8U),
|
|
|
|
.pllsscg = {0x0U, (SYSCON_PLL0SSCG1_MDIV_EXT(3072U) | SYSCON_PLL0SSCG1_SEL_EXT_MASK)},
|
|
|
|
.pllRate = 24576000U,
|
2023-01-11 17:40:46 -06:00
|
|
|
.flags = PLL_SETUPFLAG_WAITLOCK
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_INIT_PLL1
|
|
|
|
const pll_setup_t pll1Setup = {
|
|
|
|
.pllctrl = SYSCON_PLL1CTRL_CLKEN_MASK | SYSCON_PLL1CTRL_SELI(53U) |
|
|
|
|
SYSCON_PLL1CTRL_SELP(31U),
|
|
|
|
.pllndec = SYSCON_PLL1NDEC_NDIV(8U),
|
|
|
|
.pllpdec = SYSCON_PLL1PDEC_PDIV(1U),
|
2023-07-26 09:49:41 +02:00
|
|
|
.pllmdec = SYSCON_PLL1MDEC_MDIV(144U),
|
|
|
|
.pllRate = 144000000U,
|
2023-01-11 17:40:46 -06:00
|
|
|
.flags = PLL_SETUPFLAG_WAITLOCK
|
|
|
|
};
|
2021-08-27 08:36:17 -05:00
|
|
|
#endif
|
|
|
|
|
2019-04-24 16:52:51 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Initialize the system clock
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2025-01-27 16:13:43 -06:00
|
|
|
__weak void clock_init(void)
|
2019-04-24 16:52:51 +03:00
|
|
|
{
|
2023-01-11 17:40:46 -06:00
|
|
|
ExternalClockFrequency = 0;
|
2022-11-21 09:26:37 -06:00
|
|
|
|
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
/* Power Management Controller initialization */
|
|
|
|
POWER_PowerInit();
|
|
|
|
#endif
|
|
|
|
|
2022-01-30 08:07:14 +05:30
|
|
|
#if defined(CONFIG_SOC_LPC55S06) || defined(CONFIG_SOC_LPC55S16) || \
|
2024-03-05 22:04:18 +01:00
|
|
|
defined(CONFIG_SOC_LPC55S26) || defined(CONFIG_SOC_LPC55S28) || \
|
|
|
|
defined(CONFIG_SOC_LPC55S36) || defined(CONFIG_SOC_LPC55S69_CPU0)
|
2023-01-11 17:40:46 -06:00
|
|
|
/* Set up the clock sources */
|
|
|
|
/* Configure FRO192M */
|
|
|
|
/* Ensure FRO is on */
|
2019-04-24 16:52:51 +03:00
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_FRO192M);
|
2023-01-11 17:40:46 -06:00
|
|
|
/* Set up FRO to the 12 MHz, to ensure we can change the clock freq */
|
2019-04-24 16:52:51 +03:00
|
|
|
CLOCK_SetupFROClocking(12000000U);
|
2023-01-11 17:40:46 -06:00
|
|
|
/* Switch to FRO 12MHz first to ensure we can change the clock */
|
2019-04-24 16:52:51 +03:00
|
|
|
CLOCK_AttachClk(kFRO12M_to_MAIN_CLK);
|
|
|
|
|
2023-01-11 17:40:46 -06:00
|
|
|
/* Ensure CLK_IN is on */
|
2021-08-27 08:36:17 -05:00
|
|
|
SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK;
|
|
|
|
ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK;
|
|
|
|
|
2023-07-26 09:49:41 +02:00
|
|
|
/* Setting the Core Clock to either 96MHz or in the case of using PLL, 144MHz */
|
2023-01-11 17:40:46 -06:00
|
|
|
#if defined(CONFIG_SOC_LPC55S06) || !defined(CONFIG_INIT_PLL1)
|
|
|
|
SystemCoreClock = 96000000U;
|
|
|
|
#else
|
2023-07-26 09:49:41 +02:00
|
|
|
SystemCoreClock = 144000000U;
|
2023-01-11 17:40:46 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* These functions must be called before increasing to a higher frequency
|
|
|
|
* Additionally, CONFIG_TRUSTED_EXECUTION_NONSECURE is being used
|
|
|
|
* since the non-secure SOCs should not have access to the flash
|
|
|
|
* as this will cause a secure fault to occur
|
|
|
|
*/
|
|
|
|
#if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE)
|
|
|
|
/* Set Voltage for one of the fastest clock outputs: System clock output */
|
|
|
|
POWER_SetVoltageForFreq(SystemCoreClock);
|
|
|
|
/*!< Set FLASH wait states for core */
|
|
|
|
CLOCK_SetFLASHAccessCyclesForFreq(SystemCoreClock);
|
|
|
|
#endif /* !CONFIG_TRUSTED_EXECUTION_NONSECURE */
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_INIT_PLL0) || defined(CONFIG_INIT_PLL1)
|
|
|
|
/* Configure XTAL32M */
|
|
|
|
ExternalClockFrequency = 16000000U;
|
|
|
|
CLOCK_SetupExtClocking(ExternalClockFrequency);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_SOC_LPC55S06) || !defined(CONFIG_INIT_PLL1)
|
|
|
|
/* Enable FRO HF(SystemCoreClock) output (Default expected value 96MHz) */
|
|
|
|
CLOCK_SetupFROClocking(SystemCoreClock);
|
|
|
|
|
|
|
|
/* Switch MAIN_CLK to FRO_HF */
|
|
|
|
CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK);
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* Switch PLL1 clock source selector to XTAL32M */
|
|
|
|
CLOCK_AttachClk(kEXT_CLK_to_PLL1);
|
|
|
|
|
|
|
|
/* Ensure PLL1 is on */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_PLL1);
|
|
|
|
|
|
|
|
/* Configure PLL to the desired values */
|
|
|
|
CLOCK_SetPLL1Freq(&pll1Setup);
|
|
|
|
|
|
|
|
/* Switch MAIN_CLK to FRO_HF */
|
|
|
|
CLOCK_AttachClk(kPLL1_to_MAIN_CLK);
|
|
|
|
|
|
|
|
#endif /* CONFIG_SOC_LPC55S06 || !CONFIG_INIT_PLL1 */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_INIT_PLL0
|
|
|
|
/* Switch PLL0 clock source selector to XTAL32M */
|
2021-08-27 08:36:17 -05:00
|
|
|
CLOCK_AttachClk(kEXT_CLK_to_PLL0);
|
|
|
|
|
2023-01-11 17:40:46 -06:00
|
|
|
/* Configure PLL to the desired values */
|
2021-08-27 08:36:17 -05:00
|
|
|
CLOCK_SetPLL0Freq(&pll0Setup);
|
|
|
|
|
2023-01-11 17:40:46 -06:00
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivPllClk, 0U, true);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivPllClk, 1U, false);
|
|
|
|
#else
|
2021-08-27 08:36:17 -05:00
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivPll0Clk, 0U, true);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivPll0Clk, 1U, false);
|
2023-01-11 17:40:46 -06:00
|
|
|
#endif /* CONFIG_SOC_LPC55S36 */
|
|
|
|
#endif /* CONFIG_INIT_PLL0 */
|
2021-08-27 08:36:17 -05:00
|
|
|
|
2019-04-24 16:52:51 +03:00
|
|
|
|
2023-01-11 17:40:46 -06:00
|
|
|
/* Set up dividers */
|
2019-04-24 16:52:51 +03:00
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false);
|
|
|
|
|
|
|
|
/* Enables the clock for the I/O controller.: Enable Clock. */
|
2023-01-11 17:40:46 -06:00
|
|
|
CLOCK_EnableClock(kCLOCK_Iocon);
|
2019-07-01 14:02:17 -05:00
|
|
|
|
2021-05-17 16:35:47 -05:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm2), nxp_lpc_usart, okay)
|
2022-07-28 11:38:13 +08:00
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivFlexcom2Clk, 0U, true);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivFlexcom2Clk, 1U, false);
|
|
|
|
#endif
|
2021-05-17 16:35:47 -05:00
|
|
|
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM2);
|
|
|
|
#endif
|
|
|
|
|
2024-11-07 09:08:56 +01:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm3), nxp_lpc_usart, okay)
|
|
|
|
CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM3);
|
|
|
|
#endif
|
|
|
|
|
2020-05-07 12:22:26 -05:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm4), nxp_lpc_i2c, okay)
|
2022-07-28 11:38:13 +08:00
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 0U, true);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1U, false);
|
|
|
|
#endif
|
2019-12-08 13:58:29 -06:00
|
|
|
/* attach 12 MHz clock to FLEXCOMM4 */
|
|
|
|
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4);
|
2020-05-05 06:42:12 -05:00
|
|
|
#endif
|
2019-12-08 13:58:29 -06:00
|
|
|
|
2024-11-07 09:08:56 +01:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm4), nxp_lpc_usart, okay)
|
|
|
|
CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM4);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm5), nxp_lpc_usart, okay)
|
|
|
|
CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM5);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm6), nxp_lpc_usart, okay)
|
|
|
|
CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM6);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm7), nxp_lpc_usart, okay)
|
|
|
|
CLOCK_AttachClk(kFRO_HF_DIV_to_FLEXCOMM7);
|
|
|
|
#endif
|
|
|
|
|
2024-09-20 12:47:40 +08:00
|
|
|
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(hs_lspi))
|
2020-05-05 06:42:12 -05:00
|
|
|
/* Attach 12 MHz clock to HSLSPI */
|
2020-05-04 19:28:08 +03:00
|
|
|
CLOCK_AttachClk(kFRO_HF_DIV_to_HSLSPI);
|
2020-05-05 06:42:12 -05:00
|
|
|
#endif
|
2019-07-01 14:02:17 -05:00
|
|
|
|
2020-07-09 17:56:21 +02:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(wwdt0), nxp_lpc_wwdt, okay)
|
|
|
|
/* Enable 1 MHz FRO clock for WWDT */
|
|
|
|
SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_FRO1MHZ_CLK_ENA_MASK;
|
|
|
|
#endif
|
|
|
|
|
2020-12-16 18:48:33 +02:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(mailbox0), nxp_lpc_mailbox, okay)
|
|
|
|
CLOCK_EnableClock(kCLOCK_Mailbox);
|
|
|
|
#endif
|
|
|
|
|
2024-05-27 15:43:27 +08:00
|
|
|
#if CONFIG_USB_DC_NXP_LPCIP3511 || CONFIG_UDC_NXP_IP3511
|
2023-05-19 10:34:39 -05:00
|
|
|
|
2023-10-16 16:55:09 -05:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(usbfs), nxp_lpcip3511, okay)
|
2023-05-19 10:34:39 -05:00
|
|
|
/*< Turn on USB Phy */
|
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_USBFSPHY);
|
|
|
|
#else
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY);
|
|
|
|
#endif
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1, false);
|
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
CLOCK_AttachClk(kFRO_HF_to_USB0);
|
|
|
|
#else
|
|
|
|
CLOCK_AttachClk(kFRO_HF_to_USB0_CLK);
|
|
|
|
#endif
|
|
|
|
/* enable usb0 host clock */
|
|
|
|
CLOCK_EnableClock(kCLOCK_Usbhsl0);
|
|
|
|
/*
|
2025-02-20 13:49:57 +01:00
|
|
|
* According to reference manual, device mode setting has to be set by access
|
2023-05-19 10:34:39 -05:00
|
|
|
* usb host register
|
|
|
|
*/
|
2024-09-13 10:51:57 +02:00
|
|
|
USBFSH->PORTMODE |= USBFSH_PORTMODE_DEV_ENABLE_MASK;
|
2023-05-19 10:34:39 -05:00
|
|
|
/* disable usb0 host clock */
|
|
|
|
CLOCK_DisableClock(kCLOCK_Usbhsl0);
|
|
|
|
|
|
|
|
/* enable USB IP clock */
|
|
|
|
CLOCK_EnableUsbfs0DeviceClock(kCLOCK_UsbfsSrcFro, CLOCK_GetFroHfFreq());
|
|
|
|
#if defined(FSL_FEATURE_USB_USB_RAM) && (FSL_FEATURE_USB_USB_RAM)
|
|
|
|
memset((uint8_t *)FSL_FEATURE_USB_USB_RAM_BASE_ADDRESS, 0, FSL_FEATURE_USB_USB_RAM);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* USB_DEVICE_TYPE_FS */
|
|
|
|
|
2023-10-16 16:55:09 -05:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(usbhs), nxp_lpcip3511, okay)
|
2021-07-22 14:41:21 -05:00
|
|
|
/* enable usb1 host clock */
|
|
|
|
CLOCK_EnableClock(kCLOCK_Usbh1);
|
|
|
|
/* Put PHY powerdown under software control */
|
2024-09-13 10:51:57 +02:00
|
|
|
USBHSH->PORTMODE = USBHSH_PORTMODE_SW_PDCOM_MASK;
|
2021-07-22 14:41:21 -05:00
|
|
|
/*
|
2022-03-10 12:33:04 +01:00
|
|
|
* According to reference manual, device mode setting has to be set by
|
2021-07-22 14:41:21 -05:00
|
|
|
* access usb host register
|
|
|
|
*/
|
2024-09-13 10:51:57 +02:00
|
|
|
USBHSH->PORTMODE |= USBHSH_PORTMODE_DEV_ENABLE_MASK;
|
2023-05-19 10:34:39 -05:00
|
|
|
/* disable usb1 host clock */
|
2021-07-22 14:41:21 -05:00
|
|
|
CLOCK_DisableClock(kCLOCK_Usbh1);
|
|
|
|
|
|
|
|
/* enable USB IP clock */
|
|
|
|
CLOCK_EnableUsbhs0PhyPllClock(kCLOCK_UsbPhySrcExt, CLK_CLK_IN);
|
|
|
|
CLOCK_EnableUsbhs0DeviceClock(kCLOCK_UsbSrcUnused, 0U);
|
2024-05-27 15:43:27 +08:00
|
|
|
#if CONFIG_USB_DC_NXP_LPCIP3511
|
2021-07-22 14:41:21 -05:00
|
|
|
USB_EhciPhyInit(kUSB_ControllerLpcIp3511Hs0, CLK_CLK_IN, NULL);
|
2024-05-27 15:43:27 +08:00
|
|
|
#endif
|
2021-07-22 14:41:21 -05:00
|
|
|
#if defined(FSL_FEATURE_USBHSD_USB_RAM) && (FSL_FEATURE_USBHSD_USB_RAM)
|
2023-05-19 10:34:39 -05:00
|
|
|
memset((uint8_t *)FSL_FEATURE_USBHSD_USB_RAM_BASE_ADDRESS, 0, FSL_FEATURE_USBHSD_USB_RAM);
|
2021-07-22 14:41:21 -05:00
|
|
|
#endif
|
|
|
|
|
2023-05-19 10:34:39 -05:00
|
|
|
#endif /* USB_DEVICE_TYPE_HS */
|
|
|
|
|
|
|
|
#endif /* CONFIG_USB_DC_NXP_LPCIP3511 */
|
2021-07-22 14:41:21 -05:00
|
|
|
|
2024-09-02 22:09:54 +08:00
|
|
|
#if CONFIG_UHC_NXP_OHCI
|
|
|
|
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(usbhfs), nxp_uhc_ohci, okay)
|
|
|
|
/* set BOD VBAT level to 1.65V */
|
|
|
|
POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
|
|
|
|
NVIC_ClearPendingIRQ(USB0_IRQn);
|
|
|
|
NVIC_ClearPendingIRQ(USB0_NEEDCLK_IRQn);
|
|
|
|
/*< Turn on USB Phy */
|
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_USBFSPHY);
|
|
|
|
#else
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY);
|
|
|
|
#endif
|
|
|
|
RESET_PeripheralReset(kUSB1H_RST_SHIFT_RSTn);
|
|
|
|
RESET_PeripheralReset(kUSB1D_RST_SHIFT_RSTn);
|
|
|
|
RESET_PeripheralReset(kUSB1_RST_SHIFT_RSTn);
|
|
|
|
RESET_PeripheralReset(kUSB1RAM_RST_SHIFT_RSTn);
|
|
|
|
CLOCK_EnableUsbfs0HostClock(kCLOCK_UsbfsSrcPll0, 48000000U);
|
|
|
|
#if defined(FSL_FEATURE_USBHSD_USB_RAM) && (FSL_FEATURE_USBHSD_USB_RAM)
|
|
|
|
memset((uint8_t *)FSL_FEATURE_USBHSD_USB_RAM_BASE_ADDRESS, 0, FSL_FEATURE_USBHSD_USB_RAM);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_UHC_NXP_IP3516HS
|
|
|
|
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(usbhhs), nxp_uhc_ip3516hs, okay)
|
|
|
|
/*< Turn on USB Phy */
|
|
|
|
#if !defined(CONFIG_SOC_LPC55S36)
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_USB1_PHY);
|
|
|
|
#endif
|
|
|
|
CLOCK_EnableUsbhs0PhyPllClock(kCLOCK_UsbPhySrcExt, CLK_CLK_IN);
|
|
|
|
CLOCK_EnableUsbhs0HostClock(kCLOCK_UsbSrcUnused, 0U);
|
|
|
|
USB_EhciPhyInit(kUSB_ControllerLpcIp3511Hs0, CLK_CLK_IN, NULL);
|
|
|
|
#if defined(FSL_FEATURE_USBHSD_USB_RAM) && (FSL_FEATURE_USBHSD_USB_RAM)
|
|
|
|
memset((uint8_t *)FSL_FEATURE_USBHSD_USB_RAM_BASE_ADDRESS, 0, FSL_FEATURE_USBHSD_USB_RAM);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-08-10 17:04:20 +01:00
|
|
|
DT_FOREACH_STATUS_OKAY(nxp_lpc_ctimer, CTIMER_CLOCK_SETUP)
|
|
|
|
|
2024-08-06 16:48:18 +02:00
|
|
|
DT_FOREACH_STATUS_OKAY(nxp_ctimer_pwm, CTIMER_CLOCK_SETUP)
|
|
|
|
|
2021-08-27 08:36:17 -05:00
|
|
|
#if (DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm6), nxp_lpc_i2s, okay))
|
2022-07-28 11:38:13 +08:00
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivFlexcom6Clk, 0U, true);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivFlexcom6Clk, 1U, false);
|
|
|
|
#endif
|
2021-08-27 08:36:17 -05:00
|
|
|
/* attach PLL0 clock to FLEXCOMM6 */
|
|
|
|
CLOCK_AttachClk(kPLL0_DIV_to_FLEXCOMM6);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm7), nxp_lpc_i2s, okay))
|
2022-07-28 11:38:13 +08:00
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivFlexcom7Clk, 0U, true);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivFlexcom7Clk, 1U, false);
|
|
|
|
#endif
|
|
|
|
/* attach PLL0 clock to FLEXCOMM7 */
|
2021-08-27 08:36:17 -05:00
|
|
|
CLOCK_AttachClk(kPLL0_DIV_to_FLEXCOMM7);
|
|
|
|
#endif
|
|
|
|
|
2021-05-31 22:22:11 +02:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(can0), nxp_lpc_mcan, okay)
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivCanClk, 1U, false);
|
|
|
|
CLOCK_AttachClk(kMCAN_DIV_to_MCAN);
|
|
|
|
#endif
|
|
|
|
|
2022-05-06 18:22:46 -05:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(sdif), nxp_lpc_sdif, okay) && \
|
|
|
|
CONFIG_MCUX_SDIF
|
|
|
|
/* attach main clock to SDIF */
|
|
|
|
CLOCK_AttachClk(kMAIN_CLK_to_SDIO_CLK);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivSdioClk, 3, true);
|
|
|
|
#endif
|
|
|
|
|
2019-04-24 16:52:51 +03:00
|
|
|
#endif /* CONFIG_SOC_LPC55S69_CPU0 */
|
2022-08-03 15:49:58 -05:00
|
|
|
|
|
|
|
#if defined(CONFIG_SOC_LPC55S36) && defined(CONFIG_PWM)
|
|
|
|
/* Set the Submodule Clocks for FlexPWM */
|
|
|
|
SYSCON->PWM0SUBCTL |=
|
2023-01-11 17:40:46 -06:00
|
|
|
(SYSCON_PWM0SUBCTL_CLK0_EN_MASK | SYSCON_PWM0SUBCTL_CLK1_EN_MASK |
|
|
|
|
SYSCON_PWM0SUBCTL_CLK2_EN_MASK);
|
2022-08-03 15:49:58 -05:00
|
|
|
SYSCON->PWM1SUBCTL |=
|
2023-01-11 17:40:46 -06:00
|
|
|
(SYSCON_PWM1SUBCTL_CLK0_EN_MASK | SYSCON_PWM1SUBCTL_CLK1_EN_MASK |
|
|
|
|
SYSCON_PWM1SUBCTL_CLK2_EN_MASK);
|
2022-08-03 15:49:58 -05:00
|
|
|
#endif
|
2023-04-04 16:00:25 -05:00
|
|
|
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(adc0), nxp_lpc_lpadc, okay)
|
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivAdc0Clk, 2U, true);
|
|
|
|
CLOCK_AttachClk(kFRO_HF_to_ADC0);
|
2023-04-12 15:19:44 +00:00
|
|
|
#else /* not LPC55s36 */
|
2023-09-07 16:38:44 +08:00
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivAdcAsyncClk,
|
|
|
|
DT_PROP(DT_NODELABEL(adc0), clk_divider), true);
|
|
|
|
CLOCK_AttachClk(MUX_A(CM_ADCASYNCCLKSEL, DT_PROP(DT_NODELABEL(adc0), clk_source)));
|
2023-04-04 16:00:25 -05:00
|
|
|
|
2023-09-07 16:38:44 +08:00
|
|
|
/* Power up the ADC */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_LDOGPADC);
|
2023-04-12 15:19:44 +00:00
|
|
|
#endif /* SOC platform */
|
|
|
|
#endif /* ADC */
|
|
|
|
|
|
|
|
#if (DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(vref0), nxp_vref, okay))
|
|
|
|
CLOCK_EnableClock(kCLOCK_Vref);
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_VREF);
|
|
|
|
#endif /* vref0 */
|
|
|
|
|
2023-09-07 16:38:44 +08:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(dac0), nxp_lpdac, okay)
|
|
|
|
#if defined(CONFIG_SOC_LPC55S36)
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivDac0Clk, 1U, true);
|
|
|
|
CLOCK_AttachClk(kMAIN_CLK_to_DAC0);
|
|
|
|
|
|
|
|
/* Disable DAC0 power down */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_DAC0);
|
2023-04-12 15:19:44 +00:00
|
|
|
#endif /* SOC platform */
|
|
|
|
#endif /* DAC */
|
2023-04-04 16:00:25 -05:00
|
|
|
|
2019-04-24 16:52:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Perform basic hardware initialization
|
|
|
|
*
|
|
|
|
* Initialize the interrupt controller device drivers.
|
|
|
|
* Also initialize the timer device driver, if required.
|
|
|
|
*
|
|
|
|
* @return 0
|
|
|
|
*/
|
|
|
|
|
init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:
- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices
They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:
```c
struct init_entry {
int (*init)(const struct device *dev);
/* only set by DEVICE_*, otherwise NULL */
const struct device *dev;
}
```
As a result, we end up with such weird/ugly pattern:
```c
static int my_init(const struct device *dev)
{
/* always NULL! add ARG_UNUSED to avoid compiler warning */
ARG_UNUSED(dev);
...
}
```
This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:
```c
static int my_init(void)
{
...
}
```
This is achieved using a union:
```c
union init_function {
/* for SYS_INIT, used when init_entry.dev == NULL */
int (*sys)(void);
/* for DEVICE*, used when init_entry.dev != NULL */
int (*dev)(const struct device *dev);
};
struct init_entry {
/* stores init function (either for SYS_INIT or DEVICE*)
union init_function init_fn;
/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
* to know which union entry to call.
*/
const struct device *dev;
}
```
This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.
**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
init: convert SYS_INIT functions to the new signature
Conversion scripted using scripts/utils/migrate_sys_init.py.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
manifest: update projects for SYS_INIT changes
Update modules with updated SYS_INIT calls:
- hal_ti
- lvgl
- sof
- TraceRecorderSource
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: devicetree: devices: adjust test
Adjust test according to the recently introduced SYS_INIT
infrastructure.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: kernel: threads: adjust SYS_INIT call
Adjust to the new signature: int (*init_fn)(void);
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-19 09:33:44 +02:00
|
|
|
static int nxp_lpc55xxx_init(void)
|
2019-04-24 16:52:51 +03:00
|
|
|
{
|
2019-09-30 12:31:07 -07:00
|
|
|
z_arm_clear_faults();
|
2019-04-24 16:52:51 +03:00
|
|
|
|
2019-10-09 14:52:07 +03:00
|
|
|
/* Initialize FRO/system clock to 96 MHz */
|
2019-09-30 12:31:07 -07:00
|
|
|
clock_init();
|
2019-04-24 16:52:51 +03:00
|
|
|
|
2019-08-08 14:17:29 +03:00
|
|
|
#ifdef CONFIG_GPIO_MCUX_LPC
|
|
|
|
/* Turn on PINT device*/
|
|
|
|
PINT_Init(PINT);
|
|
|
|
#endif
|
|
|
|
|
2019-04-24 16:52:51 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-08-06 09:17:48 -04:00
|
|
|
#ifdef CONFIG_SOC_RESET_HOOK
|
2022-11-30 16:06:40 -06:00
|
|
|
|
2024-08-06 09:17:48 -04:00
|
|
|
void soc_reset_hook(void)
|
2022-11-30 16:06:40 -06:00
|
|
|
{
|
|
|
|
SystemInit();
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONFIG_LOG_BACKEND_SWO
|
|
|
|
/*
|
|
|
|
* SystemInit unconditionally enables the trace clock.
|
|
|
|
* Disable the trace clock unless SWO is used
|
|
|
|
*/
|
2023-01-11 17:40:46 -06:00
|
|
|
SYSCON->TRACECLKDIV = 0x4000000;
|
2022-11-30 16:06:40 -06:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-08-06 09:17:48 -04:00
|
|
|
#endif /* CONFIG_SOC_RESET_HOOK */
|
2022-11-30 16:06:40 -06:00
|
|
|
|
2020-04-18 20:16:02 +02:00
|
|
|
SYS_INIT(nxp_lpc55xxx_init, PRE_KERNEL_1, 0);
|
2020-12-16 18:48:33 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_SECOND_CORE_MCUX) && defined(CONFIG_SOC_LPC55S69_CPU0)
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Second Core Init
|
|
|
|
*
|
|
|
|
* This routine boots the secondary core
|
2022-01-06 17:22:13 -08:00
|
|
|
*
|
|
|
|
* @retval 0 on success.
|
|
|
|
*
|
2020-12-16 18:48:33 +02:00
|
|
|
*/
|
|
|
|
/* This function is also called at deep sleep resume. */
|
init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:
- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices
They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:
```c
struct init_entry {
int (*init)(const struct device *dev);
/* only set by DEVICE_*, otherwise NULL */
const struct device *dev;
}
```
As a result, we end up with such weird/ugly pattern:
```c
static int my_init(const struct device *dev)
{
/* always NULL! add ARG_UNUSED to avoid compiler warning */
ARG_UNUSED(dev);
...
}
```
This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:
```c
static int my_init(void)
{
...
}
```
This is achieved using a union:
```c
union init_function {
/* for SYS_INIT, used when init_entry.dev == NULL */
int (*sys)(void);
/* for DEVICE*, used when init_entry.dev != NULL */
int (*dev)(const struct device *dev);
};
struct init_entry {
/* stores init function (either for SYS_INIT or DEVICE*)
union init_function init_fn;
/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
* to know which union entry to call.
*/
const struct device *dev;
}
```
This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.
**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
init: convert SYS_INIT functions to the new signature
Conversion scripted using scripts/utils/migrate_sys_init.py.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
manifest: update projects for SYS_INIT changes
Update modules with updated SYS_INIT calls:
- hal_ti
- lvgl
- sof
- TraceRecorderSource
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: devicetree: devices: adjust test
Adjust test according to the recently introduced SYS_INIT
infrastructure.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: kernel: threads: adjust SYS_INIT call
Adjust to the new signature: int (*init_fn)(void);
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-19 09:33:44 +02:00
|
|
|
int _second_core_init(void)
|
2020-12-16 18:48:33 +02:00
|
|
|
{
|
|
|
|
int32_t temp;
|
|
|
|
|
|
|
|
|
|
|
|
/* Setup the reset handler pointer (PC) and stack pointer value.
|
|
|
|
* This is used once the second core runs its startup code.
|
|
|
|
* The second core first boots from flash (address 0x00000000)
|
|
|
|
* and then detects its identity (Core no. 1, second) and checks
|
|
|
|
* registers CPBOOT and use them to continue the boot process.
|
2022-03-10 12:33:04 +01:00
|
|
|
* Make sure the startup code for the first core is
|
2020-12-16 18:48:33 +02:00
|
|
|
* appropriate and shareable with the second core!
|
|
|
|
*/
|
|
|
|
SYSCON->CPUCFG |= SYSCON_CPUCFG_CPU1ENABLE_MASK;
|
|
|
|
|
|
|
|
/* Boot source for Core 1 from flash */
|
|
|
|
SYSCON->CPBOOT = SYSCON_CPBOOT_CPBOOT(DT_REG_ADDR(
|
|
|
|
DT_CHOSEN(zephyr_code_cpu1_partition)));
|
|
|
|
|
|
|
|
temp = SYSCON->CPUCTRL;
|
|
|
|
temp |= 0xc0c48000;
|
|
|
|
SYSCON->CPUCTRL = temp | SYSCON_CPUCTRL_CPU1RSTEN_MASK |
|
|
|
|
SYSCON_CPUCTRL_CPU1CLKEN_MASK;
|
|
|
|
SYSCON->CPUCTRL = (temp | SYSCON_CPUCTRL_CPU1CLKEN_MASK) &
|
|
|
|
(~SYSCON_CPUCTRL_CPU1RSTEN_MASK);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_INIT(_second_core_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
|
|
|
|
|
|
|
|
#endif /*defined(CONFIG_SECOND_CORE_MCUX) && defined(CONFIG_SOC_LPC55S69_CPU0)*/
|