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仿真環境不支持的單板,用戶只能夠使用真是的硬件環境進行測試了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章