Skip to content

Commit 31f5007

Browse files
decsny57300
authored andcommitted
[nrf fromtree] soc: nxp: Add MCXW71
Add MCXW71 SOC, which inherits some qualitiies of kinetis heritage platforms. Signed-off-by: Declan Snyder <[email protected]> (cherry picked from commit cbee39e)
1 parent 2ef1d54 commit 31f5007

File tree

11 files changed

+333
-1
lines changed

11 files changed

+333
-1
lines changed

soc/nxp/mcx/mcxw/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2023 NXP
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
zephyr_sources(soc.c mcxw71_platform_init.S)
6+
7+
zephyr_include_directories(.)
8+
9+
set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld CACHE INTERNAL "")

soc/nxp/mcx/mcxw/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_SERIES_MCXW
5+
select ARM
6+
select CPU_CORTEX_M33
7+
select CPU_CORTEX_M_HAS_DWT
8+
select ARM_TRUSTZONE_M
9+
select CPU_CORTEX_M_HAS_SYSTICK
10+
select CPU_HAS_FPU
11+
select CPU_HAS_ARM_SAU
12+
select CPU_HAS_ARM_MPU
13+
select ARMV8_M_DSP
14+
select HAS_MCUX
15+
select PLATFORM_SPECIFIC_INIT
16+
select CLOCK_CONTROL

soc/nxp/mcx/mcxw/Kconfig.defconfig

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

soc/nxp/mcx/mcxw/Kconfig.soc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SOC_SERIES_MCXW
5+
bool
6+
select SOC_FAMILY_NXP_MCX
7+
8+
config SOC_SERIES
9+
default "mcxw" if SOC_SERIES_MCXW
10+
11+
config SOC_MCXW716C
12+
bool
13+
select SOC_SERIES_MCXW
14+
15+
config SOC
16+
default "mcxw716c" if SOC_MCXW716C
17+
18+
config SOC_PART_NUMBER_MCXW716CMFTA
19+
bool
20+
21+
config SOC_PART_NUMBER
22+
default "MCXW716CMFTA" if SOC_PART_NUMBER_MCXW716CMFTA

soc/nxp/mcx/mcxw/linker.ld

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2023 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/devicetree.h>
8+
9+
m_sector_size = 0x2000;
10+
m_flash_end = 0x000FFFFF;
11+
12+
13+
m_fsl_prodInfo_size = m_sector_size;
14+
m_fsl_prodInfo_start = m_flash_end - m_fsl_prodInfo_size + 1;
15+
m_fsl_prodInfo_end = m_flash_end;
16+
PROD_DATA_BASE_ADDR = m_fsl_prodInfo_start;
17+
18+
/*
19+
* We perform all custom placement before including the generic linker file. This
20+
* is done because calling this linker at the beginning will place some sections
21+
* first, such as .noinit*, and this includes the rpmsg_sh_mem, which results
22+
* in placing the rpmsg section in RAM instead of shared mem.
23+
*/
24+
25+
#include <zephyr/arch/arm/cortex_m/scripts/linker.ld>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2023 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief MCXW71 Platform-Specific Initialization
10+
*
11+
* MCXW71 SOC reset code that initializes RAM
12+
* to prevent ECC causing faults, and calls SystemInit
13+
*/
14+
15+
#include <zephyr/toolchain.h>
16+
#include <zephyr/linker/sections.h>
17+
18+
_ASM_FILE_PROLOGUE
19+
#ifdef CONFIG_PLATFORM_SPECIFIC_INIT
20+
21+
22+
GTEXT(z_arm_platform_init)
23+
SECTION_SUBSEC_FUNC(TEXT,_reset_section,z_arm_platform_init)
24+
25+
.z_arm_platform_init:
26+
ldr r0, =0x14000000
27+
ldr r1, =.ram_init_ctcm01
28+
bics r1, #0x10000000
29+
cmp r0, r1
30+
bcc .ram_init_done
31+
.ram_init_ctcm01: /* Initialize ctcm01 */
32+
ldr r0, =0x14000000
33+
ldr r1, =0x14004000
34+
ldr r2, =0
35+
ldr r3, =0
36+
ldr r4, =0
37+
ldr r5, =0
38+
.loop01:
39+
stmia r0!, {r2 - r5}
40+
cmp r0, r1
41+
bcc .loop01
42+
.ram_init_stcm012: /* Initialize stcm012 */
43+
ldr r0, =0x30000000
44+
ldr r1, =0x30010000
45+
.loop012:
46+
stmia r0!, {r2 - r5}
47+
cmp r0, r1
48+
bcc .loop012
49+
.ram_init_stcm5:
50+
ldr r0, =0x3001a000
51+
ldr r1, =0x3001c000
52+
.loop5: /* Initialize stcm5 */
53+
stmia r0!, {r2 - r5}
54+
cmp r0, r1
55+
bcc .loop5
56+
.ram_init_done:
57+
b SystemInit
58+
59+
#endif /* CONFIG_PLATFORM_SPECIFIC_INIT */

soc/nxp/mcx/mcxw/pinctrl_soc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/drivers/pinctrl/pinctrl_soc_kinetis_common.h>

soc/nxp/mcx/mcxw/soc.c

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* Copyright 2023 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/arch/cpu.h>
8+
#include <zephyr/device.h>
9+
#include <zephyr/init.h>
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/linker/sections.h>
12+
13+
#include <soc.h>
14+
15+
#include <fsl_ccm32k.h>
16+
#include <fsl_common.h>
17+
#include <fsl_clock.h>
18+
19+
extern uint32_t SystemCoreClock;
20+
21+
static ALWAYS_INLINE void clock_init(void)
22+
{
23+
/* Unlock Reference Clock Status Registers to allow writes */
24+
CLOCK_UnlockFircControlStatusReg();
25+
CLOCK_UnlockSircControlStatusReg();
26+
CLOCK_UnlockRoscControlStatusReg();
27+
CLOCK_UnlockSysOscControlStatusReg();
28+
29+
/*
30+
* Configuration for the 32 kHz Oscillator module
31+
* Internal capatitor bank is required in order to use the more stable OSC32K source
32+
*/
33+
ccm32k_osc_config_t ccm32k_osc_config = {
34+
.coarseAdjustment = kCCM32K_OscCoarseAdjustmentRange0, /* ESR_Range0 */
35+
.enableInternalCapBank = true, /* Internal capacitance bank is enabled */
36+
.xtalCap = kCCM32K_OscXtal8pFCap, /* 8 pF */
37+
.extalCap = kCCM32K_OscExtal8pFCap, /* 8 pF */
38+
};
39+
/* Enable OSC32K */
40+
CCM32K_Set32kOscConfig(CCM32K, kCCM32K_Enable32kHzCrystalOsc, &ccm32k_osc_config);
41+
/* Disable ROSC Monitor, because switching the source would generate an expected error */
42+
CLOCK_SetRoscMonitorMode(kSCG_RoscMonitorDisable);
43+
/* Select the Real Time Clock (RTC) source as OSC32K */
44+
CCM32K_SelectClockSource(CCM32K, kCCM32K_ClockSourceSelectOsc32k);
45+
/* Wait for RTC Oscillator to be Valid */
46+
while (!CLOCK_IsRoscValid())
47+
;
48+
/* Re-enable monitor */
49+
CLOCK_SetRoscMonitorMode(kSCG_RoscMonitorInt);
50+
/* Disable the FRO32K to save power */
51+
CCM32K_Enable32kFro(CCM32K, false);
52+
53+
/* Configuration to set FIRC to maximum frequency */
54+
scg_firc_config_t scg_firc_config = {
55+
.enableMode = kSCG_FircEnable, /* Fast IRC is enabled */
56+
.range = kSCG_FircRange96M, /* 96 Mhz FIRC clock selected */
57+
.trimConfig = NULL,
58+
};
59+
60+
scg_sys_clk_config_t sys_clk_safe_config_source = {
61+
.divSlow = (uint32_t)kSCG_SysClkDivBy4,
62+
.divCore = (uint32_t)kSCG_SysClkDivBy1,
63+
.src = (uint32_t)kSCG_SysClkSrcSirc,
64+
};
65+
66+
CLOCK_SetRunModeSysClkConfig(&sys_clk_safe_config_source);
67+
68+
scg_sys_clk_config_t cur_config;
69+
70+
do {
71+
CLOCK_GetCurSysClkConfig(&cur_config);
72+
} while (cur_config.src != sys_clk_safe_config_source.src);
73+
74+
(void)CLOCK_InitFirc(&scg_firc_config);
75+
76+
scg_sys_clk_config_t sys_clk_config = {
77+
.divSlow = (uint32_t)kSCG_SysClkDivBy4, /* Slow Clock Divider: divided by 4 */
78+
.divBus = (uint32_t)kSCG_SysClkDivBy1, /* Bus Clock Divider: divided by 1 */
79+
.divCore = (uint32_t)kSCG_SysClkDivBy1, /* Core Clock Divider: divided by 1 */
80+
.src = (uint32_t)kSCG_SysClkSrcFirc, /* Select Fast IRC as System Clock */
81+
};
82+
CLOCK_SetRunModeSysClkConfig(&sys_clk_config);
83+
84+
/* Wait for clock source switch to finish */
85+
do {
86+
CLOCK_GetCurSysClkConfig(&cur_config);
87+
} while (cur_config.src != sys_clk_config.src);
88+
89+
SystemCoreClock = 96000000U;
90+
91+
/* OSC-RF / System Oscillator Configuration */
92+
scg_sosc_config_t sosc_config = {
93+
.freq = 32000U,
94+
.monitorMode = kSCG_SysOscMonitorDisable,
95+
.enableMode = kSCG_SoscEnable,
96+
};
97+
98+
/* Init OSC-RF / SOSC */
99+
(void)CLOCK_InitSysOsc(&sosc_config);
100+
CLOCK_SetXtal0Freq(sosc_config.freq);
101+
102+
/* Slow internal reference clock (SIRC) configuration */
103+
scg_sirc_config_t sirc_config = {
104+
.enableMode = kSCG_SircDisableInSleep,
105+
};
106+
107+
/* Init SIRC */
108+
(void)CLOCK_InitSirc(&sirc_config);
109+
110+
/* Attach Clocks */
111+
CLOCK_SetIpSrc(kCLOCK_Lpuart0, kCLOCK_IpSrcFro192M);
112+
CLOCK_SetIpSrc(kCLOCK_Lpuart1, kCLOCK_IpSrcFro192M);
113+
CLOCK_SetIpSrc(kCLOCK_Lpspi0, kCLOCK_IpSrcFro192M);
114+
CLOCK_SetIpSrc(kCLOCK_Lpspi1, kCLOCK_IpSrcFro192M);
115+
CLOCK_SetIpSrc(kCLOCK_Can0, kCLOCK_IpSrcFro192M);
116+
CLOCK_SetIpSrc(kCLOCK_Tpm0, kCLOCK_IpSrcFro192M);
117+
CLOCK_SetIpSrc(kCLOCK_Tpm1, kCLOCK_IpSrcFro192M);
118+
CLOCK_SetIpSrc(kCLOCK_Lpi2c0, kCLOCK_IpSrcFro192M);
119+
CLOCK_SetIpSrcDiv(kCLOCK_Lpi2c0, kSCG_SysClkDivBy16);
120+
CLOCK_SetIpSrc(kCLOCK_Lpi2c1, kCLOCK_IpSrcFro192M);
121+
CLOCK_SetIpSrcDiv(kCLOCK_Lpi2c1, kSCG_SysClkDivBy16);
122+
123+
/* Ungate clocks if the peripheral is enabled in devicetree */
124+
#if (DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(lpuart0), nxp_lpc_lpuart, okay))
125+
CLOCK_EnableClock(kCLOCK_Lpuart0);
126+
#endif
127+
#if (DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(lpuart1), nxp_lpc_lpuart, okay))
128+
CLOCK_EnableClock(kCLOCK_Lpuart1);
129+
#endif
130+
}
131+
132+
static void vbat_init(void)
133+
{
134+
VBAT_Type *base = (VBAT_Type *)DT_REG_ADDR(DT_NODELABEL(vbat));
135+
136+
/* Write 1 to Clear POR detect status bit.
137+
*
138+
* Clearing this bit is acknowledement
139+
* that software has recognized a power on reset.
140+
*
141+
* This avoids also niche issues with NVIC read/write
142+
* when searching for available interrupt lines.
143+
*/
144+
base->STATUSA |= VBAT_STATUSA_POR_DET_MASK;
145+
};
146+
147+
static int nxp_mcxw71_init(void)
148+
{
149+
unsigned int oldLevel; /* old interrupt lock level */
150+
151+
/* disable interrupts */
152+
oldLevel = irq_lock();
153+
154+
/* Initialize system clock to 40 MHz */
155+
clock_init();
156+
157+
/* Smart power switch initialization */
158+
vbat_init();
159+
160+
/* restore interrupt state */
161+
irq_unlock(oldLevel);
162+
163+
return 0;
164+
}
165+
166+
SYS_INIT(nxp_mcxw71_init, PRE_KERNEL_1, 0);

soc/nxp/mcx/mcxw/soc.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright 2023 NXP
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef _SOC__H_
7+
#define _SOC__H_
8+
9+
#include <fsl_port.h>
10+
11+
#define PORT_MUX_GPIO kPORT_MuxAsGpio
12+
13+
#endif /* _SOC__H_ */

soc/nxp/mcx/soc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ family:
1717
- name: mcxa
1818
socs:
1919
- name: mcxa156
20+
- name: mcxw
21+
socs:
22+
- name: mcxw716c
2023
runners:
2124
run_once:
2225
'--erase':

0 commit comments

Comments
 (0)