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_NRF54L10            NRF54L10_XXAA
52                                                                DEVELOP_IN_NRF54L15)
53zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L10_CPUAPP     NRF_APPLICATION)
54zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L10_CPUFLPR    NRF_FLPR)
55zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L15            NRF54L15_XXAA)
56zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L15_CPUAPP     NRF_APPLICATION)
57zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L15_CPUFLPR    NRF_FLPR)
58zephyr_compile_definitions_ifdef(CONFIG_SOC_COMPATIBLE_NRF54L15 NRF54L15_XXAA)
59zephyr_compile_definitions_ifdef(CONFIG_SOC_COMPATIBLE_NRF54L15_CPUAPP NRF_APPLICATION)
60zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L20_ENGA       NRF54L20_ENGA_XXAA)
61zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54L20_ENGA_CPUAPP NRF_APPLICATION)
62zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9120             NRF9120_XXAA)
63zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9160             NRF9160_XXAA)
64
65zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9230_ENGB_CPUAPP NRF9230_ENGB_XXAA
66                                                                NRF_APPLICATION)
67zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9230_ENGB_CPURAD NRF9230_ENGB_XXAA
68                                                                NRF_RADIOCORE)
69zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF9230_ENGB_CPUPPR NRF9230_ENGB_XXAA
70                                                                NRF_PPR)
71
72zephyr_compile_definitions_ifdef(CONFIG_NRF_APPROTECT_LOCK
73                                 ENABLE_APPROTECT)
74zephyr_compile_definitions_ifdef(CONFIG_NRF_APPROTECT_USER_HANDLING
75                                 ENABLE_APPROTECT_USER_HANDLING
76                                 ENABLE_AUTHENTICATED_APPROTECT)
77zephyr_compile_definitions_ifdef(CONFIG_NRF_SECURE_APPROTECT_LOCK
78                                 ENABLE_SECURE_APPROTECT
79                                 ENABLE_SECUREAPPROTECT)
80zephyr_compile_definitions_ifdef(CONFIG_NRF_SECURE_APPROTECT_USER_HANDLING
81                                 ENABLE_SECURE_APPROTECT_USER_HANDLING
82                                 ENABLE_AUTHENTICATED_SECUREAPPROTECT)
83zephyr_library_compile_definitions_ifdef(CONFIG_NRF_TRACE_PORT
84                                 ENABLE_TRACE)
85
86zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF5340_CPUAPP
87                                 NRF_SKIP_FICR_NS_COPY_TO_RAM)
88zephyr_compile_definitions_ifdef(CONFIG_SOC_SERIES_NRF91X
89                                 NRF_SKIP_FICR_NS_COPY_TO_RAM)
90
91# Connect Kconfig compilation option for Non-Secure software with option required by MDK/nrfx
92zephyr_compile_definitions_ifdef(CONFIG_ARM_NONSECURE_FIRMWARE NRF_TRUSTZONE_NONSECURE)
93zephyr_compile_definitions_ifdef(CONFIG_LOG_BACKEND_SWO ENABLE_SWO)
94
95zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF51X  ${MDK_DIR}/system_nrf51.c)
96zephyr_library_sources_ifdef(CONFIG_SOC_NRF52805       ${MDK_DIR}/system_nrf52805.c)
97zephyr_library_sources_ifdef(CONFIG_SOC_NRF52810       ${MDK_DIR}/system_nrf52810.c)
98zephyr_library_sources_ifdef(CONFIG_SOC_NRF52811       ${MDK_DIR}/system_nrf52811.c)
99zephyr_library_sources_ifdef(CONFIG_SOC_NRF52820       ${MDK_DIR}/system_nrf52820.c)
100zephyr_library_sources_ifdef(CONFIG_SOC_NRF52832       ${MDK_DIR}/system_nrf52.c)
101zephyr_library_sources_ifdef(CONFIG_SOC_NRF52833       ${MDK_DIR}/system_nrf52833.c)
102zephyr_library_sources_ifdef(CONFIG_SOC_NRF52840       ${MDK_DIR}/system_nrf52840.c)
103zephyr_library_sources_ifdef(CONFIG_SOC_NRF5340_CPUAPP ${MDK_DIR}/system_nrf5340_application.c)
104zephyr_library_sources_ifdef(CONFIG_SOC_NRF5340_CPUNET ${MDK_DIR}/system_nrf5340_network.c)
105zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF54HX ${MDK_DIR}/system_nrf54h.c)
106if(CONFIG_SOC_SERIES_NRF54LX OR CONFIG_SOC_SERIES_BSIM_NRF54LX)
107  zephyr_library_sources(${MDK_DIR}/system_nrf54l.c)
108endif()
109zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF91X  ${MDK_DIR}/system_nrf91.c)
110zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_NRF92X  ${MDK_DIR}/system_nrf92.c)
111
112zephyr_library_sources(nrfx_glue.c)
113zephyr_library_sources(${HELPERS_DIR}/nrfx_flag32_allocator.c)
114zephyr_library_sources_ifdef(CONFIG_HAS_NORDIC_RAM_CTRL       ${HELPERS_DIR}/nrfx_ram_ctrl.c)
115zephyr_library_sources_ifdef(CONFIG_NRFX_GPPI                 ${HELPERS_DIR}/nrfx_gppi_dppi.c)
116zephyr_library_sources_ifdef(CONFIG_NRFX_GPPI                 ${HELPERS_DIR}/nrfx_gppi_ppi.c)
117
118zephyr_library_sources_ifdef(CONFIG_NRFX_PRS     ${SRC_DIR}/prs/nrfx_prs.c)
119
120zephyr_library_sources_ifdef(CONFIG_NRFX_ADC     ${SRC_DIR}/nrfx_adc.c)
121zephyr_library_sources_ifdef(CONFIG_NRFX_CLOCK   ${SRC_DIR}/nrfx_clock.c)
122zephyr_library_sources_ifdef(CONFIG_NRFX_COMP    ${SRC_DIR}/nrfx_comp.c)
123zephyr_library_sources_ifdef(CONFIG_NRFX_DPPI    ${SRC_DIR}/nrfx_dppi.c)
124zephyr_library_sources_ifdef(CONFIG_NRFX_EGU     ${SRC_DIR}/nrfx_egu.c)
125zephyr_library_sources_ifdef(CONFIG_NRFX_GPIOTE  ${SRC_DIR}/nrfx_gpiote.c)
126zephyr_library_sources_ifdef(CONFIG_NRFX_GRTC    ${SRC_DIR}/nrfx_grtc.c)
127zephyr_library_sources_ifdef(CONFIG_NRFX_I2S     ${SRC_DIR}/nrfx_i2s.c)
128zephyr_library_sources_ifdef(CONFIG_NRFX_IPC     ${SRC_DIR}/nrfx_ipc.c)
129zephyr_library_sources_ifdef(CONFIG_NRFX_LPCOMP  ${SRC_DIR}/nrfx_lpcomp.c)
130zephyr_library_sources_ifdef(CONFIG_NRFX_NFCT    ${SRC_DIR}/nrfx_nfct.c)
131zephyr_library_sources_ifdef(CONFIG_NRFX_NVMC    ${SRC_DIR}/nrfx_nvmc.c)
132zephyr_library_sources_ifdef(CONFIG_NRFX_PDM     ${SRC_DIR}/nrfx_pdm.c)
133zephyr_library_sources_ifdef(CONFIG_NRFX_POWER   ${SRC_DIR}/nrfx_power.c)
134zephyr_library_sources_ifdef(CONFIG_NRFX_PPI     ${SRC_DIR}/nrfx_ppi.c)
135zephyr_library_sources_ifdef(CONFIG_NRFX_PPIB    ${SRC_DIR}/nrfx_ppib.c)
136zephyr_library_sources_ifdef(CONFIG_NRFX_PWM     ${SRC_DIR}/nrfx_pwm.c)
137zephyr_library_sources_ifdef(CONFIG_NRFX_QDEC    ${SRC_DIR}/nrfx_qdec.c)
138zephyr_library_sources_ifdef(CONFIG_NRFX_QSPI    ${SRC_DIR}/nrfx_qspi.c)
139zephyr_library_sources_ifdef(CONFIG_NRFX_RNG     ${SRC_DIR}/nrfx_rng.c)
140zephyr_library_sources_ifdef(CONFIG_NRFX_RRAMC   ${SRC_DIR}/nrfx_rramc.c)
141zephyr_library_sources_ifdef(CONFIG_NRFX_RTC     ${SRC_DIR}/nrfx_rtc.c)
142zephyr_library_sources_ifdef(CONFIG_NRFX_SAADC   ${SRC_DIR}/nrfx_saadc.c)
143zephyr_library_sources_ifdef(CONFIG_NRFX_SPI     ${SRC_DIR}/nrfx_spi.c)
144zephyr_library_sources_ifdef(CONFIG_NRFX_SPIM    ${SRC_DIR}/nrfx_spim.c)
145zephyr_library_sources_ifdef(CONFIG_NRFX_SPIS    ${SRC_DIR}/nrfx_spis.c)
146zephyr_library_sources_ifdef(CONFIG_NRFX_SYSTICK ${SRC_DIR}/nrfx_systick.c)
147zephyr_library_sources_ifdef(CONFIG_NRFX_TBM     ${SRC_DIR}/nrfx_tbm.c)
148zephyr_library_sources_ifdef(CONFIG_NRFX_TEMP    ${SRC_DIR}/nrfx_temp.c)
149zephyr_library_sources_ifdef(CONFIG_NRFX_TIMER   ${SRC_DIR}/nrfx_timer.c)
150zephyr_library_sources_ifdef(CONFIG_NRFX_TWI     ${SRC_DIR}/nrfx_twi.c)
151zephyr_library_sources_ifdef(CONFIG_NRFX_TWIM    ${SRC_DIR}/nrfx_twim.c)
152zephyr_library_sources_ifdef(CONFIG_NRFX_TWIS    ${SRC_DIR}/nrfx_twis.c)
153zephyr_library_sources_ifdef(CONFIG_NRFX_UART    ${SRC_DIR}/nrfx_uart.c)
154zephyr_library_sources_ifdef(CONFIG_NRFX_UARTE   ${SRC_DIR}/nrfx_uarte.c)
155zephyr_library_sources_ifdef(CONFIG_NRFX_USBREG  ${SRC_DIR}/nrfx_usbreg.c)
156zephyr_library_sources_ifdef(CONFIG_NRFX_WDT     ${SRC_DIR}/nrfx_wdt.c)
157
158if(CONFIG_NRFX_TWI OR CONFIG_NRFX_TWIM)
159  zephyr_library_sources(${SRC_DIR}/nrfx_twi_twim.c)
160endif()
161
162# Inject HAL "CONFIG_NFCT_PINS_AS_GPIOS" definition if user requests to
163# configure the NFCT pins as GPIOS. Do the same with "CONFIG_GPIO_AS_PINRESET"
164# to configure the reset GPIO as nRESET. This way, the HAL will take care of
165# doing the proper configuration sequence during system init
166
167dt_nodelabel(uicr_path NODELABEL "uicr")
168if(DEFINED uicr_path)
169  dt_prop(nfct_pins_as_gpios PATH ${uicr_path} PROPERTY "nfct-pins-as-gpios")
170  if(${nfct_pins_as_gpios})
171    zephyr_library_compile_definitions(
172      CONFIG_NFCT_PINS_AS_GPIOS
173      NRF_CONFIG_NFCT_PINS_AS_GPIOS
174    )
175  endif()
176
177  dt_prop(gpio_as_nreset PATH ${uicr_path} PROPERTY "gpio-as-nreset")
178  if(${gpio_as_nreset})
179    zephyr_library_compile_definitions(CONFIG_GPIO_AS_PINRESET)
180  endif()
181endif()
182
183if(CONFIG_SOC_NRF54L_CPUAPP_COMMON)
184	dt_prop(clock_frequency PATH "/cpus/cpu@0" PROPERTY "clock-frequency")
185	math(EXPR clock_frequency_mhz "${clock_frequency} / 1000000")
186	zephyr_compile_definitions("NRF_CONFIG_CPU_FREQ_MHZ=${clock_frequency_mhz}")
187endif()
188
189zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54LX_SKIP_CLOCK_CONFIG NRF_SKIP_CLOCK_CONFIGURATION)
190zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54LX_DISABLE_FICR_TRIMCNF NRF_DISABLE_FICR_TRIMCNF)
191zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF54LX_SKIP_GLITCHDETECTOR_DISABLE NRF_SKIP_GLITCHDETECTOR_DISABLE)
192
193# Inject code to skip TAMPC setup for nRF54L20. It is not supported for now.
194# It needs to be removed when support is provided.
195if(CONFIG_SOC_NRF54L20_ENGA_CPUAPP)
196  zephyr_compile_definitions(NRF_SKIP_TAMPC_SETUP)
197endif()
198
199if(CONFIG_SOC_SERIES_NRF54LX AND CONFIG_NRFX_GPPI)
200  zephyr_library_sources(${HELPERS_DIR}/nrfx_gppi_dppi_ppib_lumos.c)
201  zephyr_library_sources(${NRFX_DIR}/soc/interconnect/dppic_ppib/nrfx_interconnect_dppic_ppib.c)
202endif()
203
204if(CONFIG_SOC_SERIES_NRF54HX AND CONFIG_NRFX_GPPI)
205  zephyr_library_sources(${HELPERS_DIR}/nrfx_gppi_dppi_ppib.c)
206  zephyr_library_sources(${NRFX_DIR}/soc/interconnect/apb/nrfx_interconnect_apb.c)
207  zephyr_library_sources(${NRFX_DIR}/soc/interconnect/ipct/nrfx_interconnect_ipct.c)
208endif()
209
210# Get the SVD file for the current SoC
211macro(mdk_svd_ifdef feature_toggle filename)
212  if(${feature_toggle})
213    set(SOC_SVD_FILE ${MDK_DIR}/${filename} CACHE FILEPATH "Path to a CMSIS-SVD file")
214  endif()
215endmacro()
216
217mdk_svd_ifdef(CONFIG_SOC_SERIES_NRF51X        nrf51.svd)
218mdk_svd_ifdef(CONFIG_SOC_NRF52805             nrf52805.svd)
219mdk_svd_ifdef(CONFIG_SOC_NRF52810             nrf52810.svd)
220mdk_svd_ifdef(CONFIG_SOC_NRF52811             nrf52811.svd)
221mdk_svd_ifdef(CONFIG_SOC_NRF52820             nrf52820.svd)
222mdk_svd_ifdef(CONFIG_SOC_NRF52832             nrf52.svd)
223mdk_svd_ifdef(CONFIG_SOC_NRF52833             nrf52833.svd)
224mdk_svd_ifdef(CONFIG_SOC_NRF52840             nrf52840.svd)
225mdk_svd_ifdef(CONFIG_SOC_NRF5340_CPUAPP       nrf5340_application.svd)
226mdk_svd_ifdef(CONFIG_SOC_NRF5340_CPUNET       nrf5340_network.svd)
227mdk_svd_ifdef(CONFIG_SOC_NRF54H20_CPUAPP      nrf54h20_application.svd)
228mdk_svd_ifdef(CONFIG_SOC_NRF54H20_CPUPPR      nrf54h20_ppr.svd)
229mdk_svd_ifdef(CONFIG_SOC_NRF54H20_CPUFLPR     nrf54h20_flpr.svd)
230mdk_svd_ifdef(CONFIG_SOC_NRF54H20_CPURAD      nrf54h20_radiocore.svd)
231mdk_svd_ifdef(CONFIG_SOC_NRF54L05_CPUAPP      nrf54l05_application.svd)
232mdk_svd_ifdef(CONFIG_SOC_NRF54L05_CPUFLPR     nrf54l05_flpr.svd)
233mdk_svd_ifdef(CONFIG_SOC_NRF54L10_CPUAPP      nrf54l10_application.svd)
234mdk_svd_ifdef(CONFIG_SOC_NRF54L10_CPUFLPR     nrf54l10_flpr.svd)
235mdk_svd_ifdef(CONFIG_SOC_NRF54L15_CPUAPP      nrf54l15_application.svd)
236mdk_svd_ifdef(CONFIG_SOC_NRF54L15_CPUFLPR     nrf54l15_flpr.svd)
237mdk_svd_ifdef(CONFIG_SOC_NRF54L20_ENGA_CPUAPP nrf54l20_enga_application.svd)
238mdk_svd_ifdef(CONFIG_SOC_NRF9120              nrf9120.svd)
239mdk_svd_ifdef(CONFIG_SOC_NRF9160              nrf9160.svd)
240mdk_svd_ifdef(CONFIG_SOC_NRF9230_ENGB_CPUAPP  nrf9230_engb_application.svd)
241mdk_svd_ifdef(CONFIG_SOC_NRF9230_ENGB_CPUPPR  nrf9230_engb_ppr.svd)
242mdk_svd_ifdef(CONFIG_SOC_NRF9230_ENGB_CPURAD  nrf9230_engb_radiocore.svd)
243build_info(vendor-specific nordic svdfile VALUE ${SOC_SVD_FILE})
244