1# Copyright (c) 2021 Nordic Semiconductor ASA
2# SPDX-License-Identifier: Apache-2.0
3
4zephyr_library()
5
6# The nrfx source directory can be override through the definition of the NRFX_DIR symbol
7# during the invocation of the build system
8if(NOT DEFINED NRFX_DIR)
9  set(NRFX_DIR ${ZEPHYR_CURRENT_MODULE_DIR}/nrfx CACHE PATH "nrfx Directory")
10endif()
11
12set(INC_DIR ${NRFX_DIR}/drivers/include)
13set(SRC_DIR ${NRFX_DIR}/drivers/src)
14set(MDK_DIR ${NRFX_DIR}/mdk)
15set(HELPERS_DIR ${NRFX_DIR}/helpers)
16
17zephyr_include_directories(${NRFX_DIR})
18zephyr_include_directories(${INC_DIR})
19zephyr_include_directories(${MDK_DIR})
20zephyr_include_directories(.)
21
22# Define MDK defines globally
23zephyr_compile_definitions_ifdef(CONFIG_SOC_SERIES_NRF51X       NRF51)
24zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF51822_QFAA       NRF51422_XXAA)
25zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF51822_QFAB       NRF51422_XXAB)
26zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF51822_QFAC       NRF51422_XXAC)
27zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF52805            NRF52805_XXAA)
28zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF52810            NRF52810_XXAA)
29zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF52811            NRF52811_XXAA)
30zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF52820            NRF52820_XXAA)
31zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF52832            NRF52832_XXAA)
32zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF52833            NRF52833_XXAA)
33zephyr_compile_definitions_ifdef(CONFIG_SOC_COMPATIBLE_NRF52833 NRF52833_XXAA)
34zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF52840            NRF52840_XXAA)
35zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF5340_CPUAPP      NRF5340_XXAA_APPLICATION)
36zephyr_compile_definitions_ifdef(CONFIG_SOC_COMPATIBLE_NRF5340_CPUAPP NRF5340_XXAA_APPLICATION)
37zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF5340_CPUNET      NRF5340_XXAA_NETWORK)
38zephyr_compile_definitions_ifdef(CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET NRF5340_XXAA_NETWORK)
39zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54H20_CPUAPP     NRF54H20_XXAA
40                                                                NRF_APPLICATION)
41zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54H20_CPURAD     NRF54H20_XXAA
42                                                                NRF_RADIOCORE)
43zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54H20_CPUPPR     NRF54H20_XXAA
44                                                                NRF_PPR)
45zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54H20_CPUFLPR    NRF54H20_XXAA
46                                                                NRF_FLPR)
47zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L05            NRF54L05_XXAA
48                                                                DEVELOP_IN_NRF54L15)
49zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L05_CPUAPP     NRF_APPLICATION)
50zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L05_CPUFLPR    NRF_FLPR)
51zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L09_ENGA       NRF54LV10A_ENGA_XXAA)
52zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L09_ENGA_CPUAPP NRF_APPLICATION)
53zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L10            NRF54L10_XXAA
54                                                                DEVELOP_IN_NRF54L15)
55zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L10_CPUAPP     NRF_APPLICATION)
56zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L10_CPUFLPR    NRF_FLPR)
57zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L15            NRF54L15_XXAA)
58zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L15_CPUAPP     NRF_APPLICATION)
59zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L15_CPUFLPR    NRF_FLPR)
60zephyr_compile_definitions_ifdef(CONFIG_SOC_COMPATIBLE_NRF54L15 NRF54L15_XXAA)
61zephyr_compile_definitions_ifdef(CONFIG_SOC_COMPATIBLE_NRF54L15_CPUAPP NRF_APPLICATION)
62zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L20_ENGA       NRF54LM20A_ENGA_XXAA)
63zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L20_ENGA_CPUAPP NRF_APPLICATION)
64zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9120             NRF9120_XXAA)
65zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9160             NRF9160_XXAA)
66
67zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9230_ENGB_CPUAPP NRF9230_ENGB_XXAA
68                                                                NRF_APPLICATION)
69zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9230_ENGB_CPURAD NRF9230_ENGB_XXAA
70                                                                NRF_RADIOCORE)
71zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9230_ENGB_CPUPPR NRF9230_ENGB_XXAA
72                                                                NRF_PPR)
73
74zephyr_compile_definitions_ifdef(CONFIG_NRF_APPROTECT_LOCK
75                                 ENABLE_APPROTECT)
76zephyr_compile_definitions_ifdef(CONFIG_NRF_APPROTECT_USER_HANDLING
77                                 ENABLE_APPROTECT_USER_HANDLING
78                                 ENABLE_AUTHENTICATED_APPROTECT)
79zephyr_compile_definitions_ifdef(CONFIG_NRF_SECURE_APPROTECT_LOCK
80                                 ENABLE_SECURE_APPROTECT
81                                 ENABLE_SECUREAPPROTECT)
82zephyr_compile_definitions_ifdef(CONFIG_NRF_SECURE_APPROTECT_USER_HANDLING
83                                 ENABLE_SECURE_APPROTECT_USER_HANDLING
84                                 ENABLE_AUTHENTICATED_SECUREAPPROTECT)
85zephyr_library_compile_definitions_ifdef(CONFIG_NRF_TRACE_PORT
86                                 ENABLE_TRACE)
87
88zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF5340_CPUAPP
89                                 NRF_SKIP_FICR_NS_COPY_TO_RAM)
90zephyr_compile_definitions_ifdef(CONFIG_SOC_SERIES_NRF91X
91                                 NRF_SKIP_FICR_NS_COPY_TO_RAM)
92
93# Connect Kconfig compilation option for Non-Secure software with option required by MDK/nrfx
94zephyr_compile_definitions_ifdef(CONFIG_ARM_NONSECURE_FIRMWARE NRF_TRUSTZONE_NONSECURE)
95zephyr_compile_definitions_ifdef(CONFIG_LOG_BACKEND_SWO ENABLE_SWO)
96
97zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF51X  ${MDK_DIR}/system_nrf51.c)
98zephyr_library_sources_ifdef(CONFIG_SOC_NRF52805       ${MDK_DIR}/system_nrf52805.c)
99zephyr_library_sources_ifdef(CONFIG_SOC_NRF52810       ${MDK_DIR}/system_nrf52810.c)
100zephyr_library_sources_ifdef(CONFIG_SOC_NRF52811       ${MDK_DIR}/system_nrf52811.c)
101zephyr_library_sources_ifdef(CONFIG_SOC_NRF52820       ${MDK_DIR}/system_nrf52820.c)
102zephyr_library_sources_ifdef(CONFIG_SOC_NRF52832       ${MDK_DIR}/system_nrf52.c)
103zephyr_library_sources_ifdef(CONFIG_SOC_NRF52833       ${MDK_DIR}/system_nrf52833.c)
104zephyr_library_sources_ifdef(CONFIG_SOC_NRF52840       ${MDK_DIR}/system_nrf52840.c)
105zephyr_library_sources_ifdef(CONFIG_SOC_NRF5340_CPUAPP ${MDK_DIR}/system_nrf5340_application.c)
106zephyr_library_sources_ifdef(CONFIG_SOC_NRF5340_CPUNET ${MDK_DIR}/system_nrf5340_network.c)
107zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF54HX ${MDK_DIR}/system_nrf54h.c)
108if(CONFIG_SOC_SERIES_NRF54LX OR CONFIG_SOC_SERIES_BSIM_NRF54LX)
109  zephyr_library_sources(${MDK_DIR}/system_nrf54l.c)
110endif()
111zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF91X  ${MDK_DIR}/system_nrf91.c)
112zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF92X  ${MDK_DIR}/system_nrf92.c)
113
114zephyr_library_sources(nrfx_glue.c)
115zephyr_library_sources(${HELPERS_DIR}/nrfx_flag32_allocator.c)
116zephyr_library_sources_ifdef(CONFIG_HAS_NORDIC_RAM_CTRL       ${HELPERS_DIR}/nrfx_ram_ctrl.c)
117zephyr_library_sources_ifdef(CONFIG_NRFX_GPPI                 ${HELPERS_DIR}/nrfx_gppi_dppi.c)
118zephyr_library_sources_ifdef(CONFIG_NRFX_GPPI                 ${HELPERS_DIR}/nrfx_gppi_ppi.c)
119
120zephyr_library_sources_ifdef(CONFIG_NRFX_PRS     ${SRC_DIR}/prs/nrfx_prs.c)
121
122zephyr_library_sources_ifdef(CONFIG_NRFX_ADC     ${SRC_DIR}/nrfx_adc.c)
123zephyr_library_sources_ifdef(CONFIG_NRFX_CLOCK   ${SRC_DIR}/nrfx_clock.c)
124zephyr_library_sources_ifdef(CONFIG_NRFX_COMP    ${SRC_DIR}/nrfx_comp.c)
125zephyr_library_sources_ifdef(CONFIG_NRFX_CRACEN  ${SRC_DIR}/nrfx_cracen.c)
126zephyr_library_sources_ifdef(CONFIG_NRFX_DPPI    ${SRC_DIR}/nrfx_dppi.c)
127zephyr_library_sources_ifdef(CONFIG_NRFX_EGU     ${SRC_DIR}/nrfx_egu.c)
128zephyr_library_sources_ifdef(CONFIG_NRFX_GPIOTE  ${SRC_DIR}/nrfx_gpiote.c)
129zephyr_library_sources_ifdef(CONFIG_NRFX_GRTC    ${SRC_DIR}/nrfx_grtc.c)
130zephyr_library_sources_ifdef(CONFIG_NRFX_I2S     ${SRC_DIR}/nrfx_i2s.c)
131zephyr_library_sources_ifdef(CONFIG_NRFX_IPC     ${SRC_DIR}/nrfx_ipc.c)
132zephyr_library_sources_ifdef(CONFIG_NRFX_LPCOMP  ${SRC_DIR}/nrfx_lpcomp.c)
133zephyr_library_sources_ifdef(CONFIG_NRFX_NFCT    ${SRC_DIR}/nrfx_nfct.c)
134zephyr_library_sources_ifdef(CONFIG_NRFX_NVMC    ${SRC_DIR}/nrfx_nvmc.c)
135zephyr_library_sources_ifdef(CONFIG_NRFX_PDM     ${SRC_DIR}/nrfx_pdm.c)
136zephyr_library_sources_ifdef(CONFIG_NRFX_POWER   ${SRC_DIR}/nrfx_power.c)
137zephyr_library_sources_ifdef(CONFIG_NRFX_PPI     ${SRC_DIR}/nrfx_ppi.c)
138zephyr_library_sources_ifdef(CONFIG_NRFX_PPIB    ${SRC_DIR}/nrfx_ppib.c)
139zephyr_library_sources_ifdef(CONFIG_NRFX_PWM     ${SRC_DIR}/nrfx_pwm.c)
140zephyr_library_sources_ifdef(CONFIG_NRFX_QDEC    ${SRC_DIR}/nrfx_qdec.c)
141zephyr_library_sources_ifdef(CONFIG_NRFX_QSPI    ${SRC_DIR}/nrfx_qspi.c)
142zephyr_library_sources_ifdef(CONFIG_NRFX_RNG     ${SRC_DIR}/nrfx_rng.c)
143zephyr_library_sources_ifdef(CONFIG_NRFX_RRAMC   ${SRC_DIR}/nrfx_rramc.c)
144zephyr_library_sources_ifdef(CONFIG_NRFX_RTC     ${SRC_DIR}/nrfx_rtc.c)
145zephyr_library_sources_ifdef(CONFIG_NRFX_SAADC   ${SRC_DIR}/nrfx_saadc.c)
146zephyr_library_sources_ifdef(CONFIG_NRFX_SPI     ${SRC_DIR}/nrfx_spi.c)
147zephyr_library_sources_ifdef(CONFIG_NRFX_SPIM    ${SRC_DIR}/nrfx_spim.c)
148zephyr_library_sources_ifdef(CONFIG_NRFX_SPIS    ${SRC_DIR}/nrfx_spis.c)
149zephyr_library_sources_ifdef(CONFIG_NRFX_SYSTICK ${SRC_DIR}/nrfx_systick.c)
150zephyr_library_sources_ifdef(CONFIG_NRFX_TBM     ${SRC_DIR}/nrfx_tbm.c)
151zephyr_library_sources_ifdef(CONFIG_NRFX_TEMP    ${SRC_DIR}/nrfx_temp.c)
152zephyr_library_sources_ifdef(CONFIG_NRFX_TIMER   ${SRC_DIR}/nrfx_timer.c)
153zephyr_library_sources_ifdef(CONFIG_NRFX_TWI     ${SRC_DIR}/nrfx_twi.c)
154zephyr_library_sources_ifdef(CONFIG_NRFX_TWIM    ${SRC_DIR}/nrfx_twim.c)
155zephyr_library_sources_ifdef(CONFIG_NRFX_TWIS    ${SRC_DIR}/nrfx_twis.c)
156zephyr_library_sources_ifdef(CONFIG_NRFX_UART    ${SRC_DIR}/nrfx_uart.c)
157zephyr_library_sources_ifdef(CONFIG_NRFX_UARTE   ${SRC_DIR}/nrfx_uarte.c)
158zephyr_library_sources_ifdef(CONFIG_NRFX_USBREG  ${SRC_DIR}/nrfx_usbreg.c)
159zephyr_library_sources_ifdef(CONFIG_NRFX_WDT     ${SRC_DIR}/nrfx_wdt.c)
160
161if(CONFIG_NRFX_TWI OR CONFIG_NRFX_TWIM)
162  zephyr_library_sources(${SRC_DIR}/nrfx_twi_twim.c)
163endif()
164
165# Inject HAL "CONFIG_NFCT_PINS_AS_GPIOS" definition if user requests to
166# configure the NFCT pins as GPIOS. Do the same with "CONFIG_GPIO_AS_PINRESET"
167# to configure the reset GPIO as nRESET. This way, the HAL will take care of
168# doing the proper configuration sequence during system init
169
170dt_nodelabel(uicr_path NODELABEL "uicr")
171if(DEFINED uicr_path)
172  dt_prop(nfct_pins_as_gpios PATH ${uicr_path} PROPERTY "nfct-pins-as-gpios")
173  if(${nfct_pins_as_gpios})
174    zephyr_library_compile_definitions(
175      CONFIG_NFCT_PINS_AS_GPIOS
176      NRF_CONFIG_NFCT_PINS_AS_GPIOS
177    )
178  endif()
179
180  dt_prop(gpio_as_nreset PATH ${uicr_path} PROPERTY "gpio-as-nreset")
181  if(${gpio_as_nreset})
182    zephyr_library_compile_definitions(CONFIG_GPIO_AS_PINRESET)
183  endif()
184endif()
185
186if(CONFIG_SOC_NRF54L_CPUAPP_COMMON)
187	# Ideally, hfpll should taken as a phandle from clocks property from cpu but it
188	# seems that there is no such option in DT cmake functions. Assuming that nrf54l
189	# is using hfpll as CPU clock source (true for all existing devices).
190	dt_prop(clock_frequency PATH "/clocks/hfpll" PROPERTY "clock-frequency")
191	math(EXPR clock_frequency_mhz "${clock_frequency} / 1000000")
192	zephyr_compile_definitions("NRF_CONFIG_CPU_FREQ_MHZ=${clock_frequency_mhz}")
193endif()
194
195zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54LX_SKIP_CLOCK_CONFIG NRF_SKIP_CLOCK_CONFIGURATION)
196zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54LX_DISABLE_FICR_TRIMCNF NRF_DISABLE_FICR_TRIMCNF)
197zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54LX_SKIP_GLITCHDETECTOR_DISABLE NRF_SKIP_GLITCHDETECTOR_DISABLE)
198
199# Inject code to skip TAMPC setup for nRF54L20 and nRF54L09. It is not supported for now.
200# It needs to be removed when support is provided.
201if(CONFIG_SOC_NRF54L20_ENGA_CPUAPP OR CONFIG_SOC_NRF54L09_ENGA_CPUAPP)
202	  zephyr_compile_definitions(NRF_SKIP_TAMPC_SETUP)
203endif()
204
205if(CONFIG_SOC_COMPATIBLE_NRF54LX AND CONFIG_NRFX_GPPI)
206  zephyr_library_sources(${HELPERS_DIR}/nrfx_gppi_dppi_ppib_lumos.c)
207  zephyr_library_sources(${NRFX_DIR}/soc/interconnect/dppic_ppib/nrfx_interconnect_dppic_ppib.c)
208endif()
209
210if(CONFIG_SOC_SERIES_NRF54HX AND CONFIG_NRFX_GPPI)
211  zephyr_library_sources(${HELPERS_DIR}/nrfx_gppi_dppi_ppib.c)
212  zephyr_library_sources(${NRFX_DIR}/soc/interconnect/apb/nrfx_interconnect_apb.c)
213  zephyr_library_sources(${NRFX_DIR}/soc/interconnect/ipct/nrfx_interconnect_ipct.c)
214endif()
215
216# Get the SVD file for the current SoC
217macro(mdk_svd_ifdef feature_toggle filename)
218  if(${feature_toggle})
219    set(SOC_SVD_FILE ${MDK_DIR}/${filename} CACHE FILEPATH "Path to a CMSIS-SVD file")
220  endif()
221endmacro()
222
223mdk_svd_ifdef(CONFIG_SOC_SERIES_NRF51X        nrf51.svd)
224mdk_svd_ifdef(CONFIG_SOC_NRF52805             nrf52805.svd)
225mdk_svd_ifdef(CONFIG_SOC_NRF52810             nrf52810.svd)
226mdk_svd_ifdef(CONFIG_SOC_NRF52811             nrf52811.svd)
227mdk_svd_ifdef(CONFIG_SOC_NRF52820             nrf52820.svd)
228mdk_svd_ifdef(CONFIG_SOC_NRF52832             nrf52.svd)
229mdk_svd_ifdef(CONFIG_SOC_NRF52833             nrf52833.svd)
230mdk_svd_ifdef(CONFIG_SOC_NRF52840             nrf52840.svd)
231mdk_svd_ifdef(CONFIG_SOC_NRF5340_CPUAPP       nrf5340_application.svd)
232mdk_svd_ifdef(CONFIG_SOC_NRF5340_CPUNET       nrf5340_network.svd)
233mdk_svd_ifdef(CONFIG_SOC_NRF54H20_CPUAPP      nrf54h20_application.svd)
234mdk_svd_ifdef(CONFIG_SOC_NRF54H20_CPUPPR      nrf54h20_ppr.svd)
235mdk_svd_ifdef(CONFIG_SOC_NRF54H20_CPUFLPR     nrf54h20_flpr.svd)
236mdk_svd_ifdef(CONFIG_SOC_NRF54H20_CPURAD      nrf54h20_radiocore.svd)
237mdk_svd_ifdef(CONFIG_SOC_NRF54L05_CPUAPP      nrf54l05_application.svd)
238mdk_svd_ifdef(CONFIG_SOC_NRF54L05_CPUFLPR     nrf54l05_flpr.svd)
239mdk_svd_ifdef(CONFIG_SOC_NRF54L09_ENGA_CPUAPP nrf54lv10a_enga_application.svd)
240mdk_svd_ifdef(CONFIG_SOC_NRF54L10_CPUAPP      nrf54l10_application.svd)
241mdk_svd_ifdef(CONFIG_SOC_NRF54L10_CPUFLPR     nrf54l10_flpr.svd)
242mdk_svd_ifdef(CONFIG_SOC_NRF54L15_CPUAPP      nrf54l15_application.svd)
243mdk_svd_ifdef(CONFIG_SOC_NRF54L15_CPUFLPR     nrf54l15_flpr.svd)
244mdk_svd_ifdef(CONFIG_SOC_NRF54L20_ENGA_CPUAPP nrf54lm20a_enga_application.svd)
245mdk_svd_ifdef(CONFIG_SOC_NRF9120              nrf9120.svd)
246mdk_svd_ifdef(CONFIG_SOC_NRF9160              nrf9160.svd)
247mdk_svd_ifdef(CONFIG_SOC_NRF9230_ENGB_CPUAPP  nrf9230_engb_application.svd)
248mdk_svd_ifdef(CONFIG_SOC_NRF9230_ENGB_CPUPPR  nrf9230_engb_ppr.svd)
249mdk_svd_ifdef(CONFIG_SOC_NRF9230_ENGB_CPURAD  nrf9230_engb_radiocore.svd)
250build_info(vendor-specific nordic svdfile VALUE ${SOC_SVD_FILE})
251