1. 系统要求
- 操作系统:Windows 10/11(64位)
- 磁盘空间:至少 8GB 可用空间(Zephyr 及其工具链较大)
- 权限:管理员权限(部分工具需要)
2. 安装必要工具
winget安装依赖工具(Windows Package Manager)
以 管理员身份 打开 cmd.exe或者PowerShell,运行:
winget install Kitware.CMake Ninja-build.Ninja oss-winget.gperf python Git.Git oss-winget.dtc wget 7zip.7zip
windows安装包下载临时目录
C:\Users\Administrator\AppData\Local\Temp\WinGet
安装日志:
Microsoft Windows [版本 10.0.26100.4061]
(c) Microsoft Corporation。保留所有权利。C:\Users\Administrator>winget install Kitware.CMake Ninja-build.Ninja oss-winget.gperf python Git.Git oss-winget.dtc wget 7zip.7zip
找到已安装的现有包。正在尝试升级已安装的包...
找不到可用的升级。
配置的源中没有可用的较新的包版本。
已安装程序包: Kitware.CMake
找到已安装的现有包。正在尝试升级已安装的包...
找不到可用的升级。
配置的源中没有可用的较新的包版本。
已安装程序包: Ninja-build.Ninja
找到已安装的现有包。正在尝试升级已安装的包...
找不到可用的升级。
配置的源中没有可用的较新的包版本。
已安装程序包: oss-winget.gperf
找到已安装的现有包。正在尝试升级已安装的包...
找不到可用的升级。
配置的源中没有可用的较新的包版本。
已安装程序包: python
找到已安装的现有包。正在尝试升级已安装的包...
找不到可用的升级。
配置的源中没有可用的较新的包版本。
已安装程序包: Git.Git
找到已安装的现有包。正在尝试升级已安装的包...
找不到可用的升级。
配置的源中没有可用的较新的包版本。
已安装程序包: oss-winget.dtc
找到已安装的现有包。正在尝试升级已安装的包...
找不到可用的升级。
配置的源中没有可用的较新的包版本。
已安装程序包: wget
找到已安装的现有包。正在尝试升级已安装的包...
找不到可用的升级。
配置的源中没有可用的较新的包版本。
已安装程序包: 7zip.7zip
3. 获取Zephyr和安装Python依赖项
1. 使用普通用户打开cmd.exe
or PowerShell 终端
2. 创建新的虚拟环境
cd D:\workspace\
mkdir zephyrproject
python -m venv zephyrproject\.venv
3. 激活虚拟环境
zephyrproject\.venv\Scripts\activate.bat
4. 安装west
pip install west -i https://pypi.mirrors.ustc.edu.cn/simple/
5. 获取Zephyr源码
west init zephyr-project
cd zephyr-project
west update
west update日志
(.venv) D:\workspace\zephyrproject\zephyr-project>west update
=== updating acpica (modules/lib/acpica):
HEAD is now at 8d24867bc Merge pull request #5 from dcpleung/kernel/mm_z_phys_map_unmap_rename
=== updating cmsis (modules/hal/cmsis):
HEAD is now at d1b8b20 Backport CMSIS_6#102 to CMSIS 5.9.0
=== updating cmsis-dsp (modules/lib/cmsis-dsp):
HEAD is now at d80a49b2 do not generate warnings when scalar functions are used with MVE
=== updating cmsis-nn (modules/lib/cmsis-nn):
HEAD is now at e9328d6 manifest: zephyr module file
=== updating cmsis_6 (modules/hal/cmsis_6):
HEAD is now at 6dd50439 cmsis_6: Integrate with zephyr build system
=== updating edtt (tools/edtt):
HEAD is now at b9ca3c7 Fix for for python >= 3.11
=== updating fatfs (modules/fs/fatfs):
HEAD is now at 16245c7 fs: Update driver to version 0.15a
=== updating hal_adi (modules/hal/adi):
HEAD is now at f8f6547 chore(PeriphDrivers): Replace pow() with left shift in UART drivers
=== updating hal_afbr (modules/hal/afbr):
HEAD is now at 4e1eea7 general: MAKE_VERSION is defined in other modules so let's change it
=== updating hal_ambiq (modules/hal/ambiq):
HEAD is now at f46941f hal: uart: minor change for uart dma support
=== updating hal_atmel (modules/hal/atmel):
HEAD is now at ca7e4c6 sam3x: spi: missing adc macro
=== updating hal_bouffalolab (modules/hal/bouffalolab):
HEAD is now at 5811738 bflb: add register files for bl60x
=== updating hal_espressif (modules/hal/espressif):
HEAD is now at 1f1d6937f8 hal: esp32c6: Fix sleep routine
=== updating hal_ethos_u (modules/hal/ethos_u):
HEAD is now at 50ddffc Cache optimizations
=== updating hal_gigadevice (modules/hal/gigadevice):
HEAD is now at 2994b7d README.md: add pllmf and pack exception for gd32a50x
=== updating hal_infineon (modules/hal/infineon):
HEAD is now at 0fe4f3a hal: infineon: Modifications required to support XMC7200
=== updating hal_intel (modules/hal/intel):
HEAD is now at 0447cd2 Update pm_regs.h
=== updating hal_microchip (modules/hal/microchip):
HEAD is now at 4b74f40 hal: microchip: sam: Update some register definitions for FLEXCOM USART
=== updating hal_nordic (modules/hal/nordic):
HEAD is now at 4eafaa4 nrfs: usb vbus enable/disable: expand usb service
=== updating hal_nuvoton (modules/hal/nuvoton):
HEAD is now at be1042d hal:nuvoton:m55m1: support emac
=== updating hal_nxp (modules/hal/nxp):
HEAD is now at e0b43431 dts: nxp: nxp_imx: update the pinctrl dtsi for mimx9131cvvxj
=== updating hal_openisa (modules/hal/openisa):
HEAD is now at eabd530 fix-double-promotion in fsl_xcvr_trim
=== updating hal_quicklogic (modules/hal/quicklogic):
HEAD is now at bad8944 HAL: eoss3_dev: add missing `__cplusplus` handling
=== updating hal_renesas (modules/hal/renesas):
HEAD is now at 9d68ee7 portable: rp_crc: add runtime reconfigure for CRC
=== updating hal_rpi_pico (modules/hal/rpi_pico):
HEAD is now at 7b57b24 Merge pull request #8 from ajf58/merge-2.1.0
=== updating hal_silabs (modules/hal/silabs):
HEAD is now at a0095a7 wiseconnect: Apply 802.11ax config only in client mode
=== updating hal_st (modules/hal/st):
HEAD is now at 9f81b44 sensor/stmemsc: Align stmemsc i/f to v2.9.1
=== updating hal_stm32 (modules/hal/stm32):
HEAD is now at 5cbc642b dts: New batch with HSPI signals
=== updating hal_tdk (modules/hal/tdk):
HEAD is now at 6727477 Merge pull request #8 from tdk-invn-oss/main
=== updating hal_telink (modules/hal/telink):
HEAD is now at 4226c7f drivers: Disable BLE support
=== updating hal_ti (modules/hal/ti):
HEAD is now at bc8e7b9 hal: ti: mspm0: Add a support for MSPM0
=== updating hal_wch (modules/hal/wch):
HEAD is now at 6dd3137 hal: wch: update the HAL to pull in CH32V00x support
=== updating hal_wurthelektronik (modules/hal/wurthelektronik):
HEAD is now at e3e2797 Remove preprocessor warnings for not enabling float
=== updating hal_xtensa (modules/hal/xtensa):
HEAD is now at b38620c zephyr: Add SoC overlay for i.MXRT700 HiFi1 DSP
=== updating hostap (modules/lib/hostap):
HEAD is now at 8412f4b23 [noup] zephyr: remove zephyr wpas monitor socket pair
=== updating liblc3 (modules/lib/liblc3):
HEAD is now at 48bbd3e Rename lc3 python package to lc3py, and bump version to 1.1.2
=== updating libmctp (modules/lib/libmctp):
HEAD is now at b97860e build MCTP zephyr library only when CONFIG_MCTP is enabled
=== updating libmetal (modules/hal/libmetal):
HEAD is now at 14f5195 lib: update libmetal to SHA 9a21915a5f8f
=== updating littlefs (modules/fs/littlefs):
HEAD is now at 8f5ca34 Merge pull request #19 from mkaranki/update-to-v2.10.2
=== updating loramac-node (modules/lib/loramac-node):
HEAD is now at fb00b383 zephyr: configure FragDecoder using Kconfig
=== updating lvgl (modules/lib/gui/lvgl):
HEAD is now at 1ed1ddd88 docs(Alif): add docs for Alif chip vendor (#7622)
=== updating mbedtls (modules/crypto/mbedtls):
HEAD is now at 5f8899343 Merge pull request #70 from tomi-font/bump_to_3.6.3
=== updating mcuboot (bootloader/mcuboot):
HEAD is now at 990b1fcb docs: release-notes: Add additional fixes
=== updating mipi-sys-t (modules/debug/mipi-sys-t):
HEAD is now at 33e5c23 Fix for warning of potential error using = instead of ==
=== updating net-tools (tools/net-tools):
HEAD is now at 986bfeb Replace native_posix with native_sim
=== updating nrf_hw_models (modules/bsim_hw_models/nrf_hw_models):
HEAD is now at c6296f6 52/53 CCM: Remove warning on TASK_STOP
=== updating nrf_wifi (modules/lib/nrf_wifi):
HEAD is now at 0cd7f28 Fix delayed stats event handling
=== updating open-amp (modules/lib/open-amp):
HEAD is now at f7f4d08 lib: update open-amp lib to SHA 9a21915a5f8f
=== updating openthread (modules/lib/openthread):
HEAD is now at 3ae741f95 [instance] fix index computation in multi-instances context (#11099)
=== updating percepio (modules/debug/percepio):
HEAD is now at 49e6dc2 Merge branch 'main' into zephyr
=== updating picolibc (modules/lib/picolibc):
HEAD is now at 560946f26 Delete obsoleted _syslist.h
=== updating segger (modules/debug/segger):
HEAD is now at cf56b1d readme: Add readme
=== updating tinycrypt (modules/crypto/tinycrypt):
HEAD is now at 1012a3e Fix warnings reported by UBSAN
=== updating trusted-firmware-a (modules/tee/tf-a/trusted-firmware-a):
HEAD is now at 713ffbf96 Merge pull request #4 from ceolin/v2.10.4
=== updating trusted-firmware-m (modules/tee/tf-m/trusted-firmware-m):
HEAD is now at c150f4885 platform: ext: adi: pull in update from TF-M main
=== updating uoscore-uedhoc (modules/lib/uoscore-uedhoc):
HEAD is now at 54abc10 Merge pull request #5 from rlubos/upmerge-02-2025
=== updating zcbor (modules/lib/zcbor):
HEAD is now at 9b07780 Update version to 0.9.1
6. Export Zephyr package
west zephyr-export
7. 安装west python依赖包
# 使用国外镜像源比较慢
west packages pip --install
注意:永久切换pip使用国内镜像源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cnpip config list
# 恢复默认配置
pip config unset global.index-url
pip config unset global.trusted-host
常见镜像源地址
镜像名称 | URL |
清华大学 |
|
阿里云 |
|
腾讯云 |
|
华为云 |
|
4. 安装 Zephyr SDK
Zephyr SDK 包含编译工具链(如 GCC ARM 工具链)。
(1) 下载 SDK
从 Zephyr SDK 官方页面 下载最新版(如 zephyr-sdk-0.17.1_windows-x86_64.7z
)。
(2) 解压并安装
1. 解压到 D:\workspace\zephyrproject\zephyr-sdk\zephyr-sdk-0.17.1
(路径不要有空格或中文)。
以管理员身份运行解压目录中的 setup.cmd
:
cd D:\workspace\zephyrproject\zephyr-sdk\zephyr-sdk-0.17.1
.\setup.cmd
2. 按提示输入 Y
同意安装。
验证安装
(1) 检查环境
west --version
cmake --version
ninja --version
python --version# 所有命令应正常输出版本号
(.venv) D:\workspace\zephyrproject\zephyr-project\zephyr>west --version
West version: v1.4.0(.venv) D:\workspace\zephyrproject\zephyr-project\zephyr>cmake --version
cmake version 4.0.2CMake suite maintained and supported by Kitware (kitware.com/cmake).(.venv) D:\workspace\zephyrproject\zephyr-project\zephyr>ninja --version
1.12.1(.venv) D:\workspace\zephyrproject\zephyr-project\zephyr>python --version
Python 3.10.11
(2) 编译示例项目
cd D:\workspace\zephyrproject\zephyr-project\zephyr
west build -b blackpill_f401cc samples/hello_world
-b blackpill_f401cc
:指定 Black Pill STM32F401CC 开发板- 首次编译会下载工具链和依赖,耗时较长。
(3) 烧录与调试
west flash --runner blackmagicprobe --gdb-serial "\\.\COM12"
west debug --runner blackmagicprobe --gdb-serial "\\.\COM12"
west attach --runner blackmagicprobe --gdb-serial "\\.\COM12"west flash --runner blackmagicprobe --gdb-serial "\\.\COM12"
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner blackmagicprobe
-- runners.blackmagicprobe: using GDB serial: \\.\COM12
Remote debugging using \\.\COM12
Target voltage: 2.51V
Available Targets:
No. Att Driver
1 STM32F401E M4
Attaching to Remote target
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x08002d22 in ?? ()
Loading section rom_start, size 0x194 lma 0x8000000
Loading section text, size 0x367c lma 0x8000194
Loading section .ARM.exidx, size 0x8 lma 0x8003810
Loading section initlevel, size 0x80 lma 0x8003818
Loading section device_area, size 0x180 lma 0x8003898
Loading section sw_isr_table, size 0x2a8 lma 0x8003a18
Loading section gpio_driver_api_area, size 0x24 lma 0x8003cc0
Loading section reset_driver_api_area, size 0x10 lma 0x8003ce4
Loading section clock_control_driver_api_area, size 0x1c lma 0x8003cf4
Loading section uart_driver_api_area, size 0x4c lma 0x8003d10
Loading section rodata, size 0x2d4 lma 0x8003d5c
Loading section datas, size 0x4c lma 0x8004030
Loading section device_states, size 0x18 lma 0x800407c
Loading section .last_section, size 0x4 lma 0x8004094
Start address 0x080008c4, load size 16536
Transfer rate: 23 KB/sec, 590 bytes/write.
[Inferior 1 (Remote target) killed]west debug --runner blackmagicprobe --gdb-serial "\\.\COM12"
-- west debug: rebuilding
ninja: no work to do.
-- west debug: using runner blackmagicprobe
-- runners.blackmagicprobe: using GDB serial: \\.\COM12
GNU gdb (Zephyr SDK 0.17.1) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-host_w64-mingw32 --target=arm-zephyr-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://github.com/zephyrproject-rtos/sdk-ng/issues>.
Find the GDB manual and other documentation resources online at:<http://www.gnu.org/software/gdb/documentation/>.For help, type "help".
Type "apropos word" to search for commands related to "word".
Remote debugging using \\.\COM12
Target voltage: 2.44V
Available Targets:
No. Att Driver1 STM32F401E M4
Attaching to Remote target
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x08002d22 in ?? ()
Reading symbols from D:/workspace/zephyrproject/zephyr-project/zephyr/build/zephyr/zephyr.elf...
Loading section rom_start, size 0x194 lma 0x8000000
Loading section text, size 0x367c lma 0x8000194
Loading section .ARM.exidx, size 0x8 lma 0x8003810
Loading section initlevel, size 0x80 lma 0x8003818
Loading section device_area, size 0x180 lma 0x8003898
Loading section sw_isr_table, size 0x2a8 lma 0x8003a18
Loading section gpio_driver_api_area, size 0x24 lma 0x8003cc0
Loading section reset_driver_api_area, size 0x10 lma 0x8003ce4
Loading section clock_control_driver_api_area, size 0x1c lma 0x8003cf4
Loading section uart_driver_api_area, size 0x4c lma 0x8003d10
Loading section rodata, size 0x2d4 lma 0x8003d5c
--Type <RET> for more, q to quit, c to continue without paging--
Loading section datas, size 0x4c lma 0x8004030
Loading section device_states, size 0x18 lma 0x800407c
Loading section .last_section, size 0x4 lma 0x8004094
Start address 0x080008c4, load size 16536
Transfer rate: 6 KB/sec, 590 bytes/write.west attach --runner blackmagicprobe --gdb-serial "\\.\COM12"
-- west attach: rebuilding
ninja: no work to do.
-- west attach: using runner blackmagicprobe
-- runners.blackmagicprobe: using GDB serial: \\.\COM12
GNU gdb (Zephyr SDK 0.17.1) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-host_w64-mingw32 --target=arm-zephyr-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://github.com/zephyrproject-rtos/sdk-ng/issues>.
Find the GDB manual and other documentation resources online at:<http://www.gnu.org/software/gdb/documentation/>.For help, type "help".
Type "apropos word" to search for commands related to "word".
Remote debugging using \\.\COM12
Target voltage: 2.53V
Available Targets:
No. Att Driver1 STM32F401E M4
Attaching to Remote target
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x08002d22 in ?? ()
Reading symbols from D:/workspace/zephyrproject/zephyr-project/zephyr/build/zephyr/zephyr.elf...
(gdb)
如果看到 Hello World! zephyr
输出,说明环境搭建成功!
这里主要使用的是开源调试器Black Magic Debug,Black Magic Debug自带Debug口和串口,使用windows命令行请注意:
COM 端口号过高(> COM9)
- 问题原因:Windows 对
COM
端口号的命名规则有特殊限制:
-
COM1
~COM9
是传统端口,可直接以COMx
形式访问。COM10
及以上的端口属于扩展端口,需通过\\.\COMx
格式访问(例如\\.\COM12
)。