【ESP32S2】esp-idf SDK环境搭建,编译运行hello_world例程
硬件环境
-
安信可ESP-12K开发板NodeMCU-32-S2
软件环境
-
Windows 10
一、下载SDK
以下载乐鑫官方SDK v4.3.1版本为例: 方法一: git clone -b v4.3.1 --recursive https://github.com/espressif/esp-idf.git esp-idf-v4.3.1 cd esp-idf-v4.3.1 方法二: 浏览器打开:https://dl.espressif.com/dl/esp-idf/releases/esp-idf-v4.3.1.zip
二、安装
cd esp-idf-v4.3.1 install.bat // 直接执行,会非常慢,可按照下面步骤三进行修改
安装完成后,会有以下提示:
All done! You can now run: export.bat
三、修改下载源
打开系统控制面板,点击高级设置; 添加一个新的环境变量,类型为用户或系统都可以,名称为 IDF_GITHUB_ASSETS,值为 dl.espressif.com/github_assets
四、设置环境变量
cd esp-idf-v4.3.1 export.bat
执行成功后有以下提示:
Done! You can now compile ESP-IDF projects. Go to the project directory and run: idf.py build
五、配置hello world工程
cd esp-idf-v4.3.1 xcopy /e /i examplesget-startedhello_world hello_world // 拷贝例程到根目录,防止污染原目录 cd hello_world idf.py set-target esp32s2 // 配置目标芯片 idf.py menuconfig // 如只用默认配置,可跳过此步
六、构建工程
hello_world目录下,执行: idf.py build
编译成功会有以下提示:
..componentsesptool_pyesptoolesptool.py -p (PORT) -b 460800 --before default_reset --after hard_reset --chip esp32s2 write_flash --flash_mode dio --flash_size detect --flash_freq 80m 0x1000 buildootloaderootloader.bin 0x8000 buildpartition_tablepartition-table.bin 0x10000 buildhello-world.bin or run idf.py -p (PORT) flash
生成的二进制文件
build/bootloader/bootloader.bin build/partition_table/partition-table.bin build/hello-world.bin
七、烧写
方法1:使用 flash_download_tool_v3.8.5.exe 工具
下载地址:
1)打开 flash_download_tool_v3.8.5.exe 选择 developer mode -> 选择 ESP32S2 DownloadTool; 2)依次填选: bootloader.bin ... @0x1000 hello-world.bin ... @0x10000 partition-table.bin ... @0x8000 偏移地址是从idf.py build执行结果最后的几行打印中确定的。 3)SPI SPEED 默认40MHz,可不改,或根据FLASH型号来。 4)SPI MODE 默认DIO,可不改,推荐DIO方式。 5)FLASH SIZE 默认,可不改 6)右下角 COM 改成实际的串口号,BAUD最大可设921600,默认460800。这个只是SPI下载速率,不会影响串口波特率115200。 7)点击左下角 START,等进度条走完即可。
方法2:使用idf.py(推荐)
1)根据idf.py build结果最后几行打印,提示执行idf.py -p (PORT) flash,把(PORT)换成实际的串口号即可: idf.py -p com8 flash 2)烧写完成会提示: Leaving... Hard resetting via RTS pin... Done 3)烧写时要把串口连接断开。