使用 PlatformIO 的嵌入式构建
概述 #
PlatformIO 是一款跨平台的代码构建器和库管理器,用于嵌入式开发,没有外部依赖项。使用 PlatformIO,您可以在多个平台、框架和板上编译代码。单元测试需要 每月订阅.
-
平台 - 为最流行的主机操作系统 (macOS、Windows、Linux 32/64 位、Linux ARMv6+) 预先构建了不同的开发平台。每个平台都包含编译器、调试器、上传器等。
- Atmel AVR
- Espressif
- Teensy
- ST STM32
- 完整列表 在 PlatformIO 上
-
框架 - 为流行的嵌入式框架预先配置了构建脚本
- Arduino
- libOpenCM3
- mbed
- 完整列表 在 PlatformIO 上
-
嵌入式 - 为各种嵌入式板预定义了编译配置文件。
完整列表 在 PlatformIO 上
.travis.yml 设置 #
在使用 PlatformIO 之前,请阅读官方的 PlatformIO & Travis CI 文档。
PlatformIO 是用 Python 编写的,建议在 Travis CI Python 隔离环境 中运行。
language: python
python:
- "2.7"
cache:
directories:
- "~/.platformio"
env:
- PLATFORMIO_CI_SRC=path/to/test/file.c
- PLATFORMIO_CI_SRC=examples/file.ino
- PLATFORMIO_CI_SRC=path/to/test/directory
install:
- pip install -U platformio
script:
- platformio ci --board=TYPE_1 --board=TYPE_2 --board=TYPE_N
测试库 #
如果要测试的项目是一个库,请使用 --lib="."
选项作为 platformio ci 命令。
script:
- platformio ci --lib="." --board=TYPE_1 --board=TYPE_2 --board=TYPE_N
管理依赖项 #
有两种方法可以测试具有外部依赖项的项目:
- 使用 PlatformIO 库管理器
- 手动安装依赖项
PlatformIO 库管理器 #
对于 PlatformIO 库注册表中可用的依赖项
install:
- pip install -U platformio
# Libraries from PlatformIO Library Registry:
# http://platformio.org/#!/lib/show/1/OneWire
- platformio lib install 1
手动安装依赖项 #
对于 PlatformIO 库注册表中不可用的依赖项
install:
- pip install -U platformio
# download library to the temporary directory
- wget https://github.com/PaulStoffregen/OneWire/archive/master.zip -O /tmp/onewire_source.zip
- unzip /tmp/onewire_source.zip -d /tmp/
script:
- platformio ci --lib="/tmp/OneWire-master" --board=TYPE_1 --board=TYPE_2 --board=TYPE_N
自定义构建标志 #
要使用 PLATFORMIO_BUILD_FLAGS 环境指定自定义构建标志。
env:
- PLATFORMIO_CI_SRC=path/to/test/file.c PLATFORMIO_BUILD_FLAGS="-D SPECIFIC_MACROS_PER_TEST_ENV -I/extra/inc"
- PLATFORMIO_CI_SRC=examples/file.ino
- PLATFORMIO_CI_SRC=path/to/test/directory
install:
- pip install -U platformio
- export PLATFORMIO_BUILD_FLAGS=-D GLOBAL_MACROS_FOR_ALL_TEST_ENV
更多详细信息请访问 构建标志/选项.
高级配置 #
可以使用 platformio.ini 项目配置文件来配置多个构建环境,并指定 –project-conf 而不是 --board
。
script:
- platformio ci --project-conf=/path/to/platformio.ini