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 theCMakeLists.txt
file, before including Zephyr’sboilerplate.cmake
file. (Recommended)Using a
boards/<BOARD>.overlay
file in thezephyr
folder, for the current boardUsing a
<BOARD>.overlay
file in thezephyr
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.
适配硬件¶
Frequency |
SRAM/Flash |
Vendor |
|||
---|---|---|---|---|---|
STM32F412ZGT6 |
100MHz |
256KB/1MB |
|||
STM32F723IEK6 |
216MHz |
192KB/512KB |
|||
STM32F446VET6 |
168MHz |
128KB/512KB |
|||
STM32G071RBT6 |
64MHz |
36KB/128KB |
|||
STM32G431RBT6 |
170MHz |
32KB/128KB |
|||
STM32G474RET6 |
170MHz |
512KB |
128KB |
||
STM32F411VET6 |
100MHz |
512KB |
128KB |
||
STM32F429ZIT6 |
180MHz |
2MB |
256KB |
||
STM32F469NIH6 |
180MHz |
1MB |
384KB |
||
STM32F746NGH6 |
216MHz |
1MB |
320KB |
||
STM32F769NIH6 |
216MHz |
1MB |
512KB |
||
STM32L476VGT6 |
80MHz |
1MB |
128KB |
||
STM32L496AGI6 |
80MHz |
1MB |
320KB |
||
STM32L475VGT6 |
80MHz |
1MB |
96KB |
||
STM32L072CZ |
32MHz |
192KB |
20KB |
||
STM32F072RBT6 |
48MHz |
128KB |
16KB |
||
STM32F030R8T6 |
48MHz |
64KB |
8KB |
||
STM32F031K6T6 |
48MHz |
32KB |
4KB |
||
STM32F070RBT6 |
48MHz |
128KB |
16KB |
||
STM32F091RCT6 |
48MHz |
256KB |
32KB |
||
STM32F103RBT6 |
72MHz |
128KB |
20KB |
||
STM32F207ZGT6 |
120MHz |
1MB |
128KB |
||
STM32F302R8T6 |
72MHz |
64KB |
16KB |
||
STM32F303K8T6 |
72MHz |
64KB |
12KB |
||
STM32F303RET6 |
72MHz |
512KB |
64KB |
||
STM32F334R8T6 |
72MHz |
64KB |
16KB |
||
STM32F401RET6 |
84MHz |
512KB |
96KB |
||
STM32F410RBT6 |
100MHz |
128KB |
32KB |
||
STM32F411RET6 |
100MHz |
512KB |
128KB |
||
STM32F412ZGT6 |
100MHz |
1MB |
256KB |
||
STM32F413ZHT6 |
100MHz |
512KB |
128KB |
||
STM32F429ZIT6 |
180MHz |
2MB |
192KB |
||
STM32F446RET6 |
180MHz |
512KB |
128KB |
||
STM32F446ZET6 |
180MHz |
512KB |
128KB |
||
STM32F746ZGT6 |
216MHz |
1MB |
320KB |
||
STM32F756ZG |
216MHz |
1MB |
320KB |
||
STM32F767ZIT6 |
216MHz |
2MB |
512KB |
||
STM32H723ZGT6 |
550MHz |
1MB |
432KB |
||
STM32H743ZIT6 |
400MHz |
2MB |
512KB |
||
STM32H745ZIT6 |
480MHz |
1MB |
512KB |
||
STM32H753ZIT6 |
400MHz |
2MB |
864KB |
||
STM32L011K4T6 |
32MHz |
16KB |
2KB |
||
STM32L031K6T6 |
32MHz |
32KB |
8KB |
||
STM32L053R8T6 |
32MHz |
64KB |
8KB |
||
STM32L073RZ |
32MHz |
192KB |
20KB |
||
STM32L412RBT6P |
80MHz |
128KB |
40KB |
||
STM32L432KCU6 |
80MHz |
256KB |
64KB |
||
STM32L433RC |
80MHz |
256KB |
64KB |
||
STM32L476RGT6 |
80MHz |
1MB |
96KB |
||
STM32L496ZGT6 |
80MHz |
1MB |
320KB |
||
STM32L4R5ZIT6 |
120MHz |
2MB |
640KB |
||
STM32WL55JC |
48MHz |
256KB |
64KB |
||
STM32F051R8T6 |
48MHz |
64KB |
8KB |
||
STM32F303VCT6 |
72MHz |
256KB |
40KB |
||
STM32F407VGT6 |
168MHz |
1MB |
128KB |
||
STM32G071RBT6 |
64MHz |
128KB |
36KB |
||
STM32H735IGK6 |
550MHz |
1MB |
432KB |
||
STM32H747XIH6 |
400MHz |
2MB |
512KB |
||
External |
STM32F412CG |
100MHz |
1MB |
256KB |
|
External |
STM32F427VIT6 |
168MHz |
1.99MB |
256KB |
|
External |
STM32F411CE |
100MHz |
512KB |
128KB |
|
External |
STM32F411CEU6 |
100MHz |
512KB |
128KB |
|
External |
STM32F401CEU6 |
84MHz |
512KB |
96KB |
|
External |
STM32F405RGT6 |
168MHz |
1MB |
128KB |
|
External |
STM32F407VET6 |
168MHz |
512KB |
128KB |
|
External |
STM32F407ZGT6 |
168MHz |
1MB |
128KB |
|
External |
STM32F103C8T6 |
72MHz |
64KB |
20KB |
|
External |
STM32F103C8T6 |
72MHz |
128KB |
20KB |
|
External |
STM32F103C8T6 |
72MHz |
64KB |
20KB |
|
External |
STM32F103C8T6 |
72MHz |
128KB |
20KB |
|
External |
STM32F103RBT6 |
72MHz |
128KB |
20KB |
|
External |
STM32F405RGT6 |
168MHz |
1MB |
128KB |
|
External |
STM32F401CCU6 |
84MHz |
256KB |
64KB |
|
External |
STM32F407ZGT6 |
168MHz |
1MB |
128KB |
|
External |
STM32F407ZGT6 |
168MHz |
1MB |
128KB |
|
External |
STM32F107VCT6 |
72MHz |
256KB |
64KB |
|
External |
STM32F373VCT6 |
72MHz |
256KB |
32KB |
|
External |
STM32F072VBT6 |
48MHz |
128KB |
16KB |
Frequency |
SRAM/Flash |
Vendor |
|||
---|---|---|---|---|---|
SAMD21G18A |
48MHz |
32KB/256KB |
|||
SAMR21G18A |
48MHz |
32KB/256KB |
|||
SAMD21J18A |
48MHz |
32KB/256KB |
|||
External |
SAMD21G18A |
48MHz |
32KB/256KB |
||
External |
SAMD51G19A |
120MHz |
192KB/512KB |
||
External |
SAMD21E18A |
48MHz |
32KB/256KB |
||
External |
AT91SAM3X8E |
84MHz |
96KB/512KB |
||
External |
SAMD21G18A |
48MHz |
32KB/256KB |
||
External |
SAMD21G18A |
48MHz |
32KB/256KB |
Frequency |
SRAM/Flash |
Vendor |
|||
---|---|---|---|---|---|
NRF52833 |
64MHz |
512KB |
128KB |
||
NRF52832 |
64MHz |
512KB |
64KB |
||
NRF52833 |
64MHz |
512KB |
128KB |
||
NRF52840 |
64MHz |
1MB |
256KB |
||
NRF52840 |
64MHz |
1MB |
256KB |
||
NRF52840 |
64MHz |
1MB |
256KB |
||
NRF52832 |
64MHz |
512KB |
64KB |
||
NRF52840 |
64MHz |
1MB |
256KB |
||
NRF52832 |
64MHz |
512KB |
64KB |
||
NRF52840 |
64MHz |
1MB |
256KB |
||
NRF52832 |
64MHz |
512KB |
64KB |
||
NRF52833 |
64MHz |
512KB |
128KB |
||
NRF52840 |
64MHz |
1MB |
256KB |
||
NRF52840 |
64MHz |
1MB |
256KB |
||
NRF52840 |
64MHz |
1MB |
256KB |
||
NRF52832 |
64MHz |
512KB |
64KB |
||
External |
NRF52832 |
64MHz |
512KB |
64KB |
|
External |
NRF52832 |
64MHz |
512KB |
64KB |
|
External |
NRF52840 |
64MHz |
796KB |
243KB |
|
External |
NRF52840 |
64MHz |
796KB |
232KB |
|
External |
NRF52832 |
64MHz |
512KB |
64KB |
|
External |
NRF52840 |
64MHz |
1MB |
256KB |
|
External |
NRF52832 |
64MHz |
512KB |
64KB |
|
External |
NRF52840 |
64MHz |
796KB |
243KB |
|
External |
NRF52840 |
64MHz |
796KB |
243KB |
|
External |
NRF52840 |
64MHz |
796KB |
243KB |
|
External |
NRF52832 |
64MHz |
512KB |
64KB |
Frequency |
SRAM/Flash |
Vendor |
|||
---|---|---|---|---|---|
NRF51822 |
16MHz |
256KB |
16KB |
||
NRF51822 |
16MHz |
128KB |
32KB |
||
NRF51822 |
16MHz |
256KB |
32KB |
||
NRF51822 |
32MHz |
256KB |
32KB |
||
NRF51822 |
32MHz |
256KB |
32KB |
||
External |
NRF51822 |
32MHz |
256KB |
32KB |
Frequency |
SRAM/Flash |
Vendor |
|||
---|---|---|---|---|---|
MK22FN512VLH12 |
120MHz |
512KB |
128KB |
||
MK64FN1M0VLL12 |
120MHz |
1MB |
256KB |
||
MK82FN256VLL15 |
150MHz |
256KB |
256KB |
||
MKL25Z128VLK4 |
48MHz |
128KB |
16KB |
||
MKW41Z512VHT4 |
48MHz |
512KB |
128KB |
||
External |
MKW24D512 |
50MHz |
512KB |
64KB |
|
External |
MK64FN1M0VDC12 |
120MHz |
1MB |
256KB |
|
External |
MK66FN2M0VMD18 |
180MHz |
2MB |
256KB |
Frequency |
SRAM/Flash |
Vendor |
|||
---|---|---|---|---|---|
FE310 |
320MHz |
16MB |
16KB |
||
FE310 |
320MHz |
16MB |
16KB |
Frequency |
SRAM/Flash |
Vendor |
|||
---|---|---|---|---|---|
LPC11U68 |
50MHz |
256KB |
36KB |
||
LPC54114J256BD64 |
100MHz |
256KB |
192KB |
||
LPC55S16 |
150MHz |
256KB |
96KB |
Frequency |
SRAM/Flash |
Vendor |
|||
---|---|---|---|---|---|
MIMXRT1011DAE5A |
500MHz |
128KB/64KB |
|||
MIMXRT1015DAF5A |
500MHz |
128KB/96KB |
|||
MIMXRT1021DAG5A |
500MHz |
32MB/8MB |
|||
MIMXRT1052DVL6B |
600MHz |
32MB/8MB |
|||
MIMXRT1062DVL6A |
600MHz |
8MB |
32MB |
||
MIMXRT1064DVL6A |
600MHz |
32MB/8MB |
|||
External |
IMXRT1062 |
600MHz |
512KB/1.94MB |
||
External |
IMXRT1062 |
600MHz |
512KB/7.75MB |
Frequency |
SRAM/Flash |
Vendor |
|||
---|---|---|---|---|---|
EFM32HG322F64 |
25MHz |
8KB/64KB |
|||
EFR32MG12P432F1024 |
40MHz |
256KB/1MB |
|||
EFM32WG990F256 |
48MHz |
32KB/256KB |
Frequency |
SRAM/Flash |
Vendor |
|||
---|---|---|---|---|---|
FE310 |
320MHz |
16KB/16MB |
|||
FE310 |
320MHz |
16KB/16MB |