2017-07-26 04:40:18 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017, NXP
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief System/hardware module for nxp_lpc54114 platform
|
|
|
|
*
|
|
|
|
* This module provides routines to initialize and support board-level
|
|
|
|
* hardware for the nxp_lpc54114 platform.
|
|
|
|
*/
|
|
|
|
|
2022-05-06 11:11:04 +02:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/device.h>
|
|
|
|
#include <zephyr/init.h>
|
2017-07-26 04:40:18 -05:00
|
|
|
#include <soc.h>
|
2022-05-06 11:11:04 +02:00
|
|
|
#include <zephyr/drivers/uart.h>
|
|
|
|
#include <zephyr/linker/sections.h>
|
2023-07-04 14:21:40 +08:00
|
|
|
#include <zephyr/arch/cpu.h>
|
2023-12-08 09:21:58 -05:00
|
|
|
#include <cortex_m/exception.h>
|
2018-02-26 16:23:40 -06:00
|
|
|
#include <fsl_power.h>
|
2017-07-26 04:40:18 -05:00
|
|
|
#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
|
2022-08-04 10:22:38 -05:00
|
|
|
#if defined(CONFIG_SECOND_CORE_MCUX) && defined(CONFIG_SOC_LPC54114_M4)
|
|
|
|
#include <zephyr_image_info.h>
|
|
|
|
/* Memcpy macro to copy segments from secondary core image stored in flash
|
|
|
|
* to RAM section that secondary core boots from.
|
|
|
|
* n is the segment number, as defined in zephyr_image_info.h
|
|
|
|
*/
|
|
|
|
#define MEMCPY_SEGMENT(n, _) \
|
|
|
|
memcpy((uint32_t *)((SEGMENT_LMA_ADDRESS_ ## n) - ADJUSTED_LMA), \
|
|
|
|
(uint32_t *)(SEGMENT_LMA_ADDRESS_ ## n), \
|
|
|
|
(SEGMENT_SIZE_ ## n))
|
|
|
|
#endif
|
2017-07-26 04:40:18 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Initialize the system clock
|
|
|
|
*
|
|
|
|
*/
|
2020-04-24 14:41:23 -05:00
|
|
|
#define CPU_FREQ DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency)
|
2017-07-26 04:40:18 -05:00
|
|
|
|
2019-09-30 12:31:07 -07:00
|
|
|
static ALWAYS_INLINE void clock_init(void)
|
2017-07-26 04:40:18 -05:00
|
|
|
{
|
2018-05-15 18:51:17 -05:00
|
|
|
|
|
|
|
#ifdef CONFIG_SOC_LPC54114_M4
|
2017-07-26 04:40:18 -05:00
|
|
|
/* Set up the clock sources */
|
|
|
|
|
|
|
|
/* Ensure FRO is on */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_FRO_EN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch to FRO 12MHz first to ensure we can change voltage without
|
|
|
|
* accidentally being below the voltage for current speed.
|
|
|
|
*/
|
|
|
|
CLOCK_AttachClk(kFRO12M_to_MAIN_CLK);
|
|
|
|
|
|
|
|
/* Set FLASH wait states for core */
|
2020-04-24 14:41:23 -05:00
|
|
|
CLOCK_SetFLASHAccessCyclesForFreq(CPU_FREQ);
|
2017-07-26 04:40:18 -05:00
|
|
|
|
|
|
|
/* Set up high frequency FRO output to selected frequency */
|
2020-04-24 14:41:23 -05:00
|
|
|
CLOCK_SetupFROClocking(CPU_FREQ);
|
2017-07-26 04:40:18 -05:00
|
|
|
|
|
|
|
/* Set up dividers */
|
|
|
|
/* Set AHBCLKDIV divider to value 1 */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false);
|
|
|
|
|
|
|
|
/* Set up clock selectors - Attach clocks to the peripheries */
|
|
|
|
/* Switch MAIN_CLK to FRO_HF */
|
|
|
|
CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK);
|
|
|
|
|
|
|
|
/* Attach 12 MHz clock to FLEXCOMM0 */
|
|
|
|
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0);
|
2019-07-03 14:49:36 -05:00
|
|
|
|
2020-05-07 12:22:26 -05:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm4), nxp_lpc_i2c, okay)
|
2019-12-08 14:38:02 -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 14:38:02 -06:00
|
|
|
|
2020-05-07 12:22:26 -05:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm5), nxp_lpc_spi, okay)
|
2019-07-03 14:49:36 -05:00
|
|
|
/* Attach 12 MHz clock to FLEXCOMM5 */
|
2020-05-04 19:28:08 +03:00
|
|
|
CLOCK_AttachClk(kFRO_HF_to_FLEXCOMM5);
|
2019-07-03 14:49:36 -05:00
|
|
|
|
|
|
|
/* reset FLEXCOMM for SPI */
|
|
|
|
RESET_PeripheralReset(kFC5_RST_SHIFT_RSTn);
|
2020-05-05 06:42:12 -05:00
|
|
|
#endif
|
2019-07-03 14:49:36 -05:00
|
|
|
|
2018-05-15 18:51:17 -05:00
|
|
|
#endif /* CONFIG_SOC_LPC54114_M4 */
|
2017-07-26 04:40:18 -05: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_lpc54114_init(void)
|
2017-07-26 04:40:18 -05:00
|
|
|
{
|
|
|
|
/* Initialize FRO/system clock to 48 MHz */
|
2019-09-30 12:31:07 -07:00
|
|
|
clock_init();
|
2017-07-26 04:40:18 -05:00
|
|
|
|
2019-08-08 14:17:29 +03:00
|
|
|
#ifdef CONFIG_GPIO_MCUX_LPC
|
|
|
|
/* Turn on PINT device*/
|
|
|
|
PINT_Init(PINT);
|
|
|
|
#endif
|
|
|
|
|
2017-07-26 04:40:18 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_INIT(nxp_lpc54114_init, PRE_KERNEL_1, 0);
|
2018-05-15 18:52:23 -05:00
|
|
|
|
2022-11-30 16:06:40 -06:00
|
|
|
#if defined(CONFIG_PLATFORM_SPECIFIC_INIT) && defined(CONFIG_SOC_LPC54114_M0)
|
|
|
|
|
|
|
|
/* M4 core has a custom platform initialization routine in assembly,
|
|
|
|
* but M0 core does not. install one here to call SystemInit.
|
|
|
|
*/
|
|
|
|
void z_arm_platform_init(void)
|
|
|
|
{
|
|
|
|
SystemInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_PLATFORM_SPECIFIC_INIT */
|
|
|
|
|
2018-05-15 18:52:23 -05:00
|
|
|
|
2022-08-04 10:22:38 -05:00
|
|
|
#if defined(CONFIG_SECOND_CORE_MCUX) && defined(CONFIG_SOC_LPC54114_M4)
|
2018-05-15 18:52:23 -05:00
|
|
|
|
2020-12-16 18:54:03 +02:00
|
|
|
#define CORE_M0_BOOT_ADDRESS ((void *)CONFIG_SECOND_CORE_BOOT_ADDRESS_MCUX)
|
2018-05-15 18:52:23 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Slave Init
|
|
|
|
*
|
|
|
|
* This routine boots the secondary core
|
2022-01-06 17:22:13 -08:00
|
|
|
*
|
|
|
|
* @retval 0 on success.
|
|
|
|
*
|
2018-05-15 18:52:23 -05: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 _slave_init(void)
|
2018-05-15 18:52:23 -05:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
int32_t temp;
|
2018-05-15 18:52:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
/* Enable SRAM2, used by other core */
|
|
|
|
SYSCON->AHBCLKCTRLSET[0] = SYSCON_AHBCLKCTRL_SRAM2_MASK;
|
|
|
|
|
|
|
|
/* Copy second core image to SRAM */
|
2022-08-04 10:22:38 -05:00
|
|
|
LISTIFY(SEGMENT_NUM, MEMCPY_SEGMENT, (;));
|
2018-05-15 18:52:23 -05:00
|
|
|
|
|
|
|
/* 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 (Cortex-M0, slave) and checks
|
|
|
|
* registers CPBOOT and CPSTACK and use them to continue the
|
|
|
|
* boot process.
|
2022-03-10 12:33:04 +01:00
|
|
|
* Make sure the startup code for the current core (Cortex-M4) is
|
2018-05-15 18:52:23 -05:00
|
|
|
* appropriate and shareable with the Cortex-M0 core!
|
|
|
|
*/
|
|
|
|
SYSCON->CPBOOT = SYSCON_CPBOOT_BOOTADDR(
|
|
|
|
*(uint32_t *)((uint8_t *)CORE_M0_BOOT_ADDRESS + 0x4));
|
|
|
|
SYSCON->CPSTACK = SYSCON_CPSTACK_STACKADDR(
|
|
|
|
*(uint32_t *)CORE_M0_BOOT_ADDRESS);
|
|
|
|
|
|
|
|
/* Reset the secondary core and start its clocks */
|
2018-12-19 15:22:00 -06:00
|
|
|
temp = SYSCON->CPUCTRL;
|
2018-05-15 18:52:23 -05:00
|
|
|
temp |= 0xc0c48000;
|
2018-12-19 15:22:00 -06:00
|
|
|
SYSCON->CPUCTRL = (temp | SYSCON_CPUCTRL_CM0CLKEN_MASK
|
|
|
|
| SYSCON_CPUCTRL_CM0RSTEN_MASK);
|
|
|
|
SYSCON->CPUCTRL = (temp | SYSCON_CPUCTRL_CM0CLKEN_MASK)
|
|
|
|
& (~SYSCON_CPUCTRL_CM0RSTEN_MASK);
|
2018-05-15 18:52:23 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_INIT(_slave_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
|
|
|
|
|
2022-08-04 10:22:38 -05:00
|
|
|
#endif /*CONFIG_SECOND_CORE_MCUX && CONFIG_SOC_LPC54114_M4 */
|