Zephyr新手指南

Getting Started Guide

Use this guide to get started with your Zephyr development.

该文档用于指导新手开始Zephyr开发工作。

Set Up the Development Environment配置开发环境

The Zephyr project supports these operating systems:

  • Linux
  • Mac OS
  • Windows 8.1
  • Zephyr支持三种操作系统:Linux,Mac OS以及Windows8.1

Use the following procedures to create a new development environment.

Checking Out the Source Code Anonymously

匿名拉取源代码

The code is hosted at the Linux Foundation with a Gerrit backend that supports anonymous cloning via git.

Zephyr源代码托管在Linux基金会的Gerrit上,支持git匿名拉取

To clone the repository anonymously, enter:

匿名克隆代码仓库的命令如下:

$ git clone https://gerrit.zephyrproject.org/r/zephyr zephyr-project

You have successfully checked out a copy of the source code to your local machine.

Once you’re ready to start contributing, follow the steps to make yourself a Linux Foundation account at Gerrit Accounts.

在共享代码之前,你需要注册一个Gerrit账号

Building and Running an Application构建运行App

Using the ‘Hello World’ sample application as a base model, the following section will describe the pieces necessary for creating a Zephyr application.

The processes to build and run a Zephyr application are the same across operating systems. Nevertheless, the commands needed do differ from one OS to the next. The following sections contain the commands used in a Linux development environment. If you are using Mac OS please use the appropriate commands for your OS.

不同操作系统构建和运行Zephyr应用的处理过程是相同的,唯一的不同点在于命令有所差异。下面的部分已Linux开发环境为示例写的命令。其他的操作系统请使用相应的命令。

Building a Sample Application构建一个示例App

To build an example application follow these steps:

步骤如下:

  1. Make sure your environment is setup by exporting the following environment variables. When using the Zephyr SDK on Linux for example, type:   确保下面的环境变量被设置成export,以应用于Linux的Zephyr SDK为例:

    $ export ZEPHYR_GCC_VARIANT=zephyr
    
    $ export ZEPHYR_SDK_INSTALL_DIR=<sdk installation directory>
  2. Navigate to the main project directory:  切换到主工程目录:

    $ cd zephyr-project
    
  3. Source the project environment file to set the project environtment variables:  source工程环境文件设置环境变量

    $ source zephyr-env.sh
    
  4. Build the example project, enter:  构建应用工程:

    $ cd $ZEPHYR_BASE/samples/hello_world/microkernel
    
    $ make
    

The above invocation of make will build the hello_world sample application using the default settings defined in the application’s Makefile. You can build for a different board by defining the variable BOARD with one of the supported boards, for example:

上面的make指令将使用App的Makefile文件的默认配置来构建hello_world示例app。用户可以通过制定BOARD变量来构建不同单板的APP。比如:

$ make BOARD=arduino_101

For further information on the supported boards go see here. Alternatively, run the following command to obtain a list of the supported boards:  

可以通过如下命令来获取当前版本支持哪些单板的列表:

$ make help

The sample projects for the microkernel and the nanokernel are available at $ZEPHYR_BASE/samples

微内核和超微内核的示例工程可以在如下目录获取:$ZEPHYR_BASE/samples。

After building an application successfully, the results can be found in the outdir sub-directory under the application root directory.

APP构建完成之后,结果可以在APP根目录的outdir子目录中找到。

The ELF binaries generated by the build system are named by default zephyr.elf

构建系统生成的ELF二进制文件默认名称是zephyr.elf。

This value can be overridden in the application configuration The build system generates different names for different use cases depending on the hardware and boards used.

这个名称可以在App的配置中修改。构建系统针对不同的硬件和单板生成不同名称的文件。

Using Custom and 3rd Party Cross Compilers 使用定制和第三方交叉编译

The Zephyr SDK is provided for convenience and ease of use. It provides cross-compilers for all ports supported by Zephyr and does not require any extra flags when building applications or running tests.

Zephyr SDK使用方便容易。当构建应用或者运行测试时,Zephyr SDK提供了让Zephyr支持交叉编译工具的所有端口,不需要任何额外的标记。

If you have a custom cross-compiler or if you wish to use a vendor provided SDK, follow the steps below to build with any custom or 3rd party cross-compilers:

如果用户需要使用定制的交叉编译或者希望使用厂商提供的SDK,可以参照如下步骤来构建任意定制或第三方的交叉编译:

  1. To avoid any conflicts with the Zephyr SDK, enter the following commands.  为了避免任何与Zephyr SDK产生冲突,键入如下命令:

    $ unset ZEPHYR_GCC_VARIANT
    
    $ unset ZEPHYR_SDK_INSTALL_DIR
    
  2. We will use the GCC ARM Embedded compiler for this example, download the package suitable for your operating system from the GCC ARM Embedded website and extract it on your file system. This example assumes the compiler was extracted to: ~/gcc-arm-none-eabi-5_3-2016q1/.  我们以GCC ARM嵌入式编译器为例,从GCC ARM嵌入式官网下载与你的操作系统相匹配的软件包,并且解压到你的文件系统之中。下面的示例假设编译器被解压到~/gcc-arm-none-eabi-5_3-2016q1/。

  3. Navigate to the main project directory: 切换到工程主目录:

    $ cd zephyr-project
    
  4. Source the project environment file to set the project environment variables:  source工程环境文件设置环境变量

    $ source zephyr-env.sh
    
  5. Build the example project and make sure you supply the CROSS_COMPILE on the command line, enter:  开始构建示例工程,注意在命令行中键入CROSS_COMPILE参数值

    $ cd $ZEPHYR_BASE/samples/hello_world/microkernel
    
    $ make CROSS_COMPILE=~/gcc-arm-none-eabi-5_3-2016q1/bin/arm-none-eabi- BOARD=arduino_due
    

The above will build the sample using the toolchain downloaded from GCC ARM Embedded.

以上构建过程使用的工具链从GCC ARM嵌入式官网下载。

Running a Sample Application in QEMU 在QEMU运行示例APP

To perform rapid testing of an application in the development environment you can use the qemu emulation board configuration available for both X86 and ARM Cortex-M3 architectures. This can be easily accomplished by calling a special target when building an application that invokes QEMU once the build process is completed.

为了能在开发环境中快速测试APP,你可以使用QEMU仿真A86和ARM Cortex-M3架构配置单板。这很容易实现,只需要在构建App是调用特定的目标配置。

To run an application using the x86 emulation board configuration (qemu_x86), type:  运行一个X86仿真单板配置的APP,键入:

$ make BOARD=qemu_x86 qemu

To run an application using the ARM qemu_cortex_m3 board configuration, type:  运行一个ARM仿真单板配置的APP,键入:

$ make BOARD=qemu_cortex_m3 ARCH=arm qemu

QEMU is not supported on all boards and SoCs. When developing for a specific hardware target you should always test on the actual hardware and should not rely on testing in the QEMU emulation environment only.

QEMU仅支持部分单板和SoC。对于QEMU仿真环境不支持的单板,用户只能够使用真是的硬件环境进行测试了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值