1# Copyright 2025 NXP 2# 3# SPDX-License-Identifier: Apache-2.0 4 5string(TOUPPER ${CONFIG_SOC} MCUX_DEVICE) 6 7# Find the folder in mcux-sdk/devices that matches the device name 8message(STATUS "Looking for device ${MCUX_DEVICE} in ${SdkRootDirPath}/devices/") 9 10file(GLOB_RECURSE device_cmake_files ${SdkRootDirPath}/devices/*/CMakeLists.txt) 11foreach(file ${device_cmake_files}) 12 get_filename_component(folder ${file} DIRECTORY) 13 get_filename_component(folder_name ${folder} NAME) 14 if(folder_name STREQUAL ${MCUX_DEVICE}) 15 message(STATUS "Found device folder: ${folder}") 16 set(mcux_device_folder ${folder}) 17 break() 18 endif() 19endforeach() 20 21if(NOT mcux_device_folder) 22 message(FATAL_ERROR "Device ${MCUX_DEVICE} not found in ${SdkRootDirPath}/devices/") 23endif() 24 25# Note: Difference between `core_id` and `core_id_suffix_name` in MCUX SDK NG. 26# 27# MCUX SDK NG uses `core_id` to distinguish which core currently is running on. 28# 29# In most of the time, `core_id` and `core_id_suffix_name` are the same, but 30# there are some exceptions, for example: RT595 FUSIONF1. 31# `core_id` is used for the core's folder name in device folder, like: 32# "mcux-sdk-ng/devices/RT/RT500/MIMXRT595S/fusionf1", here `core_id` is fusionf1. 33# `core_id_suffix_name` is used for the device files and macro suffix, such as: 34# file "system_MIMXRT595S_dsp.h", macro `CPU_MIMXRT595SFAWC_dsp`, here 35# `core_id_suffix_name` is dsp. 36# 37# MCUX SDK NG needs `core_id` as input, it defines `core_id_suffix_name` based on 38# `core_id` in file "mcux-sdk-ng/devices/RT/RT500/MIMXRT595S/<core_id>". 39# 40# Zephyr provides `MCUX_CORE_SUFFIX` to distinguish the core, it is actaully the 41# `core_id_suffix_name` in MCUX SDK NG, here convert it to `core_id`, then pass 42# it to MCUX SDK NG. 43if(DEFINED CONFIG_MCUX_CORE_SUFFIX) 44 if (CONFIG_SOC_MIMXRT595S_F1) 45 set(core_id "fusionf1") 46 elseif (CONFIG_SOC_MIMXRT685S_HIFI4) 47 set(core_id "hifi4") 48 else() 49 string (REGEX REPLACE "^_" "" core_id "${CONFIG_MCUX_CORE_SUFFIX}") 50 endif() 51endif() 52 53if(CONFIG_SOC_SERIES_IMXRT10XX OR CONFIG_SOC_SERIES_IMXRT11XX) 54 set(CONFIG_MCUX_COMPONENT_device.boot_header ON) 55endif() 56 57if(NOT CONFIG_SOC_MIMX94398_M33) 58 set(CONFIG_MCUX_COMPONENT_device.system ON) 59endif() 60set(CONFIG_MCUX_COMPONENT_device.CMSIS ON) 61if(NOT CONFIG_CLOCK_CONTROL_ARM_SCMI) 62 set(CONFIG_MCUX_COMPONENT_driver.clock ON) 63endif() 64 65# Exclude fsl_power.c for DSP domains 66if((CONFIG_ARM) AND (NOT CONFIG_CLOCK_CONTROL_ARM_SCMI)) 67 set(CONFIG_MCUX_COMPONENT_driver.power ON) 68endif() 69 70if(NOT CONFIG_CPU_CORTEX_A) 71 set(CONFIG_MCUX_COMPONENT_driver.reset ON) 72 set(CONFIG_MCUX_COMPONENT_driver.memory ON) 73endif() 74 75# Include fsl_dsp.c for ARM domains (applicable to i.MX RTxxx devices) 76if(CONFIG_ARM) 77 set(CONFIG_MCUX_COMPONENT_driver.dsp ON) 78endif() 79 80# load device variables 81include(${mcux_device_folder}/variable.cmake) 82 83# Define CPU macro, like: CPU_MIMXRT595SFAWC_dsp. 84# Variable `core_id_suffix_name` is from file ${mcux_device_folder}/variable.cmake 85zephyr_compile_definitions("CPU_${CONFIG_SOC_PART_NUMBER}${core_id_suffix_name}") 86 87# Definitions to load device drivers, like: CPU_MIMXRT595SFAWC_dsp. 88set(CONFIG_MCUX_HW_DEVICE_CORE "${MCUX_DEVICE}${core_id_suffix_name}") 89 90# Necessary values to load right SDK NG cmake files 91# CONFIG_MCUX_HW_CORE 92# CONFIG_MCUX_HW_FPU_TYPE 93# 94# They are used by the files like: 95# zephyr/modules/hal/nxp/mcux/mcux-sdk-ng/devices/arm/shared.cmake 96# zephyr/modules/hal/nxp/mcux/mcux-sdk-ng/devices/xtensa/shared.cmake 97if (CONFIG_CPU_CORTEX_M0PLUS) 98 set(CONFIG_MCUX_HW_CORE cm0p) 99elseif (CONFIG_CPU_CORTEX_M3) 100 set(CONFIG_MCUX_HW_CORE cm3) 101elseif (CONFIG_CPU_CORTEX_M33) 102 set(CONFIG_MCUX_HW_CORE cm33) 103elseif (CONFIG_CPU_CORTEX_M4) 104 if (CONFIG_CPU_HAS_FPU) 105 set(CONFIG_MCUX_HW_CORE cm4f) 106 else() 107 set(CONFIG_MCUX_HW_CORE cm4) 108 endif() 109elseif (CONFIG_CPU_CORTEX_M7) 110 set(CONFIG_MCUX_HW_CORE cm7f) 111elseif (CONFIG_XTENSA) 112 set(CONFIG_MCUX_HW_CORE dsp) 113endif() 114 115if (CONFIG_CPU_HAS_FPU) 116 if (CONFIG_CPU_CORTEX_M33 OR CONFIG_CPU_CORTEX_M7) 117 if (CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION) 118 set(CONFIG_MCUX_HW_FPU_TYPE fpv5_dp) 119 else() 120 set(CONFIG_MCUX_HW_FPU_TYPE fpv5_sp) 121 endif() 122 elseif (CONFIG_CPU_CORTEX_M4) 123 set(CONFIG_MCUX_HW_FPU_TYPE fpv4_sp) 124 endif() 125else() 126 set(CONFIG_MCUX_HW_FPU_TYPE no_fpu) 127endif() 128 129# Load device files 130mcux_add_cmakelists(${mcux_device_folder}) 131 132# Workaround for fsl_flexspi_nor_boot link error, remove the one in SDK, use the Zephyr file. 133if(CONFIG_MCUX_COMPONENT_device.boot_header) 134 135 get_target_property(MCUXSDK_SOURCES ${MCUX_SDK_PROJECT_NAME} SOURCES) 136 list(FILTER MCUXSDK_SOURCES INCLUDE REGEX ".*fsl_flexspi_nor_boot\.c$") 137 138 if(NOT MCUXSDK_SOURCES STREQUAL "") 139 file(RELATIVE_PATH MCUXSDK_SOURCES ${SdkRootDirPath} ${MCUXSDK_SOURCES}) 140 mcux_project_remove_source( 141 BASE_PATH ${SdkRootDirPath} 142 SOURCES ${MCUXSDK_SOURCES} 143 ) 144 endif() 145 146endif() 147