1# Copyright 2022-2024 NXP
2
3# Set the SoC specific drivers and configuration to build
4if(HWMv2)
5  set(SOC_BASE ${CONFIG_SOC})
6else()
7  if(${CONFIG_SOC} STREQUAL "s32z27")
8    set(SOC_BASE "s32z270")
9  else()
10    set(SOC_BASE ${CONFIG_SOC})
11  endif()
12endif()
13
14add_subdirectory(drivers/${SOC_SERIES})
15add_subdirectory(soc/${SOC_BASE})
16
17if(CONFIG_HAS_MCUX)
18
19  # This is an adaptation from hal_nxp/mcux/CMakeLists.txt entry CMake in order
20  # to build MCUX drivers together with RTD drivers for NXP S32 devices.
21  # MCUX don't have official support for NXP S32 devices but we are leveraging
22  # the existing shim drivers in Zephyr for those hardware blocks which are
23  # present in both NXP S32 and non NXP S32 devices.
24  #
25  # Glue code must be added for each device supported to build with MCUX. This
26  # can be found in hal_nxp/s32/mcux/devices:
27  # - s32/mcux/devices/${MCUX_DEVICE}/${MCUX_DEVICE}_device.h
28  #   redefine RTD module's peripheral access layers and its register masks to be
29  #   compatible with MCUX drivers for incompatible peripherals
30  # - s32/mcux/devices/${MCUX_DEVICE}/${MCUX_DEVICE}_features.h
31  #   define SoC module's features
32  # - s32/mcux/devices/${MCUX_DEVICE}/${MCUX_DEVICE}_glue_mcux.h
33  #   redefine RTD module's base addresses/pointers/interrupts to be compatible
34  #   with MCUX drivers
35  # - s32/mcux/devices/${MCUX_DEVICE}/fsl_device_registers.h
36  #   expose device features to the MCUX drivers
37  # - s32/mcux/devices/${MCUX_DEVICE}/drivers/fsl_clock.h
38  #   required by mcux/mcux-sdk/drivers/common/fsl_common_arm.h (at least)
39  # - s32/mcux/devices/${MCUX_DEVICE}/drivers/driver_reset.cmake
40  #   required by mcux/mcux-sdk/drivers/common/drivers_common.cmake
41  # - s32/mcux/devices/${MCUX_DEVICE}/device_system.cmake
42  #   required by mcux/hal_nxp.cmake
43  # - s32/mcux/devices/${MCUX_DEVICE}/device_CMSIS.cmake
44  #   required by mcux/mcux-sdk/drivers/common/drivers_common.cmake for non DSP
45  #   architectures
46
47  function(include_mcux_driver_ifdef feature_toggle directory module)
48    if(${${feature_toggle}})
49      list(APPEND CMAKE_MODULE_PATH
50          ${CMAKE_CURRENT_LIST_DIR}/../mcux/mcux-sdk/drivers/${directory}
51      )
52      zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/../mcux/mcux-sdk/drivers/${directory})
53      include(${module})
54    endif()
55  endfunction()
56
57  set(MCUX_SDK_PROJECT_NAME ${ZEPHYR_CURRENT_LIBRARY})
58
59  # Translate the SoC name into the MCUX device
60  string(TOUPPER ${SOC_BASE} MCUX_DEVICE)
61
62  # This is normally done in mcux/hal_nxp.cmake, but we need to point to the
63  # path on this directory instead
64  list(APPEND CMAKE_MODULE_PATH
65    ${CMAKE_CURRENT_LIST_DIR}/mcux/devices/${MCUX_DEVICE}
66    ${CMAKE_CURRENT_LIST_DIR}/mcux/devices/${MCUX_DEVICE}/drivers
67  )
68
69  # MCUX uses the CPU name to expose SoC-specific features of a given peripheral
70  zephyr_compile_definitions(CPU_${MCUX_DEVICE})
71
72  # Clock control is supported through RTD, so disable it in the MCUX drivers
73  zephyr_compile_definitions(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL=1)
74
75  zephyr_include_directories(mcux/devices/${MCUX_DEVICE})
76  zephyr_include_directories(mcux/devices/${MCUX_DEVICE}/drivers)
77
78  zephyr_linker_sources(RWDATA
79    ${CMAKE_CURRENT_LIST_DIR}/../mcux/quick_access_data.ld
80  )
81  zephyr_linker_sources_ifdef(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
82    RAMFUNC_SECTION
83    ${CMAKE_CURRENT_LIST_DIR}/../mcux/quick_access_code.ld
84  )
85  zephyr_linker_sources_ifdef(CONFIG_NOCACHE_MEMORY
86    NOCACHE_SECTION
87    ${CMAKE_CURRENT_LIST_DIR}/../mcux/nocache.ld
88  )
89
90  # Entry CMake component for MCUX
91  include(${CMAKE_CURRENT_LIST_DIR}/../mcux/hal_nxp.cmake)
92
93  if(${MCUX_DEVICE} MATCHES "S32K1")
94    zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/../mcux/mcux-sdk/drivers/port)
95    include_mcux_driver_ifdef(CONFIG_PINCTRL port driver_port)
96
97    zephyr_include_directories(${CMAKE_CURRENT_LIST_DIR}/../mcux/mcux-sdk/drivers/sysmpu)
98    include_mcux_driver_ifdef(CONFIG_ARM_MPU sysmpu driver_sysmpu)
99
100    include_mcux_driver_ifdef(CONFIG_HAS_MCUX_CACHE cache/lmem driver_cache_lmem)
101  endif()
102
103endif()
104