Skip to content

Commit dd05205

Browse files
michal-smolanashif
authored andcommitted
soc: nxp mcxc: Add support for NXP MCXC series
Add initial suport for NXP MCXC series Signed-off-by: Michal Smola <[email protected]>
1 parent 4278766 commit dd05205

File tree

10 files changed

+377
-0
lines changed

10 files changed

+377
-0
lines changed

soc/nxp/mcx/mcxc/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
zephyr_sources_ifdef(CONFIG_MCXC_FLASH_CONFIG flash_configuration.c)
5+
6+
zephyr_include_directories(.)
7+
8+
zephyr_sources(soc.c)
9+
10+
set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "")
11+
12+
zephyr_linker_sources_ifdef(CONFIG_MCXC_FLASH_CONFIG
13+
ROM_START
14+
SORT_KEY ${CONFIG_MCXC_FLASH_CONFIG_OFFSET}
15+
flash_config.ld
16+
)
17+
18+
# CMSIS SystemInit will disable watchdog unless instructed not to.
19+
# Add a compiler definition here to leave watchdog untouched
20+
# if this Kconfig is set
21+
zephyr_compile_definitions_ifdef(CONFIG_WDOG_ENABLE_AT_BOOT DISABLE_WDOG=0)

soc/nxp/mcx/mcxc/Kconfig

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_SERIES_MCXC
5+
select ARM
6+
select CPU_CORTEX_M0PLUS
7+
select CPU_CORTEX_M_HAS_SYSTICK
8+
select CPU_CORTEX_M_HAS_VTOR
9+
select CLOCK_CONTROL
10+
select PLATFORM_SPECIFIC_INIT
11+
select HAS_MCUX
12+
select HAS_MCUX_ADC16
13+
select HAS_MCUX_SIM
14+
select HAS_MCUX_RCM
15+
select HAS_MCUX_FTFX
16+
select HAS_MCUX_LPUART
17+
select HAS_MCUX_LPI2C
18+
select HAS_MCUX_TPM
19+
20+
if SOC_SERIES_MCXC
21+
22+
config MCXC_FLASH_CONFIG
23+
bool "MCXC flash configuration field"
24+
default y if XIP && !BOOTLOADER_MCUBOOT
25+
help
26+
Include the 16-byte flash configuration field that stores default
27+
protection settings (loaded on reset) and security information that
28+
allows the MCU to restrict access to the FTFx module.
29+
30+
if MCXC_FLASH_CONFIG
31+
32+
config MCXC_FLASH_CONFIG_OFFSET
33+
hex
34+
default $(dt_node_int_prop_hex,/soc/flash-controller@40020000,config-field-offset)
35+
36+
endif # MCXC_FLASH_CONFIG
37+
38+
config WDOG_ENABLE_AT_BOOT
39+
bool "Keep watchdog timer enabled at boot"
40+
help
41+
Leave SOC watchdog timer enabled at boot. The specific timeout
42+
and clock configuration of the watchdog at boot is SOC dependent.
43+
Note: if the watchdog timer is enabled at boot, the user will
44+
need to configure the watchdog using z_arm_watchdog_init, as
45+
the SOC requires watchdog configuration before initial expiration
46+
47+
# Enable watchdog configuration function if watchdog is left enabled at boot
48+
config WDOG_INIT
49+
bool
50+
default WDOG_ENABLE_AT_BOOT
51+
52+
endif # SOC_FAMILY_MCXC

soc/nxp/mcx/mcxc/Kconfig.defconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if SOC_SERIES_MCXC
5+
6+
config NUM_IRQS
7+
default 32
8+
9+
config SYS_CLOCK_HW_CYCLES_PER_SEC
10+
default 48000000
11+
12+
endif # SOC_SERIES_MCXC

soc/nxp/mcx/mcxc/Kconfig.soc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_SERIES_MCXC
5+
bool
6+
select SOC_FAMILY_NXP_MCX
7+
8+
config SOC_SERIES
9+
default "mcxc" if SOC_SERIES_MCXC
10+
11+
config SOC_MCXC141
12+
bool
13+
select SOC_SERIES_MCXC
14+
15+
config SOC_MCXC142
16+
bool
17+
select SOC_SERIES_MCXC
18+
19+
config SOC_MCXC242
20+
bool
21+
select SOC_SERIES_MCXC
22+
23+
config SOC
24+
default "mcxc141" if SOC_MCXC141
25+
default "mcxc142" if SOC_MCXC142
26+
default "mcxc242" if SOC_MCXC242
27+
28+
config SOC_PART_NUMBER_MCXC141VLH
29+
bool
30+
31+
config SOC_PART_NUMBER_MCXC141VFM
32+
bool
33+
34+
config SOC_PART_NUMBER_MCXC142VFM
35+
bool
36+
37+
config SOC_PART_NUMBER_MCXC242VLH
38+
bool
39+
40+
config SOC_PART_NUMBER_MCXC242VFM
41+
bool
42+
43+
config SOC_PART_NUMBER
44+
default "MCXC141VFM" if SOC_PART_NUMBER_MCXC141VLH
45+
default "MCXC141VFM" if SOC_PART_NUMBER_MCXC141VFM
46+
default "MCXC141VFM" if SOC_PART_NUMBER_MCXC142VFM
47+
default "MCXC242VLH" if SOC_PART_NUMBER_MCXC242VLH
48+
default "MCXC242VFM" if SOC_PART_NUMBER_MCXC242VFM

soc/nxp/mcx/mcxc/flash_config.ld

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/devicetree.h>
8+
9+
10+
. = DT_PROP(DT_NODELABEL(ftfa), config_field_offset);
11+
KEEP(*(.kinetis_flash_config))
12+
KEEP(*(".kinetis_flash_config.*"))
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/linker/sections.h>
9+
#include <zephyr/device.h>
10+
11+
uint8_t __kinetis_flash_config_section __kinetis_flash_config[] = {
12+
/* Backdoor Comparison Key (unused) */
13+
0xFF,
14+
0xFF,
15+
0xFF,
16+
0xFF,
17+
0xFF,
18+
0xFF,
19+
0xFF,
20+
0xFF,
21+
22+
/* Program flash protection; 1 bit/region - 0=protected, 1=unprotected
23+
*/
24+
0xFF,
25+
0xFF,
26+
0xFF,
27+
0xFF,
28+
29+
/* Flash security register (FSEC) enables/disables backdoor key access,
30+
* mass erase, factory access, and flash security
31+
*/
32+
DT_PROP_OR(DT_NODELABEL(ftfa), fsec, 0xFF),
33+
34+
/* Flash nonvolatile option register (FOPT) enables/disables NMI,
35+
* EzPort, and boot options
36+
*/
37+
DT_PROP_OR(DT_NODELABEL(ftfa), fopt, 0xFF),
38+
39+
/* EEPROM protection register (FEPROT) for FlexNVM devices */
40+
0xFF,
41+
42+
/* Data flash protection register (FDPROT) for FlexNVM devices */
43+
0XFF,
44+
};

soc/nxp/mcx/mcxc/pinctrl_soc.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_SOC_ARM_NXP_MCXC_COMMON_PINCTRL_SOC_H_
8+
#define ZEPHYR_SOC_ARM_NXP_MCXC_COMMON_PINCTRL_SOC_H_
9+
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/types.h>
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
typedef uint32_t pinctrl_soc_pin_t;
18+
19+
/* MCXC series does not support open drain. Define macros to have no effect */
20+
#define PORT_PCR_ODE(x) 0x0
21+
#define PORT_PCR_ODE_MASK 0x0
22+
23+
#define Z_PINCTRL_MCXC_PINCFG(node_id) \
24+
(PORT_PCR_DSE(DT_ENUM_IDX(node_id, drive_strength)) | \
25+
PORT_PCR_PS(DT_PROP(node_id, bias_pull_up)) | \
26+
PORT_PCR_PE(DT_PROP(node_id, bias_pull_up)) | \
27+
PORT_PCR_PE(DT_PROP(node_id, bias_pull_down)) | \
28+
PORT_PCR_ODE(DT_PROP(node_id, drive_open_drain)) | \
29+
PORT_PCR_SRE(DT_ENUM_IDX(node_id, slew_rate)) | \
30+
PORT_PCR_PFE(DT_PROP(node_id, nxp_passive_filter)))
31+
32+
#define Z_PINCTRL_KINETIS_PCR_MASK \
33+
(PORT_PCR_MUX_MASK | PORT_PCR_DSE_MASK | PORT_PCR_ODE_MASK | \
34+
PORT_PCR_PFE_MASK | PORT_PCR_SRE_MASK | PORT_PCR_PE_MASK | \
35+
PORT_PCR_PS_MASK)
36+
37+
38+
#define Z_PINCTRL_STATE_PIN_INIT(group, pin_prop, idx) \
39+
DT_PROP_BY_IDX(group, pin_prop, idx) | Z_PINCTRL_MCXC_PINCFG(group),
40+
41+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
42+
{DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), \
43+
DT_FOREACH_PROP_ELEM, pinmux, Z_PINCTRL_STATE_PIN_INIT)};
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
49+
#endif /* ZEPHYR_SOC_ARM_NXP_MCXC_COMMON_PINCTRL_SOC_H_ */

soc/nxp/mcx/mcxc/soc.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/device.h>
9+
#include <zephyr/init.h>
10+
#include <soc.h>
11+
#include <fsl_common.h>
12+
#include <fsl_clock.h>
13+
#include <zephyr/arch/cpu.h>
14+
15+
/*******************************************************************************
16+
* Definitions
17+
******************************************************************************/
18+
#define MCG_NODE DT_NODELABEL(mcg)
19+
#define OSC_NODE DT_NODELABEL(osc)
20+
21+
#define SIM_LPUART_CLK_SEL_DISABLED 0U /*!< LPUART clock select: Disabled */
22+
#define SIM_LPUART_CLK_SEL_IRC48M_CLK 1U /*!< LPUART clock select: IRC48M clock */
23+
#define SIM_LPUART_CLK_SEL_OSCERCLK_CLK 2U /*!< LPUART clock select: OSCERCLK clock */
24+
#define SIM_LPUART_CLK_SEL_MCGIRCLK_CLK 3U /*!< LPUART clock select: MCGIRCLK clock */
25+
26+
#define CLOCK_NODEID(clk) DT_CHILD(DT_INST(0, nxp_kinetis_sim), clk)
27+
28+
#define CLOCK_DIVIDER(clk) DT_PROP_OR(CLOCK_NODEID(clk), clock_div, 1) - 1
29+
30+
#define LPUART_CLOCK_SEL(label) \
31+
(DT_PHA(DT_NODELABEL(label), clocks, name) == kCLOCK_McgIrc48MClk \
32+
? SIM_LPUART_CLK_SEL_IRC48M_CLK \
33+
: DT_PHA(DT_NODELABEL(label), clocks, name) == kCLOCK_Osc0ErClk \
34+
? SIM_LPUART_CLK_SEL_OSCERCLK_CLK \
35+
: DT_PHA(DT_NODELABEL(label), clocks, name) == kCLOCK_McgInternalRefClk \
36+
? SIM_LPUART_CLK_SEL_MCGIRCLK_CLK \
37+
: SIM_LPUART_CLK_SEL_DISABLED)
38+
39+
/*******************************************************************************
40+
* Variables
41+
******************************************************************************/
42+
43+
const mcglite_config_t mcgliteConfig_BOARD_BootClockRUN = {
44+
.outSrc = kMCGLITE_ClkSrcHirc, /* MCGOUTCLK source is HIRC */
45+
.irclkEnableMode = kMCGLITE_IrclkEnable, /* MCGIRCLK enabled */
46+
.ircs = kMCGLITE_Lirc8M, /* Slow internal reference (LIRC) 8 MHz clock */
47+
/* Low-frequency Reference Clock Divider */
48+
.fcrdiv = DT_PROP_OR(MCG_NODE, fcrdiv, 0),
49+
/* Second Low-frequency Reference Clock Divider */
50+
.lircDiv2 = DT_PROP_OR(MCG_NODE, lircdiv2, 0),
51+
.hircEnableInNotHircMode = true, /* HIRC source is enabled */
52+
};
53+
54+
const sim_clock_config_t simConfig_BOARD_BootClockRUN = {
55+
.er32kSrc = DT_PROP(DT_INST(0, nxp_kinetis_sim), er32k_select),
56+
.clkdiv1 = SIM_CLKDIV1_OUTDIV1(CLOCK_DIVIDER(core_clk)) |
57+
SIM_CLKDIV1_OUTDIV4(CLOCK_DIVIDER(flash_clk)),
58+
};
59+
60+
const osc_config_t oscConfig_BOARD_BootClockRUN = {
61+
.freq = DT_PROP(OSC_NODE, clock_frequency),
62+
.capLoad = 0,
63+
#if DT_ENUM_HAS_VALUE(OSC_NODE, mode, external)
64+
.workMode = kOSC_ModeExt,
65+
#elif DT_ENUM_HAS_VALUE(OSC_NODE, mode, low_power)
66+
.workMode = kOSC_ModeOscLowPower,
67+
#elif DT_ENUM_HAS_VALUE(OSC_NODE, mode, high_gain)
68+
.workMode = kOSC_ModeOscHighGain,
69+
#else
70+
#error "An oscillator mode must be defined"
71+
#endif
72+
.oscerConfig = {
73+
.enableMode = kOSC_ErClkEnable,
74+
}
75+
};
76+
77+
static void clock_init(void)
78+
{
79+
/* Set the system clock dividers in SIM to safe value. */
80+
CLOCK_SetSimSafeDivs();
81+
/* Initializes OSC0 according to board configuration. */
82+
CLOCK_InitOsc0(&oscConfig_BOARD_BootClockRUN);
83+
CLOCK_SetXtal0Freq(oscConfig_BOARD_BootClockRUN.freq);
84+
/* Set MCG to HIRC mode. */
85+
CLOCK_SetMcgliteConfig(&mcgliteConfig_BOARD_BootClockRUN);
86+
/* Set the clock configuration in SIM module. */
87+
CLOCK_SetSimConfig(&simConfig_BOARD_BootClockRUN);
88+
/* Set SystemCoreClock variable. */
89+
SystemCoreClock = DT_PROP(DT_NODELABEL(cpu0), clock_frequency);
90+
/* Set LPUART0 clock source. */
91+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(lpuart0), okay)
92+
CLOCK_SetLpuart0Clock(LPUART_CLOCK_SEL(lpuart0));
93+
#endif
94+
}
95+
96+
static int mcxc_init(void)
97+
{
98+
clock_init();
99+
return 0;
100+
}
101+
102+
#ifdef CONFIG_PLATFORM_SPECIFIC_INIT
103+
104+
void z_arm_platform_init(void)
105+
{
106+
SystemInit();
107+
}
108+
109+
#endif /* CONFIG_PLATFORM_SPECIFIC_INIT */
110+
111+
SYS_INIT(mcxc_init, PRE_KERNEL_1, 0);

soc/nxp/mcx/mcxc/soc.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef _SOC__H_
8+
#define _SOC__H_
9+
10+
#include <zephyr/sys/util.h>
11+
#include <fsl_port.h>
12+
13+
#define UART0_CLK_SRC kCLOCK_CoreSysClk
14+
15+
#define PORT_MUX_GPIO kPORT_MuxAsGpio /* GPIO setting for the Port Mux Register */
16+
17+
#ifndef _ASMLANGUAGE
18+
19+
#include <fsl_common.h>
20+
21+
#endif /* !_ASMLANGUAGE */
22+
23+
#endif /* _SOC__H_ */

soc/nxp/mcx/soc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ family:
88
- name: cpu0
99
- name: cpu1
1010
- name: mcxn236
11+
- name: mcxc
12+
socs:
13+
- name: mcxc141
14+
- name: mcxc142
15+
- name: mcxc242
1116
runners:
1217
run_once:
1318
'--erase':

0 commit comments

Comments
 (0)