Skip to content

Commit a8f5958

Browse files
lucien-nxpnashif
authored andcommitted
soc: nxp: imxrt: imxrt118x: add flexspi support
add flexspi.c file to get flexspi clock rate. Enable flexspi1 clock if don't boot from flash. Use custom fixed mpu_regions.c file to config MPU for CM7 Signed-off-by: Lucien Zhao <[email protected]>
1 parent 1f5a1b5 commit a8f5958

File tree

6 files changed

+108
-0
lines changed

6 files changed

+108
-0
lines changed

soc/nxp/imxrt/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ if(CONFIG_SOC_SERIES_IMXRT10XX OR CONFIG_SOC_SERIES_IMXRT11XX)
3939
endif()
4040

4141
if(CONFIG_SOC_SERIES_IMXRT118X)
42+
if(CONFIG_SOC_MIMXRT1189_CM7)
43+
zephyr_sources(mpu_regions.c)
44+
endif()
4245
if(CONFIG_EXTERNAL_MEM_CONFIG_DATA)
4346
set(boot_hdr_xmcd_data_section ".boot_hdr.xmcd_data")
4447
endif()

soc/nxp/imxrt/imxrt118x/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@ endif()
1313

1414
zephyr_include_directories(.)
1515

16+
if(CONFIG_MEMC_MCUX_FLEXSPI)
17+
zephyr_sources(flexspi.c)
18+
if(CONFIG_FLASH_MCUX_FLEXSPI_XIP)
19+
zephyr_code_relocate(FILES flexspi.c LOCATION ${CONFIG_FLASH_MCUX_FLEXSPI_XIP_MEM}_TEXT)
20+
endif()
21+
endif()
22+
1623
set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld CACHE INTERNAL "")

soc/nxp/imxrt/imxrt118x/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
config SOC_SERIES_IMXRT118X
5+
select CPU_HAS_CUSTOM_FIXED_SOC_MPU_REGIONS if SOC_MIMXRT1189_CM7
56
select CPU_CORTEX_M_HAS_DWT
67
select SOC_RESET_HOOK
78
select INIT_ARCH_HW_AT_BOOT if SOC_MIMXRT1189_CM33

soc/nxp/imxrt/imxrt118x/flexspi.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <fsl_clock.h>
8+
#include <fsl_flexspi.h>
9+
#include <soc.h>
10+
#include <errno.h>
11+
#include <zephyr/irq.h>
12+
#include <zephyr/dt-bindings/clock/imx_ccm_rev2.h>
13+
14+
uint32_t flexspi_clock_set_freq(uint32_t clock_name, uint32_t rate)
15+
{
16+
clock_name_t root;
17+
uint32_t root_rate;
18+
FLEXSPI_Type *flexspi;
19+
clock_root_t flexspi_clk;
20+
clock_ip_name_t clk_gate;
21+
uint32_t divider;
22+
23+
switch (clock_name) {
24+
case IMX_CCM_FLEXSPI_CLK:
25+
flexspi_clk = kCLOCK_Root_Flexspi1;
26+
flexspi = (FLEXSPI_Type *)DT_REG_ADDR(DT_NODELABEL(flexspi));
27+
clk_gate = kCLOCK_Flexspi1;
28+
break;
29+
case IMX_CCM_FLEXSPI2_CLK:
30+
flexspi_clk = kCLOCK_Root_Flexspi2;
31+
flexspi = (FLEXSPI_Type *)DT_REG_ADDR(DT_NODELABEL(flexspi2));
32+
clk_gate = kCLOCK_Flexspi2;
33+
break;
34+
default:
35+
return -ENOTSUP;
36+
}
37+
root = CLOCK_GetRootClockSource(flexspi_clk,
38+
CLOCK_GetRootClockMux(flexspi_clk));
39+
/* Get clock root frequency */
40+
root_rate = CLOCK_GetFreq(root);
41+
/* Select a divider based on root clock frequency. We round the
42+
* divider up, so that the resulting clock frequency is lower than
43+
* requested when we can't output the exact requested frequency
44+
*/
45+
divider = ((root_rate + (rate - 1)) / rate);
46+
/* Cap divider to max value */
47+
divider = MIN(divider, CCM_CLOCK_ROOT_CONTROL_DIV_MASK);
48+
49+
while (FLEXSPI_GetBusIdleStatus(flexspi) == false) {
50+
/* Spin */
51+
}
52+
FLEXSPI_Enable(flexspi, false);
53+
54+
CLOCK_DisableClock(clk_gate);
55+
56+
CLOCK_SetRootClockDiv(flexspi_clk, divider);
57+
58+
CLOCK_EnableClock(clk_gate);
59+
60+
FLEXSPI_Enable(flexspi, true);
61+
62+
FLEXSPI_SoftwareReset(flexspi);
63+
64+
return 0;
65+
}

soc/nxp/imxrt/imxrt118x/soc.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ const clock_sys_pll2_config_t sysPll2Config_BOARD_BootClockRUN = {
7676
.ssEnable = false,
7777
};
7878

79+
/* Function Name : board_flexspi_clock_safe_config
80+
* Description : FLEXSPI clock source safe configuration weak function.
81+
* Called before clock source configuration.
82+
* Note : Users need override this function to change FLEXSPI clock source to stable
83+
* source when executing code on FLEXSPI memory(XIP). If XIP, the function
84+
* should runs in RAM and move the FLEXSPI clock source to a stable clock
85+
* to avoid instruction/data fetch issue during clock updating.
86+
*/
87+
__attribute__((weak)) void board_flexspi_clock_safe_config(void)
88+
{
89+
}
90+
7991
/**
8092
* @brief Initialize the system clock
8193
*/
@@ -123,6 +135,12 @@ static ALWAYS_INLINE void clock_init(void)
123135
(ANADIG_OSC->OSC_24M_CTRL & ANADIG_OSC_OSC_24M_CTRL_OSC_24M_STABLE_MASK)) {
124136
}
125137

138+
/* Call function board_flexspi_clock_safe_config() to move FlexSPI clock to a stable
139+
* clock source to avoid instruction/data fetch issue when updating PLL if XIP
140+
* (execute code on FLEXSPI memory).
141+
*/
142+
board_flexspi_clock_safe_config();
143+
126144
#ifdef CONFIG_INIT_ARM_PLL
127145
/* Init Arm Pll. */
128146
CLOCK_InitArmPll(&armPllConfig_BOARD_BootClockRUN);
@@ -391,6 +409,14 @@ static ALWAYS_INLINE void clock_init(void)
391409

392410
#endif /* CONFIG_MCUX_LPTMR_TIMER || CONFIG_COUNTER_MCUX_LPTMR */
393411

412+
#if !(DT_NODE_HAS_COMPAT(DT_PARENT(DT_CHOSEN(zephyr_flash)), nxp_imx_flexspi_nor)) && \
413+
defined(CONFIG_MEMC_MCUX_FLEXSPI) && DT_NODE_HAS_STATUS(DT_NODELABEL(flexspi), okay)
414+
/* Configure FLEXSPI1 using SYS_PLL3_PFD0_CLK */
415+
rootCfg.mux = kCLOCK_FLEXSPI1_ClockRoot_MuxSysPll3Pfd0;
416+
rootCfg.div = 3;
417+
CLOCK_SetRootClock(kCLOCK_Root_Flexspi1, &rootCfg);
418+
#endif
419+
394420
/* Keep core clock ungated during WFI */
395421
CCM->LPCG[1].LPM0 = 0x33333333;
396422
CCM->LPCG[1].LPM1 = 0x33333333;
@@ -511,8 +537,10 @@ void soc_early_init_hook(void)
511537

512538
/* Enable data cache */
513539
#if defined(CONFIG_IMXRT118X_CM33_XCACHE_PS)
540+
XCACHE_EnableCache(XCACHE_PC);
514541
XCACHE_EnableCache(XCACHE_PS);
515542
#elif defined(CONFIG_SOC_MIMXRT1189_CM7)
543+
sys_cache_instr_enable();
516544
sys_cache_data_enable();
517545
#endif
518546
__ISB();

soc/nxp/imxrt/imxrt118x/soc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
extern "C" {
2121
#endif
2222

23+
#ifdef CONFIG_MEMC_MCUX_FLEXSPI
24+
uint32_t flexspi_clock_set_freq(uint32_t clock_name, uint32_t rate);
25+
#endif
26+
2327
#ifdef __cplusplus
2428
}
2529
#endif

0 commit comments

Comments
 (0)