赞
踩
鉴于ESP32出众性价比拿了ESP32模块学习一下
WIN10/11+VSCODE+ESP-IDF环境(多版本切换)。板子是乐鑫官方淘宝店ESP32C3(附带书)套餐。VScode绝大部分是GUI环境,比起文本环境的傻瓜
首先按照官方例程很快将VScode+ESP-IDF5.2环境搭好,win环境下用ESP-IDF离线包最简单,各种win系统下的环境变量都会自动配好。
VScode里面ESP-IDF 和C/C++插件必装的,英文环境如果觉得吃力还可以装简体中文语言包。如果没有科学上网,推荐选乐鑫服务器下载。前面装过ESP-IDF包之后这里就能读到IDF_PATH和IDF_TOOL_PATH,点intall会检查环境,注意在切换不同版本IDF时候一定要这里重新跑一下。2个路径会自动切换好。这里图片是5.1.1仅为示范图。下载看电脑性能和网络速度,离线IDF包装好的情况下几分钟,没有的会自动补下载。有的老版本IDF包不好找,可以在这选版本后自动下载自动解压好。不同版本的IDF_PATH是不同的
VScode里面用ESP-IDF插件将show example将hello_world和blink跑一下,左下角COM口和target选择ESP32C3,很快很顺利就好了。
在blink工程里面可以用SDK Cconfiguration Editor (menuconfig)设置改改BLINK的GPIO设置,编译后下载后可以看到修改生效,萌新的成就感马上来了
前面利用show example顺利编译让人信心膨胀,拿书带的例程代码,项目名是book-esp32c3-iot-projects,,github和gitee都有下载
https://github.com/espressif/book-esp32c3-iot-projects
https://gitee.com/EspressifSystems/book-esp32c3-iot-projects
用2_light_drivers拿来练手。
如果打开的是device_firmware根目录会同时出现多项目,最好是打到对应工程的main文件夹级别
然后打开就是编译报错,我当时IDF是5.2
报错信息如下
Configuring incomplete, errors occurred!
See also “D:/project/book-esp32c3-iot-projects-main/device_firmware/2_light_drivers/build/CMakeFiles/CMakeOutput.log”.
刚开始怀疑是自己文件夹选的位置错误,或者库没下好,ninja编译器或者找powershell被系统禁用等等,最后发现方向全都错了,
根本原因就是IDF版本不对
根本原因就是IDF版本不对
根本原因就是IDF版本不对
按照一般思维是用越高越好,向下兼容,但是在乐鑫这里不是的,至少要2位版本号对齐例如这本书例程对应4.3,试了5.2和4.4都是不行的。类似编译环境的问题到github,乐鑫自己论坛,还是乐鑫b站视频评论区下面骂声一片。熬了几晚上想不通找论坛才看明白。
IDF版本不对,menuconfig和build都会有问题,所以一定要问清楚用的IDF版本。如果是很简单的hello world等库的依赖很简单,有可能不同版本能过,但是稍复杂一点有几个组件(components)就编译失败了。经常见到的错误就是ninja或者terminated with exit code: 1.
我改了4.3.7就编译全正常了。
官方论坛已经回复了https://www.esp32.com/viewtopic.php?f=47&t=30837
github也有人评论了
前面库的问题解决了,在IDF4.3.7里面再编一下device_firmware\2_light_drivers\工程
不需要在C/C++的includep path额外添加头文件,这个功能很简单就是按键控制LED亮灭。
main\app_driver.c里面app_driver_set_state可以修改LED状态,例如加一句呼吸灯
回到正经工程device_firmware\5_rainmaker\ 编译发现
CMake Error at CMakeLists.txt:9 (message):
Please set RAIMAKER_PATH to esp-rainmaker repo
是缺乏RAIMAKER_PATH ,在说明文件README_cn.md需要设置一下
ESP32论坛也有人问这个 https://esp32.com/viewtopic.php?t=31501
下载好的 D:\project\esp-rainmaker文件在这里,显然的这些命令不是win系统终端能干的,搜索一下 https://rainmaker.espressif.com/zh-hans/docs/cli-setup/
直接改win的环境变量试试看,修改失败
索性拷贝D:\project\esp-rainmaker的components过来还是同样错误,作罢。。。
以上就是书籍带的例程,运行试了两个,第二个失败,不懂怎么改Rainmaker path
最后实验一下esp-rainmaker\examples\led_light,里面的例子,IDF仍然是4.3.7轻松编译成功
main\app_driver.c是驱动文件
默认例程中 BUTTON_GPIO 用9(CONFIG_EXAMPLE_BOARD_BUTTON_GPIO),
#define BUTTON_GPIO CONFIG_EXAMPLE_BOARD_BUTTON_GPIO
#define BUTTON_ACTIVE_LEVEL 0
还定义了3秒长按出厂设置(随机密码仅刷机第一次,之后恢复出厂不更新)
#define WIFI_RESET_BUTTON_TIMEOUT 3
#define FACTORY_RESET_BUTTON_TIMEOUT 10
LED是板上W2812 LED,IO 8, 在menufig搜索或者sdkconfig文件可以修改
使用流畅
用app控制LED开关。log是二维码,名称和密码,用的随机密码
手机装乐鑫Rainmaker app,可以手机APP端扫码,也可以蓝牙搜索
配好wifi后联网,可以控制颜色,开关
板上LED跟着变化
玩一个复杂的带联网查天气显示灯环状态的,APP操作W2812灯带(5V供电单IO管脚控制)
做好视频传了B站 https://www.bilibili.com/video/BV1bu4m1g7UL/
最后发现确实不用额外加include,就是原工程有2个components是改过的默认在工程里面,其他没动过的都是从自动下载的,在managed_components目录下
main/idf_component.yml 规定了这两个从gitee下载的
编译过程检查依赖,编译过程的log可以看到
processing 12 dependencies:
[1/12] app_wifi (909c7f00be0cd3343ba18a174d403889f0ea314b)
[2/12] espressif/esp_rainmaker (1.1.0)
[3/12] espressif/esp_schedule (1.1.0)
[4/12] espressif/esp_secure_cert_mgr (2.4.1)
[5/12] espressif/jsmn (1.1.0)
[6/12] espressif/json_generator (1.1.2)
[7/12] espressif/json_parser (1.0.3)
[8/12] espressif/led_strip (2.5.3) from file:///D:/Espressif/registry
[9/12] espressif/mdns (1.2.5)
[10/12] espressif/rmaker_common (1.4.5)
[11/12] idf (5.1.1)
[12/12] qrcode (909c7f00be0cd3343ba18a174d403889f0ea314b)
mangaged_components目录会有这么多
我可能毕竟点背,
espressif/esp_rainmaker
espressif/esp_schedule
这两个总是编译报错版本不对,mangaged_components有的可能是从github下载的,刚好网络问题没下好,但是文件夹有了,第二次不会重新下载。删了后自动重新下载到mangaged_components就好了
最后编译成功
LED控制用的10,数量16,可以自定义
原作者是无密码自动连接(POP_TYPE_NONE),我改了MAC地址做8位密码连接(POP_TYPE_MAC),在main.c的app_wifi_start修改参数
/* Use BLE provisioning */
app_wifi_start(POP_TYPE_MAC);
有四种类型如下
typedef enum {
/** *Use MAC address to generate PoP */
POP_TYPE_MAC,
/** Use random stream generated and stored in fctry partition during claiming process as PoP */
POP_TYPE_RANDOM,
/** Do not use any PoP.
* Use this option with caution. Consider using `CONFIG_APP_WIFI_PROV_TIMEOUT_PERIOD` with this.
*/
POP_TYPE_NONE,
/** Use a custom PoP.
* Set a custom PoP using app_wifi_set_custom_pop() first.
*/
POP_TYPE_CUSTOM
} app_wifi_pop_type_t;
插曲,本来components目录下只有2个,如果完整的从mangaged_components的拷贝到components如下图,这样编译时候如果动了mangaged_components里面的文件夹就不会重新下载了,components比mangaged_components优先使用。
用闪电图案一键三连烧录进去
烧录log部分
esptool.py v4.7.0
Serial port COM3
Connecting…
Chip is ESP32-C3 (QFN32) (revision v0.3)
Features: WiFi, BLE, Embedded Flash 4MB (XMC)
Crystal is 40MHz
MAC: 10:91:a8:1f:dd:c0
Uploading stub…
Running stub…
Stub running…
Changing baud rate to 460800
Changed.
Configuring flash size…
Flash will be erased from 0x00000000 to 0x00005fff…
Flash will be erased from 0x00020000 to 0x001d2fff…
Flash will be erased from 0x00008000 to 0x00008fff…
Compressed 20528 bytes to 12602…
Wrote 20528 bytes (12602 compressed) at 0x00000000 in 0.7 seconds (effective 228.4 kbit/s)…
Hash of data verified.
Compressed 1781648 bytes to 970229…
Wrote 1781648 bytes (970229 compressed) at 0x00020000 in 30.3 seconds (effective 470.7 kbit/s)…
启动log
I (30) boot: ESP-IDF v5.1.1 2nd stage bootloader
I (30) boot: compile time Mar 10 2024 14:52:23
I (30) boot: chip revision: v0.3
I (33) boot.esp32c3: SPI Speed : 80MHz
I (38) boot.esp32c3: SPI Mode : DIO
I (43) boot.esp32c3: SPI Flash Size : 4MB
I (47) boot: Enabling RNG early entropy source…
I (53) boot: Partition Table:
I (56) boot: ## Label Usage Type ST Offset Length
I (64) boot: 0 esp_secure_cert unknown 3f 06 0000d000 00002000
I (71) boot: 1 nvs WiFi data 01 02 00010000 00006000
I (79) boot: 2 phy_init RF data 01 01 00016000 00001000
I (86) boot: 3 factory factory app 00 00 00020000 002c0000
I (94) boot: 4 fctry WiFi data 01 02 002e0000 00006000
I (101) boot: End of partition table
I (105) esp_image: segment 0: paddr=00020020 vaddr=3c140020 size=60c38h (396344) map
I (177) esp_image: segment 1: paddr=00080c60 vaddr=3fc94a00 size=03234h ( 12852) load
I (180) esp_image: segment 2: paddr=00083e9c vaddr=40380000 size=0c17ch ( 49532) load
I (192) esp_image: segment 3: paddr=00090020 vaddr=42000020 size=13a77ch (1288060) map
I (398) esp_image: segment 4: paddr=001ca7a4 vaddr=4038c17c size=087bch ( 34748) load
I (411) boot: Loaded app from partition at offset 0x20000
I (411) boot: Disabling RNG early entropy source…
I (423) cpu_start: Unicore app
I (423) cpu_start: Pro cpu up.
I (432) cpu_start: Pro cpu start user code
I (432) cpu_start: cpu freq: 160000000 Hz
I (432) cpu_start: Application information:
I (435) cpu_start: Project name: main
I (439) cpu_start: App version: 1
I (444) cpu_start: Compile time: Mar 10 2024 14:59:58
I (450) cpu_start: ELF file SHA256: b4a1b3e2cc530106…
I (456) cpu_start: ESP-IDF: v5.1.1
I (461) cpu_start: Min chip rev: v0.3
I (465) cpu_start: Max chip rev: v0.99
I (470) cpu_start: Chip rev: v0.3
I (475) heap_init: Initializing. RAM available for dynamic allocation:
I (482) heap_init: At 3FC9FEE0 len 0003C830 (242 KiB): DRAM
I (488) heap_init: At 3FCDC710 len 00002950 (10 KiB): STACK/DRAM
I (495) heap_init: At 50000010 len 00001FD8 (7 KiB): RTCRAM
I (502) spi_flash: detected chip: generic
I (506) spi_flash: flash io: dio
I (510) sleep: Configure to isolate all GPIO pins in sleep state
I (517) sleep: Enable automatic switching of GPIO sleep configuration
I (524) coexist: coex firmware version: 80b0d89
I (529) coexist: coexist rom version 9387209
I (534) app_start: Starting scheduler on CPU0
I (539) main_task: Started on CPU0
I (539) main_task: Calling app_main()
I (549) pp: pp rom version: 9387209
I (549) net80211: net80211 rom version: 9387209
I (559) wifi:wifi driver task: 3fca952c, prio:23, stack:6656, core=0
I (559) wifi:wifi firmware version: ce9244d
I (559) wifi:wifi certification version: v7.0
I (569) wifi:config NVS flash: enabled
I (569) wifi:config nano formating: disabled
I (569) wifi:Init data frame dynamic rx buffer num: 32
I (579) wifi:Init management frame dynamic rx buffer num: 32
I (579) wifi:Init management short buffer num: 32
I (589) wifi:Init dynamic tx buffer num: 32
I (589) wifi:Init static tx FG buffer num: 2
I (599) wifi:Init static rx buffer size: 1600
I (599) wifi:Init static rx buffer num: 10
I (599) wifi:Init dynamic rx buffer num: 32
I (609) wifi_init: rx ba win: 6
I (609) wifi_init: tcpip mbox: 32
I (619) wifi_init: udp mbox: 6
I (619) wifi_init: tcp mbox: 6
I (619) wifi_init: tcp tx win: 5744
I (629) wifi_init: tcp rx win: 5744
I (629) wifi_init: tcp mss: 1440
I (639) wifi_init: WiFi IRAM OP enabled
I (639) wifi_init: WiFi RX IRAM OP enabled
I (649) esp_rmaker_work_queue: Work Queue created.
I (659) esp_mqtt_glue: AWS PPI: ?Platform=APN3|A0|RM|EX00|RMDev|1x0|1091A81FDDC0
I (659) esp_mqtt_glue: Initialising MQTT
I (659) esp_rmaker_mqtt_budget: MQTT Budgeting initialised. Default: 100, Max: 1024, Revive count: 1, Revive period: 5
I (679) esp_rmaker_node: Node ID ----- 1091A81FDDC0
I (679) esp_rmaker_time: Initializing SNTP. Using the SNTP server: pool.ntp.org
I (689) esp_rmaker_core: Starting RainMaker Work Queue task
I (689) esp_rmaker_work_queue: RainMaker Work Queue task started.
I (699) wifi_prov_scheme_ble: BT memory released
I (709) app_wifi: Already provisioned, starting Wi-Fi STA
I (709) wifi_prov_scheme_ble: BTDM memory released
I (719) phy_init: phy_version 970,1856f88,May 10 2023,17:44:12
I (769) wifi:mode : sta (10:91:a8:1f:dd:c0)
I (769) wifi:enable tsf
I (3179) wifi声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。