Loading...
Loading...
Compare original and translation side by side
Complete reference for PlatformIO embedded development.
PlatformIO嵌入式开发完整参考手册
undefinedundefined
---
---project/
├── platformio.ini # Project configuration
├── src/
│ └── main.cpp # Main source file
├── include/ # Header files
├── lib/ # Project-specific libraries
├── test/ # Unit tests
└── .pio/ # Build output (gitignored)project/
├── platformio.ini # Project configuration
├── src/
│ └── main.cpp # Main source file
├── include/ # Header files
├── lib/ # Project-specific libraries
├── test/ # Unit tests
└── .pio/ # Build output (gitignored); Global options
[platformio]
default_envs = esp32dev
src_dir = src
include_dir = include
; Environment definition
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino; Global options
[platformio]
default_envs = esp32dev
src_dir = src
include_dir = include
; Environment definition
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino| Platform | Board Examples | Frameworks |
|---|---|---|
| esp32dev, esp32-s3-devkitc-1 | arduino, espidf |
| esp12e, d1_mini | arduino |
| nucleo_f446re, bluepill_f103c8 | arduino, stm32cube |
| pico | arduino |
| uno, nanoatmega328 | arduino |
| 平台 | 开发板示例 | 框架 |
|---|---|---|
| esp32dev, esp32-s3-devkitc-1 | arduino, espidf |
| esp12e, d1_mini | arduino |
| nucleo_f446re, bluepill_f103c8 | arduino, stm32cube |
| pico | arduino |
| uno, nanoatmega328 | arduino |
; ESP32 with Arduino
[env:esp32-arduino]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_speed = 921600
lib_deps =
bblanchon/ArduinoJson@^7.0.0
; ESP32-S3 with PSRAM
[env:esp32s3]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
board_build.mcu = esp32s3
board_build.f_cpu = 240000000L
build_flags =
-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
; ESP32 with ESP-IDF
[env:esp32-idf]
platform = espressif32
board = esp32dev
framework = espidf
monitor_speed = 115200
board_build.partitions = partitions.csv; ESP32 with Arduino
[env:esp32-arduino]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_speed = 921600
lib_deps =
bblanchon/ArduinoJson@^7.0.0
; ESP32-S3 with PSRAM
[env:esp32s3]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
board_build.mcu = esp32s3
board_build.f_cpu = 240000000L
build_flags =
-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
; ESP32 with ESP-IDF
[env:esp32-idf]
platform = espressif32
board = esp32dev
framework = espidf
monitor_speed = 115200
board_build.partitions = partitions.csv; Nucleo F446RE
[env:nucleo_f446re]
platform = ststm32
board = nucleo_f446re
framework = arduino
upload_protocol = stlink
; Blue Pill
[env:bluepill]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = stlink; Nucleo F446RE
[env:nucleo_f446re]
platform = ststm32
board = nucleo_f446re
framework = arduino
upload_protocol = stlink
; Blue Pill
[env:bluepill]
platform = ststm32
board = bluepill_f103c8
framework = arduino
upload_protocol = stlink; Raspberry Pi Pico
[env:pico]
platform = raspberrypi
board = pico
framework = arduino
; Pico W with WiFi
[env:picow]
platform = raspberrypi
board = rpipicow
framework = arduino; Raspberry Pi Pico
[env:pico]
platform = raspberrypi
board = pico
framework = arduino
; Pico W with WiFi
[env:picow]
platform = raspberrypi
board = rpipicow
framework = arduinoundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined
---
---build_flags =
-DDEBUG ; Define DEBUG macro
-DVERSION=\"1.0.0\" ; String define (escaped quotes)
-I include/extra ; Additional include path
-Wall ; Enable all warnings
-Wextra ; Extra warnings
-O2 ; Optimization levelbuild_flags =
-DDEBUG ; Define DEBUG macro
-DVERSION=\"1.0.0\" ; String define (escaped quotes)
-I include/extra ; Additional include path
-Wall ; Enable all warnings
-Wextra ; Extra warnings
-O2 ; Optimization levelbuild_flags =
-DCORE_DEBUG_LEVEL=3 ; Debug output level (0-5)
-DBOARD_HAS_PSRAM ; Enable PSRAM
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1build_flags =
-DCORE_DEBUG_LEVEL=3 ; Debug output level (0-5)
-DBOARD_HAS_PSRAM ; Enable PSRAM
-DCONFIG_ASYNC_TCP_RUNNING_CORE=1build_flags =
${env.build_flags} ; Inherit from parent
$BUILD_FLAGS ; From environment variablebuild_flags =
${env.build_flags} ; Inherit from parent
$BUILD_FLAGS ; From environment variablelib_deps =
; Library by owner/name
bblanchon/ArduinoJson@^7.0.0
; Library by name only
Adafruit Unified Sensor
; GitHub repository
https://github.com/me/mylib.git
; Specific branch/tag
https://github.com/me/mylib.git#develop
; Local library
file:///path/to/librarylib_deps =
; Library by owner/name
bblanchon/ArduinoJson@^7.0.0
; Library by name only
Adafruit Unified Sensor
; GitHub repository
https://github.com/me/mylib.git
; Specific branch/tag
https://github.com/me/mylib.git#develop
; Local library
file:///path/to/librarylib_deps =
library@1.2.3 ; Exact version
library@^1.2.3 ; Compatible (>=1.2.3 <2.0.0)
library@~1.2.3 ; Approximate (>=1.2.3 <1.3.0)
library@>=1.0.0 ; Minimum versionlib_deps =
library@1.2.3 ; Exact version
library@^1.2.3 ; Compatible (>=1.2.3 <2.0.0)
library@~1.2.3 ; Approximate (>=1.2.3 <1.3.0)
library@>=1.0.0 ; Minimum version[env]
; Shared across all environments
monitor_speed = 115200
lib_deps =
bblanchon/ArduinoJson@^7.0.0
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
[env:esp32s3]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
build_flags =
-DBOARD_HAS_PSRAM[env]
; Shared across all environments
monitor_speed = 115200
lib_deps =
bblanchon/ArduinoJson@^7.0.0
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
[env:esp32s3]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
build_flags =
-DBOARD_HAS_PSRAM[env:debug]
extends = env:esp32dev
build_type = debug
build_flags =
-DDEBUG=1
-g3
[env:release]
extends = env:esp32dev
build_type = release
build_flags =
-DNDEBUG
-O2[env:debug]
extends = env:esp32dev
build_type = debug
build_flags =
-DDEBUG=1
-g3
[env:release]
extends = env:esp32dev
build_type = release
build_flags =
-DNDEBUG
-O2test/
├── test_main.cpp ; Native tests
├── test_embedded/
│ └── test_gpio.cpp ; On-device tests
└── unity.h ; Unity test framework (included)test/
├── test_main.cpp ; Native tests
├── test_embedded/
│ └── test_gpio.cpp ; On-device tests
└── unity.h ; Unity test framework (included)#include <unity.h>
void setUp(void) {
// Runs before each test
}
void tearDown(void) {
// Runs after each test
}
void test_addition(void) {
TEST_ASSERT_EQUAL(4, 2 + 2);
}
void test_string(void) {
TEST_ASSERT_EQUAL_STRING("hello", "hello");
}
int main(int argc, char **argv) {
UNITY_BEGIN();
RUN_TEST(test_addition);
RUN_TEST(test_string);
UNITY_END();
}#include <unity.h>
void setUp(void) {
// Runs before each test
}
void tearDown(void) {
// Runs after each test
}
void test_addition(void) {
TEST_ASSERT_EQUAL(4, 2 + 2);
}
void test_string(void) {
TEST_ASSERT_EQUAL_STRING("hello", "hello");
}
int main(int argc, char **argv) {
UNITY_BEGIN();
RUN_TEST(test_addition);
RUN_TEST(test_string);
UNITY_END();
}[env:native]
platform = native
test_framework = unity[env:native]
platform = native
test_framework = unity[env:debug]
platform = espressif32
board = esp32dev
framework = arduino
debug_tool = esp-prog
debug_init_break = tbreak setup[env:debug]
platform = espressif32
board = esp32dev
framework = arduino
debug_tool = esp-prog
debug_init_break = tbreak setupundefinedundefined
---
---[env:esp32dev]
extra_scripts =
pre:scripts/pre_build.py
post:scripts/post_build.py[env:esp32dev]
extra_scripts =
pre:scripts/pre_build.py
post:scripts/post_build.pyundefinedundefined
---
---| Issue | Solution |
|---|---|
| Upload failed | Check port, try lower upload_speed |
| Library not found | Use full |
| Build error | Clean with |
| Wrong board | Verify board ID with |
Note: PlatformIO supports 1000+ boards. Useto find your board.pio boards <search>
| 问题 | 解决方案 |
|---|---|
| 上传失败 | 检查端口,尝试降低upload_speed |
| 库未找到 | 使用完整的 |
| 编译错误 | 执行 |
| 开发板不匹配 | 使用 |
注意: PlatformIO支持1000+款开发板,使用查找你的开发板。pio boards <搜索关键词>