zephyr笔记 1.2 软件开发环境准备

1 前言

我正在学习 Zephyr,一个很可能会用到很多物联网设备上的操作系统,如果你也感兴趣,可点此查看帖子zephyr学习笔记汇总。

2 概述

Zephyr 项目使用 CMake 来管理项目编译,CMake 可以产生不同格式的编译所需文件,我们称之为生成器文件,这些文件支持 ninja 和 make 编译。

  • make: Supported on UNIX-like platforms (Linux, macOS).
  • ninja: Supported on all platforms.

大多数 Zephyr 文档中都是使用 ninja 来作为编译工具,但其实可以用其他方式来使用生成器文件。

Zephyr 开发支持如下3个操作系统:

巧的是,在前几天,3月7日那天 Zephyr 刚发布 1.11 版本,宣布支持 windows 开发。本尊可以不打开虚拟机,还是很开心。

Development Environment Setup on Linux
Development Environment Setup on macOS
Development Environment Setup on Windows

3 windows 开发环境搭建

在Windows上的开发环境搭建,主要使用推荐的第一种方式Using Windows Command Prompt (Recommended, fastest)。

这是在windows命令行利用 Chocolatey 包管理工具。

1.If you’re behind a corporate firewall, you’ll likely need to specify a proxy to get access to internet resources:

set HTTP_PROXY=http://user:[email protected]:1234
set HTTPS_PROXY=http://user:[email protected]:1234

2.Install Chocolatey by following the instructions on the Chocolatey install website.

3.Open a Command Prompt (cmd.exe) as an Administrator.

TwoWinter注:一定要是管理员权限才行,否则会报错。

4.Optionally disable global confirmation to avoid having to add -y to all commands:

choco feature enable -n allowGlobalConfirmation

5.Install CMake:

choco install cmake –installargs ‘ADD_CMAKE_TO_PATH=System’

6.Install the rest of the tools:

choco install git python ninja dtc-msys2 gperf

7.Close the Command Prompt window.

8.Open a Command Prompt (cmd.exe) as a regular user.

9.Clone a copy of the Zephyr source into your home directory using Git.

cd %userprofile%
git clone https://github.com/zephyrproject-rtos/zephyr.git

10.Install the required Python modules:

cd %userprofile%\zephyr
pip install –user -r scripts/requirements.txt

如果你安装中发现 pyyaml 出错,提示类似这样的错误:

Exception:
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
    return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 72: invalid continuation byte

那就是命令行工具的标准输出流编码不对,我们可以使用chcp命令,更改代码页为65001(UTF-8)再执行pip安装命令即可。

chcp 65001
pip install pyyaml

这样就安装成功了。

chcp 936

记得再切换回默认的GBK,不然后面编译会出错。

11.If you require pyocd, an open source python2 library for programming and debugging ARM Cortex-M microcontrollers, use this command:

pip2 install –user -r scripts/py2-requirements.txt

12.The build system should now be ready to work with any toolchain installed in your system. In the next step you’ll find instructions for installing toolchains for building both x86 and ARM applications.

到目前为止已经差不多了,剩余 工具链 待安装。

13.Install cross compiler toolchain:

  • For x86, install the 2017 Windows host ISSM toolchain from the Intel Developer Zone: ISSM Toolchain. Use your web browser to download the toolchain’s tar.gz file. You can then use 7-Zip or a similar tool to extract it into a destination folder.
Note
The ISSM toolset only supports development for Intel® Quark™ Microcontrollers, for example, the Arduino 101 board. (Check out the “Zephyr Development Environment Setup” in this Getting Started on Arduino 101 with ISSM document.) Additional setup is required to use the ISSM GUI for development.
  • For ARM, install GNU ARM Embedded from the ARM developer website: GNU ARM Embedded (install to c:\gccarmemb).

咱们搞ARM,那就下载GNU ARM 编译器,安装到指定位置 c:\gccarmemb。

14.Within the Command Prompt, set up environment variables for the installed tools and for the Zephyr environment:

For x86:

set ZEPHYR_TOOLCHAIN_VARIANT=issm
set ISSM_INSTALLATION_PATH=c:\issm0-toolchain-windows-2017-01-25

Use the path where you extracted the ISSM toolchain.

For ARM:

set ZEPHYR_TOOLCHAIN_VARIANT=gccarmemb
set GCCARMEMB_TOOLCHAIN_PATH=c:\gccarmemb

To use the same toolchain in new sessions in the future you can set the variables in a .cmd file and run that every time you open a new Command Prompt.

And for either, run the zephyr-env.cmd file in order to set the ZEPHYR_BASE environment variable:

zephyr-env.cmd

15.Finally, you can try building the Hello World sample to check things out.

To build for the Intel® Quark™ (x86-based) Arduino 101:

cd %ZEPHYR_BASE%\samples\hello_world
mkdir build & cd build

# Use cmake to configure a Ninja-based build system:
cmake -GNinja -DBOARD=arduino_101 ..

# Now run ninja on the generated build system:
ninja

TwoWinter开个玩笑:英特尔君投钱给Zephyr,绝对是有得赚,到处都是英特尔的软广。

To build for the ARM-based Nordic nRF52 Development Kit:

cd %ZEPHYR_BASE%\samples\hello_world
mkdir build & cd build

# Use cmake to configure a Ninja-based build system:
cmake -GNinja -DBOARD=nrf52_pca10040 ..

# Now run ninja on the generated build system:
ninja

如果这一步出错,要确认环境变量有没有配置进去。

set ZEPHYR_BASE=D:\winter\resources\zephyr\zephyr\

This should check that all the tools and toolchain are set up correctly for your own Zephyr development.

4 总结

Zephyr 是使用 Cmake 和 Ninja 进行编译,在这篇笔记里,学习如何搭建 Zephyr 开发所必须的软件开发环境。

cd %ZEPHYR_BASE%\samples\hello_world
mkdir build & cd build

# Use cmake to configure a Ninja-based build system:
cmake -GNinja -DBOARD=nrf52_pca10040 ..

# Now run ninja on the generated build system:
ninja

End


你可能感兴趣的:(物,-,操作系统,Zephyr,Ninja,Cmake,IoT)