Use nrfx Drivers Directly Without Zephyr Abstractions
Use nrfx drivers directly on an nRF52 in the nRF Connect SDK: enable the nrfx timer, connect its interrupt and run a periodic callback without Zephyr drivers.

Zephyr's driver API is portable: the same gpio_pin_toggle_dt runs on an nRF52, an STM32 and an ESP32. Portability costs a layer of indirection, a device model and sometimes a feature the generic API cannot express, such as an nRF-specific timer shortcut or a hardware-triggered sample. Nordic ships nrfx, the drivers and HAL that sit underneath its own Zephyr drivers, and the nRF Connect SDK lets your application call them directly. This post shows where nrfx lives, how to enable a driver, how to connect its interrupt and a complete periodic timer, and when to prefer it over the Zephyr API. It targets nRF Connect SDK v2.9, which bundles nrfx 3.x. Names and signatures changed between nrfx 2 and 3, so confirm the exact names in the nrfx release notes of your SDK.
The layers
Nordic's driver stack has three levels you can call:
| Level | Prefix | Example | Use for |
|---|---|---|---|
| Zephyr API | gpio_, uart_, counter_ | gpio_pin_toggle_dt | Portable application code |
| nrfx driver | nrfx_ | nrfx_timer_init | Nordic-specific features and control with a managed interrupt |
| nrfx HAL | nrf_ | nrf_gpio_pin_toggle | Direct register access, no state, no interrupts |
The nrfx HAL is a set of inline functions over the registers defined in the MDK headers. The nrfx drivers add state, interrupt handling and error codes. Zephyr's own drivers for the nRF52 call nrfx internally, so everything you can do with the Zephyr API you can also do with nrfx. The reverse is not true: the Zephyr API cannot express hardware event routing between peripherals, EasyDMA chains or the timer's capture and compare shortcuts.
Enabling a driver
In the nRF Connect SDK each nrfx driver has a Kconfig symbol of the form CONFIG_NRFX_<DRIVER>, and per-instance symbols for peripherals with several instances. For TIMER1, add to prj.conf:
CONFIG_NRFX_TIMER1=y
CONFIG_GPIO=yChoose an instance that nothing else uses. Zephyr uses RTC1 for its system clock on the nRF52, and the Bluetooth controller uses TIMER0 and RTC0 through the MPSL, so avoid those if you enable Bluetooth. If the same instance is claimed by a Zephyr driver in the devicetree, the build or the run fails with a conflict, and the fix is to disable the node with status = "disabled" in an overlay.
A periodic timer with nrfx
The nrfx timer driver wraps a TIMER peripheral. You describe an instance, initialise it with a configuration and a handler, program a compare channel and enable its interrupt.
#include <zephyr/kernel.h>
#include <zephyr/irq.h>
#include <nrfx_timer.h>
#include <helpers/nrfx_gppi.h>
#include <hal/nrf_gpio.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(app, LOG_LEVEL_INF);
#define LED_PIN 13 /* P0.13 is LED1 on the nRF52840 DK */
static const nrfx_timer_t timer = NRFX_TIMER_INSTANCE(NRF_TIMER1);
static volatile uint32_t ticks;
static void timer_handler(nrf_timer_event_t event_type, void *p_context)
{
if (event_type == NRF_TIMER_EVENT_COMPARE0) {
ticks++;
nrf_gpio_pin_toggle(LED_PIN);
}
}
int main(void)
{
nrf_gpio_cfg_output(LED_PIN);
nrf_gpio_pin_set(LED_PIN); /* LED1 is active low */
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_TIMER1), 5, nrfx_isr,
nrfx_timer_1_irq_handler, 0);
nrfx_timer_config_t cfg = NRFX_TIMER_DEFAULT_CONFIG(1000000); /* 1 MHz */
cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
nrfx_err_t err = nrfx_timer_init(&timer, &cfg, timer_handler);
if (err != NRFX_SUCCESS) {
LOG_ERR("nrfx_timer_init failed: 0x%08x", err);
return 0;
}
uint32_t ticks_500ms = nrfx_timer_ms_to_ticks(&timer, 500);
nrfx_timer_extended_compare(&timer, NRF_TIMER_CC_CHANNEL0, ticks_500ms,
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrfx_timer_enable(&timer);
while (1) {
k_sleep(K_SECONDS(2));
LOG_INF("timer ticks: %u", ticks);
}
}Read the setup line by line. NRFX_TIMER_INSTANCE(NRF_TIMER1) creates the instance descriptor, whose macro form varies with the nrfx version (in some releases it takes an index such as 1), so check the header in your SDK. IRQ_CONNECT binds the peripheral's interrupt to the nrfx dispatcher: Zephyr owns the interrupt vectors, so the application must connect the vector to nrfx_isr, which calls the driver's handler nrfx_timer_1_irq_handler. The priority 5 is an example in Zephyr's numbering; priorities 0 and 1 are normally reserved for the radio and for the zero-latency interrupts.
NRFX_TIMER_DEFAULT_CONFIG(1000000) sets the base clock to 1 MHz, which the driver derives from the 16 MHz timer clock with a prescaler of 4. The compare in nrfx_timer_extended_compare is 500,000 ticks of 1 µs, which is 500 ms. The SHORT_COMPARE0_CLEAR shortcut makes the hardware reset the counter on a match, so the period has no software jitter from interrupt latency, and the final true enables the compare interrupt. The handler toggles LED1 and counts.
After 5 seconds the log shows roughly ten interrupts:
[00:00:02.000,000] <inf> app: timer ticks: 4
[00:00:04.000,000] <inf> app: timer ticks: 8
[00:00:06.000,000] <inf> app: timer ticks: 12The counts follow from the arithmetic, one tick per 500 ms, so four per 2 seconds, though the exact count at a log moment can differ by one depending on the phase.
Using the HAL alone
When you want no driver state at all, the HAL gives raw register control. The same timer without the driver:
#include <hal/nrf_timer.h>
void timer1_start_hal(void)
{
nrf_timer_mode_set(NRF_TIMER1, NRF_TIMER_MODE_TIMER);
nrf_timer_bit_width_set(NRF_TIMER1, NRF_TIMER_BIT_WIDTH_32);
nrf_timer_prescaler_set(NRF_TIMER1, 4); /* 16 MHz / 2^4 = 1 MHz */
nrf_timer_cc_set(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, 500000);
nrf_timer_shorts_enable(NRF_TIMER1, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK);
nrf_timer_int_enable(NRF_TIMER1, NRF_TIMER_INT_COMPARE0_MASK);
nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_START);
}Every call is an inline function over a register write, and they correspond one-to-one with the product specification's TIMER chapter: MODE, BITMODE, PRESCALER, CC[0], SHORTS, INTENSET and TASKS_START. You write the interrupt handler yourself and clear the event flag, with nrf_timer_event_clear(NRF_TIMER1, NRF_TIMER_EVENT_COMPARE0). The advantage is full control and a tiny footprint, and the disadvantage is that you own every detail.
Why you might choose nrfx over the Zephyr API
There are three good reasons. The first is a Nordic-only feature: PPI routing, the TIMER shortcuts shown above, the EasyDMA double buffering of the UARTE, the SAADC's hardware-triggered sampling and burst mode. The second is determinism: a direct interrupt avoids the Zephyr device model's locking and callbacks, which matters for a tight sampling period. The third is footprint and porting: code that began on the nRF5 SDK, which used nrfx-style drivers, ports to the nRF Connect SDK with fewer changes if it keeps calling nrfx.
Where it goes wrong
Resource conflicts are the main trap. If you enable CONFIG_NRFX_TIMER1 and Zephyr's counter driver or PWM driver also takes TIMER1 through a devicetree node set to "okay", the two fight, and the symptom is a hard fault or silence. Look at zephyr.dts for any node with status = "okay" on the instance you want. The Bluetooth controller is the other claimant, and its reserved peripherals are listed in the MPSL documentation: the controller's own TIMER and RTC instances, plus PPI channels and some interrupts, are off limits.
A second trap is the interrupt priority. A handler that runs at a priority above the controller's can delay radio events and break connections. Keep application interrupts at priority 2 or lower urgency (higher number) unless there is a reason.
A third is that the nrfx API differs between versions. A snippet from the nRF5 SDK or from nrfx 1.x does not compile against nrfx 3.x without changes: functions were renamed, error type changes and instance macros were reworked. Use examples from the SDK version you build with, in modules/hal/nordic/nrfx/ and the samples folders.
When to stay with Zephyr's API
Use the Zephyr API for everything that is ordinary: GPIO, UART consoles, I2C and SPI transfers with a sensor driver, a k_timer for non-critical periodic work. The portable code is easier to test and easier to move to another SoC, and the performance difference rarely matters. Reach for nrfx when you hit the edge of what the generic API expresses, not before.


