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