2019-04-24 16:52:51 +03:00
|
|
|
/*
|
2023-04-04 16:00:25 -05:00
|
|
|
* Copyright 2017, 2019-2023 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>
|
2019-11-09 17:49:36 +00:00
|
|
|
#include <aarch32/cortex_m/exc.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
|
2021-07-22 14:41:21 -05:00
|
|
|
#if CONFIG_USB_DC_NXP_LPCIP3511
|
|
|
|
#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-04-04 16:00:25 -05:00
|
|
|
#if defined(CONFIG_SOC_LPC55S36) && defined(CONFIG_ADC_MCUX_LPADC)
|
|
|
|
#include <fsl_vref.h>
|
|
|
|
#endif
|
2019-04-24 16:52:51 +03:00
|
|
|
|
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) |
|
|
|
|
SYSCON_PLL0CTRL_SELP(31U),
|
|
|
|
.pllndec = SYSCON_PLL0NDEC_NDIV(125U),
|
|
|
|
.pllpdec = SYSCON_PLL0PDEC_PDIV(8U),
|
|
|
|
.pllsscg = {0x0U, (SYSCON_PLL0SSCG1_MDIV_EXT(3072U) | SYSCON_PLL0SSCG1_SEL_EXT_MASK)},
|
|
|
|
.pllRate = 24576000U,
|
|
|
|
.flags = PLL_SETUPFLAG_WAITLOCK}
|
|
|
|
;
|
|
|
|
#endif
|
|
|
|
|
2019-04-24 16:52:51 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Initialize the system clock
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-09-30 12:31:07 -07:00
|
|
|
static ALWAYS_INLINE void clock_init(void)
|
2019-04-24 16:52:51 +03:00
|
|
|
{
|
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) || \
|
2022-07-28 11:38:13 +08:00
|
|
|
defined(CONFIG_SOC_LPC55S28) || defined(CONFIG_SOC_LPC55S36) || \
|
|
|
|
defined(CONFIG_SOC_LPC55S69_CPU0)
|
2019-04-24 16:52:51 +03:00
|
|
|
/*!< Set up the clock sources */
|
|
|
|
/*!< Configure FRO192M */
|
|
|
|
/*!< Ensure FRO is on */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_FRO192M);
|
|
|
|
/*!< Set up FRO to the 12 MHz, just for sure */
|
|
|
|
CLOCK_SetupFROClocking(12000000U);
|
|
|
|
/*!< Switch to FRO 12MHz first to ensure we can change the clock */
|
|
|
|
CLOCK_AttachClk(kFRO12M_to_MAIN_CLK);
|
|
|
|
|
|
|
|
/* Enable FRO HF(96MHz) output */
|
|
|
|
CLOCK_SetupFROClocking(96000000U);
|
|
|
|
|
2021-08-27 08:36:17 -05:00
|
|
|
#ifdef CONFIG_INIT_PLL0
|
|
|
|
/*!< Ensure XTAL16M is on */
|
|
|
|
PMC->PDRUNCFGCLR0 |= PMC_PDRUNCFG0_PDEN_XTAL32M_MASK;
|
|
|
|
PMC->PDRUNCFGCLR0 |= PMC_PDRUNCFG0_PDEN_LDOXO32M_MASK;
|
|
|
|
|
|
|
|
/*!< Ensure CLK_IN is on */
|
|
|
|
SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK;
|
|
|
|
ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK;
|
|
|
|
|
|
|
|
/*!< Switch PLL0 clock source selector to XTAL16M */
|
|
|
|
CLOCK_AttachClk(kEXT_CLK_to_PLL0);
|
|
|
|
|
|
|
|
/*!< Configure PLL to the desired values */
|
|
|
|
CLOCK_SetPLL0Freq(&pll0Setup);
|
|
|
|
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivPll0Clk, 0U, true);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivPll0Clk, 1U, false);
|
|
|
|
#endif
|
|
|
|
|
2021-05-27 09:17:43 -05:00
|
|
|
#if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE)
|
2019-04-24 16:52:51 +03:00
|
|
|
/*!< Set FLASH wait states for core */
|
|
|
|
CLOCK_SetFLASHAccessCyclesForFreq(96000000U);
|
2021-05-25 12:58:31 +02:00
|
|
|
#endif
|
2019-04-24 16:52:51 +03:00
|
|
|
|
|
|
|
/*!< Set up dividers */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false);
|
|
|
|
|
|
|
|
/*!< Set up clock selectors - Attach clocks to the peripheries */
|
|
|
|
CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK);
|
|
|
|
|
|
|
|
/* Enables the clock for the I/O controller.: Enable Clock. */
|
|
|
|
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
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/* reset FLEXCOMM for I2C */
|
|
|
|
RESET_PeripheralReset(kFC4_RST_SHIFT_RSTn);
|
2020-05-05 06:42:12 -05:00
|
|
|
#endif
|
2019-12-08 13:58:29 -06:00
|
|
|
|
2020-05-11 11:56:08 -07:00
|
|
|
#if DT_NODE_HAS_STATUS(DT_NODELABEL(hs_lspi), okay)
|
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);
|
2019-07-01 14:02:17 -05:00
|
|
|
|
2020-05-05 06:42:12 -05:00
|
|
|
/* reset HSLSPI for SPI */
|
2019-07-01 14:02:17 -05:00
|
|
|
RESET_PeripheralReset(kHSLSPI_RST_SHIFT_RSTn);
|
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);
|
|
|
|
/* Reset the MAILBOX module */
|
|
|
|
RESET_PeripheralReset(kMAILBOX_RST_SHIFT_RSTn);
|
|
|
|
#endif
|
|
|
|
|
2021-07-22 14:41:21 -05:00
|
|
|
#if CONFIG_USB_DC_NXP_LPCIP3511
|
2023-05-19 10:34:39 -05:00
|
|
|
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(usbfs), nxp_mcux_usbd, okay)
|
|
|
|
/*< 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);
|
|
|
|
/*
|
|
|
|
* According to reference mannual, device mode setting has to be set by access
|
|
|
|
* usb host register
|
|
|
|
*/
|
|
|
|
*((uint32_t *)(USBFSH_BASE + 0x5C)) |= USBFSH_PORTMODE_DEV_ENABLE_MASK;
|
|
|
|
/* 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 */
|
|
|
|
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(usbhs), nxp_mcux_usbd, okay)
|
2021-07-22 14:41:21 -05:00
|
|
|
/* enable usb1 host clock */
|
|
|
|
CLOCK_EnableClock(kCLOCK_Usbh1);
|
|
|
|
/* Put PHY powerdown under software control */
|
|
|
|
*((uint32_t *)(USBHSH_BASE + 0x50)) = USBHSH_PORTMODE_SW_PDCOM_MASK;
|
|
|
|
/*
|
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
|
|
|
|
*/
|
|
|
|
*((uint32_t *)(USBHSH_BASE + 0x50)) |= 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);
|
|
|
|
USB_EhciPhyInit(kUSB_ControllerLpcIp3511Hs0, CLK_CLK_IN, NULL);
|
|
|
|
#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
|
|
|
|
2021-08-10 17:04:20 +01:00
|
|
|
DT_FOREACH_STATUS_OKAY(nxp_lpc_ctimer, 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);
|
|
|
|
RESET_PeripheralReset(kMCAN_RST_SHIFT_RSTn);
|
|
|
|
#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 |=
|
|
|
|
(SYSCON_PWM0SUBCTL_CLK0_EN_MASK | SYSCON_PWM0SUBCTL_CLK1_EN_MASK |
|
|
|
|
SYSCON_PWM0SUBCTL_CLK2_EN_MASK);
|
|
|
|
SYSCON->PWM1SUBCTL |=
|
|
|
|
(SYSCON_PWM1SUBCTL_CLK0_EN_MASK | SYSCON_PWM1SUBCTL_CLK1_EN_MASK |
|
|
|
|
SYSCON_PWM1SUBCTL_CLK2_EN_MASK);
|
|
|
|
#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);
|
|
|
|
|
|
|
|
#if defined(CONFIG_ADC_MCUX_LPADC)
|
|
|
|
/* Vref is required for LPADC reference */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_VREF);
|
|
|
|
|
|
|
|
vref_config_t vrefConfig;
|
|
|
|
|
|
|
|
VREF_GetDefaultConfig(&vrefConfig);
|
|
|
|
vrefConfig.bufferMode = kVREF_ModeHighPowerBuffer;
|
|
|
|
vrefConfig.enableInternalVoltageRegulator = true;
|
|
|
|
vrefConfig.enableVrefOut = true;
|
|
|
|
VREF_Init((VREF_Type *)VREF_BASE, &vrefConfig);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
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)));
|
|
|
|
|
|
|
|
/* Power up the ADC */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_LDOGPADC);
|
|
|
|
#endif
|
|
|
|
#endif
|
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;
|
|
|
|
}
|
|
|
|
|
2022-11-30 16:06:40 -06:00
|
|
|
#ifdef CONFIG_PLATFORM_SPECIFIC_INIT
|
|
|
|
|
|
|
|
void z_arm_platform_init(void)
|
|
|
|
{
|
|
|
|
SystemInit();
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONFIG_LOG_BACKEND_SWO
|
|
|
|
/*
|
|
|
|
* SystemInit unconditionally enables the trace clock.
|
|
|
|
* Disable the trace clock unless SWO is used
|
|
|
|
*/
|
|
|
|
SYSCON->TRACECLKDIV = 0x4000000;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_PLATFORM_SPECIFIC_INIT */
|
|
|
|
|
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)*/
|