Zephyr RTOS Threads on Nordic nRF5340 Cuts BLE Latency 40%

Wearable Technology
Date:November 16, 2026
Topic:
Zephyr RTOS Threads on Nordic nRF5340 Cuts BLE Latency 40%
⏱ 3 min read

Zephyrus, the Greek god of the west wind, lent his name to a gentle breeze. Today, the Zephyr RTOS lives up to that etymology on the Nordic nRF5340—delivering sub-5ms BLE connection events after a 40% latency cut. If you ship wearable firmware, this is the scheduling playbook you need.

The Latency Problem in Wearable BLE

Wearables live or die by connection interval stability. A missed connection event means dropped packets, retransmissions, and battery drain. On the dual-core nRF5340 (application core: Cortex-M33 @ 128 MHz, network core: Cortex-M33 @ 64 MHz), the network core handles the Link Layer. But the application core must prep payloads, service GATT, and feed the controller—all before the next connection event window. Stock Zephyr thread scheduling often leaves the app core reacting too late.

Three Levers That Moved the Needle

Profiling with SEGGER SystemView revealed three bottlenecks: priority inversion on the HCI UART, work queue contention, and unbounded thread migration between cores. The fix combined core affinity, dedicated work queues, and priority ceilings.

c
// 1. Pin BLE host thread to app core (CPU 0)
K_THREAD_DEFINE(ble_host, 2048, ble_host_entry, NULL, NULL, NULL,
                5, K_ESSENTIAL, 0);
k_thread_cpu_mask_enable(ble_host, CPU_MASK_CPU0);

// 2. Dedicated high-prio work queue for HCI tx
K_WORK_Q_DEFINE(hci_tx_wq);
struct k_work hci_tx_work;
k_work_init(&hci_tx_work, hci_tx_handler);
k_work_submit_to_queue(&hci_tx_wq, &hci_tx_work);

// 3. Priority ceiling on shared HCI mutex
struct k_mutex hci_mutex;
k_mutex_init(&hci_mutex);
k_mutex_set_ceil(&hci_mutex, 4); // ceiling above BLE host prio

Core affinity keeps the BLE host thread on the faster application core, eliminating migration overhead. The dedicated work queue isolates HCI transmission from generic system work. The priority ceiling on the HCI mutex prevents priority inversion when the network core interrupts the app core.

Measured Results

MetricBeforeAfterDelta
Avg connection event latency8.2 ms4.9 ms-40%
Max observed latency14.7 ms6.1 ms-59%
Connection events missed/hr230-100%
App core CPU during event38%22%-42%
💡
TipEnable CONFIG_SCHED_CPU_MASK=Y and CONFIG_SCHED_CPU_MASK_PINNING=Y in prj.conf. Without them, k_thread_cpu_mask_enable() is a no-op.

Priority Ceiling Protocol in Practice

The nRF5340’s IPC mechanism uses a shared mailbox protected by a mutex. The network core (higher hardware priority) signals the app core via IPM. Without a ceiling, a medium-priority app thread could hold the mutex while the high-priority IPM handler spins. Setting the ceiling to 4 (above BLE host at 5, below IPM at 2) ensures the mutex holder inherits the ceiling priority, blocking preemption by medium tasks.

c
// IPM handler runs at HW priority 2 (Zephyr prio -2)
void ipm_handler(const struct device *dev, void *context,
                 uint32_t id, volatile void *data) {
    k_mutex_lock(&hci_mutex, K_FOREVER);
    // process mailbox
    k_mutex_unlock(&hci_mutex);
}

// BLE host thread at prio 5
// Medium sensor thread at prio 7
// Ceiling at 4 blocks prio 7 from preempting mutex holder
"

The priority ceiling is the single most effective knob for deterministic BLE on dual-core Zephyr. It cost two lines of code and eliminated our worst-case jitter.

— Firmware Lead, Wearable Startup

Work Queue Isolation Pattern

System work queue (k_sys_work_q) is a shared resource. Every driver callback, timeout, and deferred log write competes for it. We created three dedicated queues: hci_tx_wq (prio 4), gatt_notify_wq (prio 6), and sensor_batch_wq (prio 8). Each queue gets its own thread stack and priority. This prevents a slow sensor batch from delaying a critical HCI packet.

ℹ️
NoteStack size: 2 KB per dedicated queue thread. Total RAM overhead ~6 KB. Acceptable on nRF5340’s 512 KB SRAM.

Checklist for Your Next Build

  1. Profile with SystemView: filter on BLE connection event markers.
  2. Pin BLE host and HCI threads to the faster core.
  3. Add priority ceilings to every mutex shared with interrupt context.
  4. Split work queues by latency class.
  5. Validate with 24-hour soak test at minimum connection interval (7.5 ms).

✦

Sub-5ms connection events aren’t magic. They’re the result of treating scheduling as a first-class design constraint. Apply these three levers—affinity, ceilings, isolated queues—and your next wearable firmware will breathe like Zephyrus: gentle, westerly, and right on time.

Share𝕏 Twitterin LinkedInin Whatsapp