1

在带有 PlatformIO 的 Visual Studio Code 上,当我单击[v]按钮 ( PlatformIO:Build ) 时,IDE 运行以下任务:

> Executing task: C:\Users\Mary\.platformio\penv\Scripts\platformio.exe run <

Processing d1_mini (platform: espressif8266; board: d1_mini; framework: arduino)
...
...

当我单击[=>]按钮(PlatformIO:Upload)时,IDE 运行以下任务:

> Executing task: ~\.platformio\penv\Scripts\platformio.exe run --target upload <

Processing d1_mini (platform: espressif8266; board: d1_mini; framework: arduino)
...
...

解释:

https://docs.platformio.org/en/latest/userguide/cmd_run.html

我需要区分何时运行目标(编译)或目标上传(--target 上传)以设置不同的环境变量。就像是

[env:specific_defines]
build_flags =
  -D MY_VAR=true

因为当我编译项目时,我不想要调试信息(例如 Serial.println()),当我通过 USB 上传程序并附有板时我想要这些信息。

我查看构建选项高级脚本,但我没有找到适合我的任何东西。

提前致谢。

4

1 回答 1

1

迟到的答案:构建标志不适用于 UPLOAD - 因为此时源已经构建。

如果您有两个环境,比如生产环境和调试环境,您还必须上传变体。

pio run -e prod -> compiles prod environment
pio run -e prod -t upload -> uploads prod environment

pio run -e debug -> compiles debug environment
pio run -e debug -t upload -> uploads debug environment
于 2020-09-20T09:54:30.530 回答