🛠 Monter un projet Zephyr complet avec PlatformIO
Why PlatformIO?
PlatformIO encapsulates the entire toolchain (GCC Arm, GDB, pyOCD, Zephyr framework) for the nrf52840_mdk board on the nordicnrf52 platform. The official board page indicates the onboard probe and mentions "IS READY for debugging"; the available upload protocols are cmsis-dap (default, the board's DAPLink probe), blackmagic, jlink, mbed, nrfjprog, and stlink.
Step 1 — Install PlatformIO
curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py -o get-platformio.py
python3 get-platformio.py
# ou plus simple : pip install platformio
pio --version
Step 2 — Project Skeleton
mkdir mdk-zephyr && cd mdk-zephyr
pio project init --board nrf52840_mdk
Then the platformio.ini recommended by the Board Manager page:
[env:nrf52840_mdk]
platform = nordicnrf52
board = nrf52840_mdk
framework = zephyr
; la sonde DAPLink embarquée parle CMSIS-DAP (défaut) ;
; une sonde externe fonctionne aussi : jlink / nrfjprog / mbed
upload_protocol = cmsis-dap
; rappels du manifeste de carte (déjà cohérents par défaut)
board_build.mcu = nrf52840
board_build.f_cpu = 64000000L
Step 3 — The Source Code
In src/main.c, the board's devicetree provides the alias led0 (RGB LED) and button0 (user button):
#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)
{
gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
while (1) {
gpio_pin_toggle_dt(&led);
k_msleep(500);
}
}
An empty prj.conf file is sufficient for this sample; this is where you add CONFIG_BT=y, etc., later on.
Step 4 — Build, Flash, Console
pio run # compile
pio run -t upload # flashe via cmsis-dap
pio device monitor # console CDC du DAPLink
Debugging
debug_tool = cmsis-dap in the environment enables breakpoints from VS Code. Avoid: OpenOCD with the onboard probe — the maintainer of the Rust BSP never succeeded with OpenOCD on Ubuntu 18.04 and switched to J-Link; PlatformIO uses pyOCD, which works.
Pitfalls
- The framework declared in the manifest is Zephyr; the old test scripts in the MakerDiary repository are broken (issue #42) and its samples do not follow Zephyr 3.5+ (issue #55) — base your work on the current Zephyr tree.
- If the CMSIS-DAP upload fails, reconnect the board (the USB hub may miss the enumeration, issues #53/#37).