示例与演示

Zephyr 提供了丰富的示例与演示,展示内核及各个子系统的功能。

这些示例力求简单易懂,可作为开发自己的项目的起点。

欢迎向项目贡献新示例。有意提交示例时,请先阅读 Sample Definition and Criteria。

备注

下方列表按示例源码中的元数据自动汇总。尚未翻译的示例名称和简介保留英文, 点击后打开上游英文文档。已翻译的示例会打开本站中文页面。

应用开发

Architecture-dependent Samples

MMU/MPU

Symmetric Multiprocessing (SMP)

  • SMP PiCalculate the first 240 digits of Pi on multiple execution units.
  • SMP pktqueueUse SMP to process multiple packet headers in parallel.

Basic

Bluetooth

Bluetooth Audio

Bluetooth Classic

Boards

96Boards

96Boards ArgonKey

  • MicrophoneAcquire audio through the ArgonKey's on-board MP34DT05 microphone.
  • SensorsRead sensor data from the ArgonKey board's onboard sensors.

ADI

AMD

BBC

BBC micro:bit

  • LED matrix displayUse the 5x5 LED matrix display on the BBC micro:bit board.
  • Line following robotImplement a line following robot using a BBC micro:bit board and robot chassis.
  • Pong gamePlay pong as single player or over Bluetooth between two micro:bit devices.
  • SoundUse the piezo buzzer on the BBC micro:bit board.

EnjoyDigital

Espressif ESP32 boards

  • Deep SleepUse deep sleep with wake on timer, GPIO, and EXT1 sources on ESP32.
  • ESP-NOWSend and receive ESP-NOW broadcast heartbeat beacons between two ESP32 boards.
  • ESP32 qdec per-unit threshold triggerInstall per-unit threshold callbacks on the ESP32 PCNT driver.
  • Flash EncryptionEncrypt/decrypt data stored in flash memory using ESP32 flash encryption feature.
  • Flash IPM on ESP32Sample of flash API sharing between CPU cores using inter-processor mailbox (IPM).
  • Light SleepUse light sleep mode on ESP32 to save power while preserving the state of the memory, CPU, and peripherals.
  • Memory-Mapped FlashWrite data into the storage partition and read it using flash API and memory-mapped pointer.
  • Pixel processing acceleratorScale, rotate and mirror an image with the pixel processing accelerator.
  • SPIRAMAllocate memory from SPIRAM.
  • Wi-Fi MeshBuild a self-organizing multi-hop Wi-Fi mesh network.
  • Wi-Fi Mesh IPCarry IP over a self-organizing Wi-Fi mesh with a root NAT relay.
  • XTAL32K Watchdog Timer (WDT)Trigger watchdog interrupt on external 32K crystal failure.

Ultra Low Power coprocessor (ULP)

Low-Power CPU (LP CORE)
  • Debug ULPDebug the LP Core in ESP32C6.
  • Echo ULPLeverage Zephyr's UART API to use the LP UART on the ESP32-C6's LP core.
  • Interrupt ULPHP Core interrupt LP Core.
  • LP GPIO WakeupLP Core wakes HP Core from deep sleep on LP GPIO level change.
  • LP Timer WakeupLP Core periodically wakes HP Core from deep sleep using LP timer.

Google

  • Power Delivery AnalyzerImplement a basic Power Delivery Analyzer to determine if a USB device is currently charging.

Infineon

Intel

Microchip

MEC15xxEVB Reference Board

Nordic Semiconductor

NXP

PHYTEC

reel board

QuickLogic

Raspberry Pi

Renesas

STMicroelectronics

Bluetooth

Board-specific STM32 samples

SensorTile.box
SensorTile.box Pro
STWIN.box
  • STWIN.box sensorsRead sensor data from the various STWIN SensorTile wireless industrial node sensors.

Power Management

PWM

  • STM32 pwm mastermodeDevicetree configuration for utilizing master/slave capabilities to synchronize timer instances.

UART

  • Single-wire UARTUse single-wire/half-duplex UART functionality of STM32 devices.
  • UART circular modeRead data from the console and echo it back using a circular DMA configuration.

Texas Instruments

C++

Data Structures

Drivers

ADC

Audio

Biometrics

  • Fingerprint sensorDemonstrate fingerprint sensor enrollment, verification, identification, and template management using the biometric driver API.

Buzzer

  • Buzzer TonePlay a short beep and a few tones through the buzzer device aliased as buzzer0.

Controller Area Network (CAN)

Clock Monitor

Counter

  • Counter AlarmImplement an alarm application using the counter API.

Ethernet

Firmware Samples

FPGA

  • FPGA ControllerLoad a bitstream into an FPGA and perform basic operations on it.

General Purpose I/O (GPIO)

Haptics

Inter-Integrated Circuit (I2C) Bus

I2S

Interrupt controller

Inter-Processor Mailbox (IPM)

  • IPM on ESP32Implement inter-processor mailbox (IPM) between ESP32 APP and PRO CPUs.
  • IPM on NXP i.MXImplement inter-processor mailbox (IPM) on i.MX SoCs containing a Messaging Unit peripheral.
  • IPM on NXP LPCImplement inter-processor mailbox (IPM) on NXP LPC family.
  • IPM over IVSHMEMImplement inter-processor mailbox (IPM) over IVSHMEM (Inter-VM shared memory)
  • IPM with ARM MHUImplement inter-processor mailbox (IPM) using an MHU (Message Handling Unit)

Light-Emitting Diode (LED)

Local Interconnect Network (LIN)

LoRa

  • LoRa duty cycleReceive LoRa packets using hardware RX duty cycling (wake-on-radio).
  • LoRa receiveReceive packets in both synchronous and asynchronous mode using the LoRa radio.
  • LoRa sendTransmit a preconfigured payload every second using the LoRa radio.

Miscellaneous

  • FT800Display various shapes and text using FT800 Embedded Video Engine.
  • Grove LCDDisplay an incrementing counter and change the backlight color.
  • TMC6460 Voltage ModeDrive a BLDC motor in open-loop voltage mode with a Trinamic TMC6460.

Modem

  • AT Command ClientCreate a bidirectional UART bridge between console and modem for AT command communication.
  • Hello hl78xx modem driverget & set basic hl78xx modem information & functionality with HL78XX modem APIs

Multi-bit SPI Bus (MSPI)

OPAMP

Pulse IO

PWM

SPI

  • SPI RTIO loopbackPerform SPI transfers between SPI controller and SPI target using RTIO.

Stepper

  • StepperRotate a stepper motor in 4 different modes.
  • TMC50XX stepperRotate a TMC50XX stepper motor and change velocity at runtime.
  • TMCM-3216 stepperControl a stepper motor using the ADI TMCM-3216 standalone stepper motor controller and driver board over RS485.

Universal Asynchronous Receiver-Transmitter (UART)

  • Native TTY UARTUse native TTY driver to send and receive data between two UART-to-USB bridge dongles.
  • UART ASYNC APIDemonstrate the use of the asynchronous API
  • UART echoRead data from the console and echo it back.
  • UART PassthroughPass data directly between the console and another UART interface.

Virtualization

  • IVSHMEM doorbellUse Inter-VM Shared Memory to exchange messages between two processes running on different operating systems.

1-Wire

  • 1-Wire scannerScan for 1-Wire devices and print their family ID and serial number.

Kernel and Scheduler

External modules

  • NanopbSerialize and deserialize structured data using the nanopb module.

CMSIS-DSP

LVGL

TensorFlow Lite for Microcontrollers

Networking

IoT Cloud

Network Ethernet

MCP (Model Context Protocol)

  • MCP Server Hello WorldThis code sample shows two very basic tool definitions to introduce users to the Zephyr MCP Server library.

OpenThread

Quality of Service

QUIC API

  • Echo client (QUIC)Implements a simple IPv4/IPv6 echo client using QUIC API and socket service API.
  • Echo server (QUIC)Implements a simple IPv4/IPv6 echo server using QUIC API and socket service API.

Sockets API

Wi-Fi

  • Wi-Fi AP-STA modeConfigure a Wi-Fi board to operate as both an Access Point (AP) and a Station (STA).
  • Wi-Fi provisioning over BLEReceive Wi-Fi credentials over a BLE GATT service and connect to the access point.
  • Wi-Fi shellTest Wi-Fi functionality using the Wi-Fi shell module.

PSA

Regulator

Sensors

Shields

X-NUCLEO-IKS01A2 shield

X-NUCLEO-IKS01A3 shield

X-NUCLEO-IKS02A1 shield

X-NUCLEO-IKS4A1 shield

Subsystems

Authentication

Binary Descriptor

Controller Area Network (CAN) Bus

  • ISO-TP libraryUse ISO-TP library to exchange messages between two boards.

Console

  • Console echoEcho an input character back to the output using the Console API.
  • console_getchar()Use console_getchar() to read an input character from the console.
  • console_getline()Use console_getline() to read an input line from the console.

CPU Freq

Debug

  • Debug MonitorConfigure the Debug Monitor feature on a Cortex-M processor.
  • FuzzingIntegrate fuzz testing with Zephyr apps.
  • UDP coredump via shellFault from the Zephyr shell; the coredump is mirrored as UART #CD: hex and framed UDP.

Display

File Systems

Input

Inter-Processor Communication (IPC)

Key-Value Storage Systems

Linkable Loadable Extensions (LLEXT)

Logging

LoRaWAN

Management

Modbus

Power Management

PMCI

MCTP

Portability

CMSIS RTOS v1

CMSIS RTOS v2

POSIX API

Profiling

  • Perf toolSend perf samples to the host with console support

Real Time I/O (RTIO)

Sensing

Shell

State Machine Framework

Test suites

Tracing

  • TracingGenerate kernel and application trace events and stream them to a host with any of the supported tracing formats and backends.
  • Tracing a sensor pipelineTrace a realistic multi-threaded sensor pipeline and use the trace to understand how the RTOS schedules it - and to spot a priority inversion.

USB

Legacy USB device support

USB-C device support

  • Basic USB-C DRPImplement a USB-C Power Delivery application in the form of a USB-C DRP (Dual Role Power).
  • Basic USB-C SinkImplement a USB-C Power Delivery application in the form of a USB-C Sink.
  • Basic USB-C SourceImplement a USB-C Power Delivery application in the form of a USB-C Source.

Video

zbus

Sysbuild

TF-M Integration

Userspace