blinky.c

nRF52833-DK (boards.json id: nrf52833-dk) · File : blinky.c · Language : C · Use case : Faire clignoter la LED0 à 2 Hz (hello world Zephyr)

The Zephyr hello world adapted to nRF boards: the user LED (devicetree alias led0, P0.13 on the DK) blinks at 2 Hz. The code never names a raw pin — the board BSP makes the link, which keeps it portable.

Hardware

An nRF52833-DK board (Nordic, nRF52833 Cortex-M4F SoC, BLE 5) powered over USB: 4 LEDs on P0.13-P0.16 (active-low) and 4 buttons on P0.11, P0.12, P0.24, P0.25 (active-low, internal pull-up must be enabled). Just the board, powered from its USB port; no external part for this first test.

Wiring

No wiring: the LED is on-board. On the DK the LEDs are active-low (the BSP knows via the active-low flag).

How it works

GPIO_DT_SPEC_GET resolves alias led0 into (chip, pin, flags) at compile time; gpio_pin_configure_dt drives the pin output-off, then toggle + k_msleep(500) give the 2 Hz.

Running it

Zephyr project: west build -b nrf52833dk/nrf52833 then west flash (on-board J-Link); 115200 serial console on the USB UART connector.

Variants

Drop to 0.5 Hz for a visible sleep mode, use PWM for a heartbeat, or switch to led1/led2 for a multi-LED pattern.

blinky.c

/* Blinky Zephyr — la LED0 de la carte clignote à 2 Hz.
 * L'alias devicetree led0 pointe sur la LED utilisateur du BSP
 * (P0.13 sur le nRF52833-DK, LED rouge sur le nRF52840-MDK).
 * Build : west build -b <board> ; flash : west flash. */
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

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

int main(void)
{
	if (!gpio_is_ready_dt(&led)) {
		printk("Puce GPIO absente\n");
		return 1;
	}
	/* INACTIVE : la LED s'éteint quel que soit le sens d'actif */
	gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE);

	while (1) {
		gpio_pin_toggle_dt(&led);
		k_msleep(500);
	}
	return 0;
}

← Back to the board