🛠 Faire clignoter la LED RGB avec Zephyr

nRF52840-MDK (boards.json id: nrf52840-mdk) · debutant · Votre première LED sur le nRF52840-MDK : deux commandes west suffisent, le programmateur DAPLink est déjà embarqué sur la carte.

Why start here?

The MakerDiary nRF52840-MDK (~€30) is based on the Nordic nRF52840 SoC: Arm Cortex-M4F @ 64 MHz, 1 MB of flash, 256 KB of RAM, and a multiprotocol 2.4 GHz radio (BLE, Bluetooth Mesh, Thread, Zigbee, ANT). Its major advantage: an integrated DAPLink debugger (USB mass storage + virtual COM port + CMSIS-DAP) — no external programmer is needed. The board is referenced in upstream Zephyr under the name nrf52840_mdk.

Step 1 — Install the Zephyr toolchain

Follow the official Zephyr Getting Started Guide for your OS (CMake, Ninja, Python 3, Cortex-M toolchain, then west):

python3 -m venv .venv && source .venv/bin/activate   # .venv\Scripts\activate sous Windows
pip install west
west init zephyrproject
cd zephyrproject && west update

Step 2 — Connect the board

Connect the board via USB. It enumerates as a USB 2.0 hub with two ports: one to the DAPLink (the removable drive DAPLINK appears, plus a CDC serial port), and the other to the nRF52840's native USB. If the DAPLINK drive does not appear (known issues #53 and #37, especially on Mac), try a different cable, port, or host.

Step 3 — Build and flash

west build -b nrf52840_mdk samples/basic/blinky
west flash

west flash communicates with the embedded CMSIS-DAP probe. An alternative requiring no tools: drop build/zephyr.hex onto the DAPLINK drive, then press the Boot/Reset button.

Step 4 — Understand the code

The board's devicetree defines the alias led0, which is why the standard example works without modification:

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

#define LED0_NODE DT_ALIAS(led0)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

int main(void)
{
        if (!gpio_is_ready_dt(&led)) {
                return -1;
        }
        gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
        while (1) {
                gpio_pin_toggle_dt(&led);
                k_msleep(1000);
        }
}

The RGB LED is connected to standard P0 pins: for the exact pin assignment, refer to the official pinout diagram PDF rather than hardcoding pin numbers.

Known pitfalls

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials