Zephyr

RTOS Apache 2.0 2016

Zephyr 项目是Linux基金会托管的开源项目。为所有资源受限设备,构建了针对低功耗、小型内存微处理器设备而进行优化的物联网嵌入式小型、可扩展的实时操作系统(RTOS),支持多种硬件架构及多种开发板,可以在小至8 kB内存的系统上运行。 采用深入的安全开发生命周期:安全验证,模糊和渗透测试,频繁的代码审查,静态代码分析,威胁建模和审查,以防止代码中的后门 。

入门指南

工程结构

Warning

Zephyr framework currently requires Python 3.4 or later.

Zephyr framework requires an unusual project structure because most of the framework configuration is performed by the native for Zephyr build system called CMake.

Note

Since PIO is able to generate CMake-based projects for certain IDEs, Zephyr-related files are moved to a separate folder in order to avoid conflicts between project files. That requires users to specify relative paths to source files in CMakeLists.txt.

A typical PIO project for Zephyr framework must have the following structure:

project_dir
├── include
├── src
│    └── main.c
├── zephyr
│    ├── prj.conf
│    └── CMakeLists.txt
└── platformio.ini

Besides files related to PIO project, there is an additional folder zephyr that contains Zephyr-specific files CMakeLists.txt and prj.conf:

CMakeLists.txt file enables features supported by Zephyr’s build system, e.g. board-specific kernel configuration files. A typical CMakeLists.txt file has the following content:

# Boilerplate code, which pulls in the Zephyr build system.
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(my_zephyr_app)

# Add your source file to the "app" target. This must come after the boilerplate
# code, which defines the target. Note relative path to source file
target_sources(app PRIVATE ../src/main.c)

The files specified in target_sources are used ONLY for generating build configurations, but it’s highly recommended to specify all application source files in order to keep the project compatible with the usual Zephyr workflow.

Due to the current limitations of CMake file-based API, there is no way to generate build configuration for source files written in various programming languages if they are not specified in target_sources command. If your project contains libraries written in languages that differ from the language used for the main application you need to create an empty file with desired extension (e.g. *.cpp for C++) in order to force CMake generate build configuration for this language.

Note

Build configuration generated for source files specified in target_sources is also used as the base build environment for project sources (including libraries).

prj.conf file sets application-specific values for one or more kernel configuration options. These application settings are merged with board-specific settings to produce a kernel configuration.

设备树堆叠

Device Tree Overlays DTO

Zephyr applications can use overlay files to enable a peripheral that is disabled by default, select a sensor on the board for an application specific purpose, etc. This makes it possible to reconfigure the kernel and device drivers without modifying source code. There are several ways to set .overlay files:

  • Using DTC_OVERLAY_FILE variable in the CMakeLists.txt file, before including Zephyr’s boilerplate.cmake file. (Recommended)

  • Using a boards/<BOARD>.overlay file in the zephyr folder, for the current board

  • Using a <BOARD>.overlay file in the zephyr folder.

Warning

PIO board names may differ from Zephyr targets, which means that to help the build system automatically pick up .overlay file, the <BOARD> name in <BOARD>.overlay file must have the same name as specified in the official Zephyr board list.

文件嵌入

In case your CMakeLists.txt relies on using generate_inc_* functions that are used for generating and compressing individual files (for example certificates for secure connections) you need to configure your PIO project accordingly using the following structure:

[env:myenv]
platform = ...
board = ...
framework = zephyr
board_build.embed_files =
    # files to be embedded
    src/apps-cert.der
    src/apps-key.der

Where apps-cert.der and apps-key.der are the files you want to embed to your project at the compile time.

模块组件

Note

PIO automatically installs several default modules used with Zephyr framework including modules that implement silicon vendor Hardware Abstraction Layers (HALs).

Zephyr modules are externally maintained packages that allow using well-established and mature code created by third party developers.

These modules contain either a single module.yml file or CMakeLists.txt and Kconfig files that describe how to build and configure them. You can specify paths to additional directories with source code, Kconfig, etc. using ZEPHYR_EXTRA_MODULES at the top of your project’s CMakeLists.txt file, for example:

# Additional modules
set(ZEPHYR_EXTRA_MODULES "path/to-zephyr-custom-module"  [...])

# Boilerplate code, which pulls in the Zephyr build system.
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(my_zephyr_app)

# Add your source file to the "app" target. This must come after
# the boilerplate code, which defines the target.
target_sources(app PRIVATE ../src/main.c)

Since the build may not work correctly if the full path to sources is greater than 250 characters (see CMAKE_OBJECT_PATH_MAX) it might be a good idea to keep modules close to the project configuration files (e.g. in zephyr folder) in form of a git submodule.

Warning

Make sure the ZEPHYR_EXTRA_MODULES variable is set before including the boilerplate file, as shown above.

注意事项

At the moment several limitations are present:

  • The minimum supported version of Python is 3.4

  • No whitespace characters allowed in project paths.

  • The Trusted Firmware M module is not supported

开发示例

调试工具

Debugging - “1-click” solution for debugging with a zero configuration.

Supported debugging tools are listed in “Debug” column. For more detailed information, please scroll table by horizontal. You can switch between debugging Tools & Debug Probes using debug_tool option in “platformio.ini” (Project Configuration File).

Warning

You will need to install debug tool drivers depending on your system. Please click on compatible debug tool below for the further instructions.

适配硬件

Boards

Debugging

STM32

Frequency

SRAM/Flash

Vendor

32F412GDISCOVERY

ST-LINK

STM32F412ZGT6

100MHz

256KB/1MB

32F723EDISCOVERY

ST-LINK

STM32F723IEK6

216MHz

192KB/512KB

96Boards B96B-F446VE

ST-LINK

STM32F446VET6

168MHz

128KB/512KB

Nucleo G071RB

ST-LINK

STM32G071RBT6

64MHz

36KB/128KB

Nucleo G431RB

ST-LINK

STM32G431RBT6

170MHz

32KB/128KB

Nucleo G474RE

ST-LINK

STM32G474RET6

170MHz

512KB

128KB

ST 32F411EDISCOVERY

ST-LINK

STM32F411VET6

100MHz

512KB

128KB

ST 32F429IDISCOVERY

ST-LINK

STM32F429ZIT6

180MHz

2MB

256KB

ST 32F469IDISCOVERY

ST-LINK

STM32F469NIH6

180MHz

1MB

384KB

ST 32F746GDISCOVERY

ST-LINK

STM32F746NGH6

216MHz

1MB

320KB

ST 32F769IDISCOVERY

ST-LINK

STM32F769NIH6

216MHz

1MB

512KB

ST 32L476GDISCOVERY

ST-LINK

STM32L476VGT6

80MHz

1MB

128KB

ST 32L496GDISCOVERY

ST-LINK

STM32L496AGI6

80MHz

1MB

320KB

ST B-L475E-IOT01A Discovery kit

ST-LINK

STM32L475VGT6

80MHz

1MB

96KB

ST DISCO-L072CZ-LRWAN1

ST-LINK

STM32L072CZ

32MHz

192KB

20KB

ST Discovery F072RB

ST-LINK

STM32F072RBT6

48MHz

128KB

16KB

ST Nucleo F030R8

ST-LINK

STM32F030R8T6

48MHz

64KB

8KB

ST Nucleo F031K6

ST-LINK

STM32F031K6T6

48MHz

32KB

4KB

ST Nucleo F070RB

ST-LINK

STM32F070RBT6

48MHz

128KB

16KB

ST Nucleo F091RC

ST-LINK

STM32F091RCT6

48MHz

256KB

32KB

ST Nucleo F103RB

ST-LINK

STM32F103RBT6

72MHz

128KB

20KB

ST Nucleo F207ZG

ST-LINK

STM32F207ZGT6

120MHz

1MB

128KB

ST Nucleo F302R8

ST-LINK

STM32F302R8T6

72MHz

64KB

16KB

ST Nucleo F303K8

ST-LINK

STM32F303K8T6

72MHz

64KB

12KB

ST Nucleo F303RE

ST-LINK

STM32F303RET6

72MHz

512KB

64KB

ST Nucleo F334R8

ST-LINK

STM32F334R8T6

72MHz

64KB

16KB

ST Nucleo F401RE

ST-LINK

STM32F401RET6

84MHz

512KB

96KB

ST Nucleo F410RB

ST-LINK

STM32F410RBT6

100MHz

128KB

32KB

ST Nucleo F411RE

ST-LINK

STM32F411RET6

100MHz

512KB

128KB

ST Nucleo F412ZG

ST-LINK

STM32F412ZGT6

100MHz

1MB

256KB

ST Nucleo F413ZH

ST-LINK

STM32F413ZHT6

100MHz

512KB

128KB

ST Nucleo F429ZI

ST-LINK

STM32F429ZIT6

180MHz

2MB

192KB

ST Nucleo F446RE

ST-LINK

STM32F446RET6

180MHz

512KB

128KB

ST Nucleo F446ZE

ST-LINK

STM32F446ZET6

180MHz

512KB

128KB

ST Nucleo F746ZG

ST-LINK

STM32F746ZGT6

216MHz

1MB

320KB

ST Nucleo F756ZG

ST-LINK

STM32F756ZG

216MHz

1MB

320KB

ST Nucleo F767ZI

ST-LINK

STM32F767ZIT6

216MHz

2MB

512KB

ST Nucleo H723ZG

ST-LINK

STM32H723ZGT6

550MHz

1MB

432KB

ST Nucleo H743ZI

ST-LINK

STM32H743ZIT6

400MHz

2MB

512KB

ST Nucleo H745ZI-Q

ST-LINK

STM32H745ZIT6

480MHz

1MB

512KB

ST Nucleo H753ZI

ST-LINK

STM32H753ZIT6

400MHz

2MB

864KB

ST Nucleo L011K4

ST-LINK

STM32L011K4T6

32MHz

16KB

2KB

ST Nucleo L031K6

ST-LINK

STM32L031K6T6

32MHz

32KB

8KB

ST Nucleo L053R8

ST-LINK

STM32L053R8T6

32MHz

64KB

8KB

ST Nucleo L073RZ

ST-LINK

STM32L073RZ

32MHz

192KB

20KB

ST Nucleo L412RB-P

ST-LINK

STM32L412RBT6P

80MHz

128KB

40KB

ST Nucleo L432KC

ST-LINK

STM32L432KCU6

80MHz

256KB

64KB

ST Nucleo L433RC-P

ST-LINK

STM32L433RC

80MHz

256KB

64KB

ST Nucleo L476RG

ST-LINK

STM32L476RGT6

80MHz

1MB

96KB

ST Nucleo L496ZG

ST-LINK

STM32L496ZGT6

80MHz

1MB

320KB

ST Nucleo L4R5ZI

ST-LINK

STM32L4R5ZIT6

120MHz

2MB

640KB

ST Nucleo WL55JC

ST-LINK

STM32WL55JC

48MHz

256KB

64KB

ST STM32F0DISCOVERY

ST-LINK

STM32F051R8T6

48MHz

64KB

8KB

ST STM32F3DISCOVERY

ST-LINK

STM32F303VCT6

72MHz

256KB

40KB

ST STM32F4DISCOVERY

ST-LINK

STM32F407VGT6

168MHz

1MB

128KB

ST STM32G071B Discovery

ST-LINK

STM32G071RBT6

64MHz

128KB

36KB

STM32H735G-DK Discovery kit

ST-LINK

STM32H735IGK6

550MHz

1MB

432KB

STM32H747I-DISCO

ST-LINK

STM32H747XIH6

400MHz

2MB

512KB

96Boards Argonkey (STEVAL-MKI187V1)

External

STM32F412CG

100MHz

1MB

256KB

96Boards Neonkey

External

STM32F427VIT6

168MHz

1.99MB

256KB

96Boards Neonkey

External

STM32F411CE

100MHz

512KB

128KB

WeAct Studio BlackPill V2.0 (STM32F411CE)

External

STM32F411CEU6

100MHz

512KB

128KB

WeAct Studio BlackPill V3.0 (STM32F401CE)

External

STM32F401CEU6

84MHz

512KB

96KB

Adafruit Feather STM32F405

External

STM32F405RGT6

168MHz

1MB

128KB

Black STM32F407VE

External

STM32F407VET6

168MHz

512KB

128KB

Black STM32F407ZG

External

STM32F407ZGT6

168MHz

1MB

128KB

BlackPill F103C8

External

STM32F103C8T6

72MHz

64KB

20KB

BlackPill F103C8 (128k)

External

STM32F103C8T6

72MHz

128KB

20KB

BluePill F103C8

External

STM32F103C8T6

72MHz

64KB

20KB

BluePill F103C8 (128k)

External

STM32F103C8T6

72MHz

128KB

20KB

OLIMEXINO-STM32

External

STM32F103RBT6

72MHz

128KB

20KB

Olimex STM32-P405

External

STM32F405RGT6

168MHz

1MB

128KB

STEVAL-FCU001V1 Flight controller unit evaluation board

External

STM32F401CCU6

84MHz

256KB

64KB

STM32-E407

External

STM32F407ZGT6

168MHz

1MB

128KB

STM32-H407

External

STM32F407ZGT6

168MHz

1MB

128KB

STM3210C-EVAL

External

STM32F107VCT6

72MHz

256KB

64KB

STM32373C-EVAL

External

STM32F373VCT6

72MHz

256KB

32KB

STM32F072-EVAL

External

STM32F072VBT6

48MHz

128KB

16KB

Boards

Debugging

Atmel SAM

Frequency

SRAM/Flash

Vendor

Arduino Zero (Programming/Debug Port)

CMSIS-DAP

SAMD21G18A

48MHz

32KB/256KB

Atmel ATSAMR21-XPRO

CMSIS-DAP

SAMR21G18A

48MHz

32KB/256KB

Atmel SAMD21-XPRO

CMSIS-DAP

SAMD21J18A

48MHz

32KB/256KB

Adafruit Feather M0

External

SAMD21G18A

48MHz

32KB/256KB

Adafruit ItsyBitsy M4

External

SAMD51G19A

120MHz

192KB/512KB

Adafruit Trinket M0

External

SAMD21E18A

48MHz

32KB/256KB

Arduino Due (Programming Port)

External

AT91SAM3X8E

84MHz

96KB/512KB

NANO 33 IoT

External

SAMD21G18A

48MHz

32KB/256KB

Seeeduino XIAO

External

SAMD21G18A

48MHz

32KB/256KB

Boards

Debugging

Nordic nRF52

Frequency

SRAM/Flash

Vendor

BBC micro:bit V2

CMSIS-DAP

NRF52833

64MHz

512KB

128KB

BL652 Development Kit

CMSIS-DAP

NRF52832

64MHz

512KB

64KB

BL653 Development Kit

CMSIS-DAP

NRF52833

64MHz

512KB

128KB

BL654 Development Kit

CMSIS-DAP

NRF52840

64MHz

1MB

256KB

ElectronutLabs Blip

CMSIS-DAP

NRF52840

64MHz

1MB

256KB

ElectronutLabs Papyr

CMSIS-DAP

NRF52840

64MHz

1MB

256KB

VNG VBLUno52

CMSIS-DAP

NRF52832

64MHz

512KB

64KB

u-blox BMD-345-EVAL

CMSIS-DAP

NRF52840

64MHz

1MB

256KB

Makerdiary nRF52832-MDK

CMSIS-DAP

NRF52832

64MHz

512KB

64KB

Makerdiary nRF52840-MDK

CMSIS-DAP

NRF52840

64MHz

1MB

256KB

Nordic nRF52-DK

CMSIS-DAP

NRF52832

64MHz

512KB

64KB

Nordic nRF52833-DK

CMSIS-DAP

NRF52833

64MHz

512KB

128KB

Nordic nRF52840-DK

CMSIS-DAP

NRF52840

64MHz

1MB

256KB

PHYTEC reel board

CMSIS-DAP

NRF52840

64MHz

1MB

256KB

PHYTEC reel board v2

CMSIS-DAP

NRF52840

64MHz

1MB

256KB

RedBearLab BLE Nano 2

CMSIS-DAP

NRF52832

64MHz

512KB

64KB

96Boards Nitrogen

External

NRF52832

64MHz

512KB

64KB

Adafruit Bluefruit nRF52832 Feather

External

NRF52832

64MHz

512KB

64KB

Adafruit Feather nRF52840 Express

External

NRF52840

64MHz

796KB

243KB

Adafruit LED Glasses Driver nRF52840

External

NRF52840

64MHz

796KB

232KB

Holyiot YJ-16019

External

NRF52832

64MHz

512KB

64KB

Laird Connectivity Pinnacle 100 DVK

External

NRF52840

64MHz

1MB

256KB

Nordic Thingy:52 (nRF52-PCA20020)

External

NRF52832

64MHz

512KB

64KB

Particle Argon

External

NRF52840

64MHz

796KB

243KB

Particle Boron

External

NRF52840

64MHz

796KB

243KB

Particle Xenon

External

NRF52840

64MHz

796KB

243KB

Ruuvi Tag

External

NRF52832

64MHz

512KB

64KB

Boards

Debugging

Nordic nRF51

Frequency

SRAM/Flash

Vendor

BBC micro:bit

CMSIS-DAP

NRF51822

16MHz

256KB

16KB

VNG VBLUNO51

CMSIS-DAP

NRF51822

16MHz

128KB

32KB

RedBearLab BLE Nano 1.5

CMSIS-DAP

NRF51822

16MHz

256KB

32KB

Nordic nRF51 Dongle (PCA10031)

CMSIS-DAP

NRF51822

32MHz

256KB

32KB

Nordic nRF51X22 Development Kit(PCA1000X)

CMSIS-DAP

NRF51822

32MHz

256KB

32KB

Waveshare BLE400

External

NRF51822

32MHz

256KB

32KB

Boards

Debugging

Freescale Kinetis

Frequency

SRAM/Flash

Vendor

Freescale Kinetis FRDM-K22F

CMSIS-DAP

MK22FN512VLH12

120MHz

512KB

128KB

Freescale Kinetis FRDM-K64F

CMSIS-DAP

MK64FN1M0VLL12

120MHz

1MB

256KB

Freescale Kinetis FRDM-K82F

CMSIS-DAP

MK82FN256VLL15

150MHz

256KB

256KB

Freescale Kinetis FRDM-KL25Z

CMSIS-DAP

MKL25Z128VLK4

48MHz

128KB

16KB

Freescale Kinetis FRDM-KW41Z

CMSIS-DAP

MKW41Z512VHT4

48MHz

512KB

128KB

Freescale Kinetis FRDM-KW24D512

External

MKW24D512

50MHz

512KB

64KB

Hexiwear

External

MK64FN1M0VDC12

120MHz

1MB

256KB

SEGGER IP Switch Board

External

MK66FN2M0VMD18

180MHz

2MB

256KB

Boards

Debugging

SiFive

Frequency

SRAM/Flash

Vendor

HiFive1

FTDI Chip

FE310

320MHz

16MB

16KB

HiFive1 Rev B

J-LINK

FE310

320MHz

16MB

16KB

Boards

Debugging

NXP LPC

Frequency

SRAM/Flash

Vendor

LPCXpresso11U68

CMSIS-DAP

LPC11U68

50MHz

256KB

36KB

NXP LPCXpresso54114

CMSIS-DAP

LPC54114J256BD64

100MHz

256KB

192KB

NXP LPCXpresso55S16

CMSIS-DAP

LPC55S16

150MHz

256KB

96KB

Boards

Debugging

NXP i.MX RT

Frequency

SRAM/Flash

Vendor

NXP i.MX RT1010 Evaluation Kit

J-LINK

MIMXRT1011DAE5A

500MHz

128KB/64KB

NXP i.MX RT1015 Evaluation Kit

J-LINK

MIMXRT1015DAF5A

500MHz

128KB/96KB

NXP i.MX RT1020 Evaluation Kit

J-LINK

MIMXRT1021DAG5A

500MHz

32MB/8MB

NXP i.MX RT1050 Evaluation Kit

J-LINK

MIMXRT1052DVL6B

600MHz

32MB/8MB

NXP i.MX RT1060 Evaluation Kit

J-LINK

MIMXRT1062DVL6A

600MHz

8MB

32MB

NXP i.MX RT1064 Evaluation Kit

J-LINK

MIMXRT1064DVL6A

600MHz

32MB/8MB

Teensy 4.0

External

IMXRT1062

600MHz

512KB/1.94MB

Teensy 4.1

External

IMXRT1062

600MHz

512KB/7.75MB

Boards

Debugging

Silicon Labs EFM32

Frequency

SRAM/Flash

Vendor

SLSTK3400A USB-enabled Happy Gecko

J-LINK

EFM32HG322F64

25MHz

8KB/64KB

Thunderboard Sense 2 Sensor-to-Cloud Advanced IoT

J-LINK

EFR32MG12P432F1024

40MHz

256KB/1MB

EFM32WG-STK3800 Wonder Gecko

J-LINK

EFM32WG990F256

48MHz

32KB/256KB

Boards

Debugging

SiFive

Frequency

SRAM/Flash

Vendor

SparkFun RED-V RedBoard

J-LINK

FE310

320MHz

16KB/16MB

SparkFun RED-V Thing Plus

J-LINK

FE310

320MHz

16KB/16MB