使用platformIO进行arduino,esp8266,esp32编程的性能改进和一些优化

32 篇文章 2 订阅
31 篇文章 2 订阅

目录

多环境配置

性能优化


多环境配置

平常的一些platformio的配置是这样的:

[env:esp32dev]
platform = espressif32
board = nodemcu-32s
framework = arduino
monitor_speed = 115200
upload_speed = 921600
lib_deps = 
	; painlessmesh/painlessMesh@^1.5.0
	bodmer/TFT_eSPI@^2.5.43
	moononournation/GFX Library for Arduino@^1.4.6
	; lorol/LittleFS_esp32@^1.0.6
board_build.filesystem = littlefs

build_flags = 
    -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
    -D CONFIG_ARDUHAL_LOG_COLORS=1

但是事实上,platformio.ini是支持多配置的:



[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
monitor_speed = 115200
upload_speed = 921600
board_build.filesystem = littlefs
build_flags = 
	-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
	-D CONFIG_ARDUHAL_LOG_COLORS=1
lib_deps = 
	bodmer/TFT_eSPI@^2.5.43
	moononournation/GFX Library for Arduino@^1.4.6

build_type=debug

[env:esp32dev]
platform = espressif32
board = nodemcu-32s
framework = arduino
monitor_speed = 115200
upload_speed = 921600
lib_deps = 
	; painlessmesh/painlessMesh@^1.5.0
	bodmer/TFT_eSPI@^2.5.43
	moononournation/GFX Library for Arduino@^1.4.6
	; lorol/LittleFS_esp32@^1.0.6
board_build.filesystem = littlefs

build_flags = 
    -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
    -D CONFIG_ARDUHAL_LOG_COLORS=1


build_type=debug 

多配置的意义是方便随时切换不同的硬件,不用再修改配置参数,而且如果你要上传代码到硬件的时候,系统会自动判断和选择:

A fatal error occurred: This chip is ESP32 not ESP8266. Wrong --chip argument?

A fatal error occurred: This chip is ESP8266 not ESP32. Wrong --chip argument?

不是对应型号的单片机会对应报错。

多配置会导致platformio编译两份代码,产生性能损耗,但是这少了一些其他工作,如果你的电脑足够快可能可以接受,看你怎么选择。

以前不知道支持多配置,每次都只保留一个,切换起来实在不方便。

platformio的官方还有一些公共模块配置的方案,个人感觉太复杂不推荐。

性能优化

release编译耗时

debug编译耗时

对platformio.ini的修改后重新编译项目的时候,基本上就是所有项目代码的重新编译,非常耗时,很长;但是platformio.ini是可以开启缓存的:

[platformio]

build_cache_dir =   cache

上面这个cache表示一个存放缓存的目录,当然你可以任意指定名称,但是目录最好放在项目内。

这个配置的说明在 : build_cache_dir — PlatformIO latest documentation

开启缓存后,除了第一次需要耗时很长,后续不论你怎么修改platformio.ini都是非常短的时候了:

如果你使用tft_espi,修改了user_setup.h文件,整个项目会完全编译,但是这个cache开启后就是只编译一个文件,项目整体编译的非常快。

一句话,以前可能会完全编译的时候,现在基本都是只编译局部文件了,速度大提升,这个配置很重要不知道为啥不是默认配置。

如下图所示,没有修改过的文件,统统调用了cache。

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值