我第一次做嵌入式开发然后把学习过程记录一下。ESP32开发板这里我选了一个我同事给我推荐的板子叫ESP32。具体型号为ESP32-S3开发板N16R8焊接。我在淘宝上买的20多块钱。开发环境搭建上来我用最常见的Windows做开发环境后续我会尝试一下用Linux做开发。官方文档地址如下https://docs.espressif.com/projects/esp-idf/zh_CN/stable/esp32/get-started/windows-setup.html我的实战操作如下下载安装包https://dl.espressif.com/dl/eim/https://dl.espressif.com/github_assets/espressif/idf-im-ui/releases/download/v0.19.0/eim-gui-windows-x64.exe打开开始安装第1次玩不折腾了直接简易安装。直接点开始安装然后就开始下载安装包了估计要下载10几分钟吧可惜我这里自动安装失败了。说什么找不到python的什么环境吧。我忘记截图了然后点了个重试说安装路径已经存在。然后又点了专家模式。这个版本选择这里我很怂的选择上个版本的稳定版本v5.5.5。然后点击继续安装。这里因为我不懂所以我全选 第1 次尝试我全选安装后来安装失败了。原因是磁盘空间不足原来C盘就只有不足。后来我换了安装在D盘。安装后C盘有一个Espressif目录高达17GB我感觉这个目录可能是下载的缓存吧理论上应该可以删除吧。我暂时不敢删除D盘的安装目录是为什么会这么巨大啊我猜测可能是因为是集成开发环境吧。把一堆依赖项目都自动安装了吧。创建项目为了简单点我选择使用命令行版本的参考https://docs.espressif.com/projects/esp-idf/zh_CN/stable/esp32/get-started/windows-start-project.htmlESP-IDF 安装完成后EIM 会在桌面上创建 快捷方式用于启动已激活 ESP-IDF 环境的终端。例如点击 IDF_v5.4.2_Powershell 快捷方式打开已设置好环境的 PowerShell 终端。至此您已成功在终端中激活 ESP-IDF 环境。后续所有 ESP-IDF 相关命令都需在已激活的终端中运行。开始创建项目现在可以准备开发 ESP32 应用程序了。可以从 ESP-IDF 中 examples 目录下的 get-started/hello_world 项目开始。重要ESP-IDF 编译系统不支持 ESP-IDF 路径或其项目路径中带有空格。将 get-started/hello_world 项目复制至本地的 ~/esp 目录下D:\esp\v5.5.5\esp-idf\examples\get-started\我复制到了D:\workspace\esp\hello_world获取串口信息可以拔掉设备后在插上看端口这里的设备变化因为我这里只有一台设备所以知道这里是COM3cdD:\workspace\esp\hello_world idf.py set-target esp32 idf.py menuconfig打开一个新项目后应首先使用 idf.py set-target esp32 设置“目标”芯片。注意此操作将清除并初始化项目之前的编译和配置如有。也可以直接将“目标”配置为环境变量此时可跳过该步骤。更多信息请见 选择目标芯片set-target。正确操作上述步骤后系统将显示以下菜单可以通过此菜单设置项目的具体变量包括 Wi-Fi 网络名称、密码和处理器速度等。hello_world 示例项目会以默认配置运行因此在这一项目中可以跳过使用 menuconfig 进行项目配置这一步骤。编译项目请使用以下命令编译烧录项目idf.py build运行以上命令可以编译应用程序和所有 ESP-IDF 组件接着生成引导加载程序、分区表和应用程序二进制文件。如果一切正常编译完成后将生成 .bin 文件。烧录到设备请运行以下命令将刚刚生成的二进制文件烧录至 ESP32 开发板idf.py-pPORT flash那么我这里就是上面查到的COM3idf.py-pCOM3 flash我这里并没有成功任务失败明天在试吧。然后问AI说尝试按住Boot键然后点一下RST这时会听到电脑一个设备连接的咚一声在设备管理中发现串口COM3变成COM4了。这时执行烧写日志发生变化了。idf.py flash(venv)PS D:\workspace\esp\hello_worldidf.py flash Executing action: flash Serial port COM4 Connecting... Detecting chip type... ESP32-S3 Running ninjaindirectory D:\workspace\esp\hello_world\build Executingninja flash...[0/1]Re-running CMake... -- Component directory D:/esp/v5.5.5/esp-idf/components/esp_blockdev does not contain a CMakeLists.txt file. No component will be added -- Minimal build - ON -- ccache will be usedforfaster recompilation --gitrev-parse returnedfatal: not a git repository (or any of the parent directories): .git-- Could not usegit describeto determine PROJECT_VER. -- Building ESP-IDF componentsfortarget esp32 -- ESP-TEE is currently supported only on the esp32c6;esp32h2;esp32c5 SoCs -- Project sdkconfigfileD:/workspace/esp/hello_world/sdkconfig -- Compiler supported targets: xtensa-esp-elf -- Detecting C compiler ABI info -- Detecting C compiler ABI info -done-- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info -done-- Detecting C compiler ABI info -- Detecting C compiler ABI info -done-- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info -done-- USING O3 -- Apphello_worldversion:1-- Adding linker script D:/workspace/esp/hello_world/build/esp-idf/esp_system/ld/memory.ld -- Adding linker script D:/workspace/esp/hello_world/build/esp-idf/esp_system/ld/sections.ld.in -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.api.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.libgcc.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.syscalls.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.libc-funcs.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-reent-funcs.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/soc/esp32/ld/esp32.peripherals.ld -- Components: app_update bootloader bootloader_support cxx efuse esp_app_format esp_bootloader_format esp_common esp_driver_gpio esp_hw_support esp_mm esp_partition esp_pm esp_rom esp_security esp_system esp_timer esptool_py freertos hal heap log main mbedtls newlib partition_table pthread soc spi_flash xtensa -- Component paths: D:/esp/v5.5.5/esp-idf/components/app_update D:/esp/v5.5.5/esp-idf/components/bootloader D:/esp/v5.5.5/esp-idf/components/bootloader_support D:/esp/v5.5.5/esp-idf/components/cxx D:/esp/v5.5.5/esp-idf/components/efuse D:/esp/v5.5.5/esp-idf/components/esp_app_format D:/esp/v5.5.5/esp-idf/components/esp_bootloader_format D:/esp/v5.5.5/esp-idf/components/esp_common D:/esp/v5.5.5/esp-idf/components/esp_driver_gpio D:/esp/v5.5.5/esp-idf/components/esp_hw_support D:/esp/v5.5.5/esp-idf/components/esp_mm D:/esp/v5.5.5/esp-idf/components/esp_partition D:/esp/v5.5.5/esp-idf/components/esp_pm D:/esp/v5.5.5/esp-idf/components/esp_rom D:/esp/v5.5.5/esp-idf/components/esp_security D:/esp/v5.5.5/esp-idf/components/esp_system D:/esp/v5.5.5/esp-idf/components/esp_timer D:/esp/v5.5.5/esp-idf/components/esptool_py D:/esp/v5.5.5/esp-idf/components/freertos D:/esp/v5.5.5/esp-idf/components/hal D:/esp/v5.5.5/esp-idf/components/heap D:/esp/v5.5.5/esp-idf/components/log D:/workspace/esp/hello_world/main D:/esp/v5.5.5/esp-idf/components/mbedtls D:/esp/v5.5.5/esp-idf/components/newlib D:/esp/v5.5.5/esp-idf/components/partition_table D:/esp/v5.5.5/esp-idf/components/pthread D:/esp/v5.5.5/esp-idf/components/soc D:/esp/v5.5.5/esp-idf/components/spi_flash D:/esp/v5.5.5/esp-idf/components/xtensa -- Configuringdone(19.4s)-- Generatingdone(0.9s)-- Build files have been written to: D:/workspace/esp/hello_world/build[3/9]Generating binary image from built executable esptool.py v4.12.0 Creating esp32 image... Merged2ELF sections Successfully created esp32 image. Generated D:/workspace/esp/hello_world/build/hello_world.bin[4/9]C:\Windows\system32\cmd.exe /Ccd /D D:\workspace\esp\hello_world\build\esp-idf\esptool_py C:...llo_world/build/partition_table/partition-table.bin D:/workspace/esp/hello_world/build/hello_world.bin hello_world.bin binary size 0x21660 bytes. Smallest app partition is 0x100000 bytes. 0xde9a0 bytes (87%) free. [0/1] Re-running CMake... -- Component directory D:/esp/v5.5.5/esp-idf/components/esp_blockdev does not contain a CMakeLists.txt file. No component will be added -- Minimal build - OFF -- Building ESP-IDF components for target esp32 -- ESP-TEE is currently supported only on the esp32c6;esp32h2;esp32c5 SoCs -- Project sdkconfig file D:/workspace/esp/hello_world/sdkconfig -- Compiler supported targets: xtensa-esp-elf -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Adding linker script D:/esp/v5.5.5/esp-idf/components/soc/esp32/ld/esp32.peripherals.ld -- Bootloader project name: bootloader version: 1 -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.api.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.libgcc.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/esp_rom/esp32/ld/esp32.rom.libc-funcs.ld -- Adding linker script D:/esp/v5.5.5/esp-idf/components/bootloader/subproject/main/ld/esp32/bootloader.rom.ld -- Components: bootloader bootloader_support efuse esp_app_format esp_bootloader_format esp_common esp_hw_support esp_rom esp_security esp_system esptool_py freertos hal log main micro-ecc newlib partition_table soc spi_flash xtensa -- Component paths: D:/esp/v5.5.5/esp-idf/components/bootloader D:/esp/v5.5.5/esp-idf/components/bootloader_support D:/esp/v5.5.5/esp-idf/components/efuse D:/esp/v5.5.5/esp-idf/components/esp_app_format D:/esp/v5.5.5/esp-idf/components/esp_bootloader_format D:/esp/v5.5.5/esp-idf/components/esp_common D:/esp/v5.5.5/esp-idf/components/esp_hw_support D:/esp/v5.5.5/esp-idf/components/esp_rom D:/esp/v5.5.5/esp-idf/components/esp_security D:/esp/v5.5.5/esp-idf/components/esp_system D:/esp/v5.5.5/esp-idf/components/esptool_py D:/esp/v5.5.5/esp-idf/components/freertos D:/esp/v5.5.5/esp-idf/components/hal D:/esp/v5.5.5/esp-idf/components/log D:/esp/v5.5.5/esp-idf/components/bootloader/subproject/main D:/esp/v5.5.5/esp-idf/components/bootloader/subproject/components/micro-ecc D:/esp/v5.5.5/esp-idf/components/newlib D:/esp/v5.5.5/esp-idf/components/partition_table D:/esp/v5.5.5/esp-idf/components/soc D:/esp/v5.5.5/esp-idf/components/spi_flash D:/esp/v5.5.5/esp-idf/components/xtensa -- Adding linker script D:/esp/v5.5.5/esp-idf/components/bootloader/subproject/main/ld/esp32/bootloader.ld -- Configuring done (9.8s) -- Generating done (0.4s) -- Build files have been written to: D:/workspace/esp/hello_world/build/bootloader [1/2] C:\Windows\system32\cmd.exe /C cd/D D:\workspace\esp\hello_world\build\bootloader\esp-idf\espto...izes.py--offset0x8000 bootloader 0x1000 D:/workspace/esp/hello_world/build/bootloader/bootloader.bin Bootloader binary size 0x6610 bytes. 0x9f0 bytes(9%)free.[7/9]C:\Windows\system32\cmd.exe /Ccd /D D:\esp\v5.5.5\esp-idf\components\esptool_py C:\Espressif...:/workspace/esp/hello_world/build -P D:/esp/v5.5.5/esp-idf/components/esptool_py/run_serial_tool.cmake esptool.py --chip esp32 -p COM4 -b 460800 --beforedefault_reset --afterhard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 2MB 0x1000 bootloader/bootloader.bin 0x10000 hello_world.bin 0x8000 partition_table/partition-table.bin esptool.py v4.12.0 Serial port COM4 Connecting... A fatal error occurred: This chip is ESP32-S3, not ESP32. Wrong --chip argument? CMake Error at run_serial_tool.cmake:67 (message): C:/Espressif/tools/python/v5.5.5/venv/Scripts/python.exe;;D:/esp/v5.5.5/esp-idf/components/esptool_py/esptool/esptool.py;--chip;esp32 failed. FAILED: CMakeFiles/flash D:/workspace/esp/hello_world/build/CMakeFiles/flash C:\Windows\system32\cmd.exe /C cd/D D:\esp\v5.5.5\esp-idf\components\esptool_pyC:\Espressif\tools\cmake\3.30.2\bin\cmake.exe-DIDF_PATHD:/esp/v5.5.5/esp-idf-DSERIAL_TOOLC:/Espressif/tools/python/v5.5.5/venv/Scripts/python.exe;;D:/esp/v5.5.5/esp-idf/components/esptool_py/esptool/esptool.py;--chip;esp32-DSERIAL_TOOL_ARGS--beforedefault_reset;--afterhard_reset;write_flash;flash_args-DWORKING_DIRECTORYD:/workspace/esp/hello_world/build-PD:/esp/v5.5.5/esp-idf/components/esptool_py/run_serial_tool.cmake ninja: build stopped: subcommand failed. ninja failed withexitcode1, output of thecommandisinthe D:\workspace\esp\hello_world\build\log\idf_py_stderr_output_5308 and D:\workspace\esp\hello_world\build\log\idf_py_stdout_output_5308(venv)PS D:\workspace\esp\hello_world在日志中看到A fatal error occurred: This chip is ESP32-S3, not ESP32. Wrong --chip argument?CMake Error at run_serial_tool.cmake:67 (message):对这次日志已经把问题定位得非常清楚了。你的开发板实际上是 ESP32-S3而你的项目目前按照普通 ESP32 在烧录。最关键的一行A fatal error occurred: This chip is ESP32-S3, not ESP32. Wrong --chip argument?也就是说现在的情况是你的开发板ESP32-S3 ↓ 当前项目配置ESP32 ↓ esptool--chip esp32 ↓ 发现芯片其实是 ESP32-S3 ↓ 烧录失败解决方法你需要把项目的 Target 从esp32改成esp32s3。在当前项目cd D:\workspace\esp\hello_world执行idf.pyset-targetesp32s3正常应该会看到类似Set Target to: esp32s3, new sdkconfig will be created.然后重新编译idf.py build最后烧录idf.py-p COM4 flash这次就烧录成功了。监视输出可以使用 idf.py -p PORT monitor 命令监视 “hello_world” 项目的运行情况。注意不要忘记将 PORT 替换为自己的串口名称。运行该命令后IDF 监视器 应用程序将启动。我这里显示的内容如下(venv)PS D:\workspace\esp\hello_worldidf.py monitor Executing action: monitor Serial port COM4 Connecting... Detecting chip type... ESP32-S3 Running idf_monitorindirectory D:\workspace\esp\hello_world ExecutingC:\Espressif\tools\python\v5.5.5\venv\Scripts\python.exe D:\esp\v5.5.5\esp-idf\tools/idf_monitor.py -p COM4 -b 115200 --toolchain-prefix xtensa-esp32s3-elf- --target esp32s3 --revision 0 D:\workspace\esp\hello_world\build\hello_world.elf D:\workspace\esp\hello_world\build\bootloader\bootloader.elf --force-color -m C:\Espressif\tools\python\v5.5.5\venv\Scripts\python.exe D:\esp\v5.5.5\esp-idf\tools\idf.py... --- WARNING: GDB cannotopenserial ports accessed as COMx --- NOTE: Using\\.\COM4 instead... --- esp-idf-monitor1.10.0 on\\.\COM4115200--- Quit: Ctrl]|Menu: CtrlT|Help: CtrlT followed by CtrlH ESP-ROM:esp32s3-20210327 Build:Mar272021rst:0x15(USB_UART_CHIP_RESET),boot:0x0(DOWNLOAD(USB/UART0))Saved PC:0x40048d14 --- 0x40048d14: uart_rx_one_charinROM waitingfordownload并没有我想要的hello world的输出。对烧录已经成功了。现在的问题也很明确boot:0x0 (DOWNLOAD(USB/UART0)) waiting for download说明你的 ESP32-S3现在还停留在下载模式没有启动刚才写进去的hello_world程序。现在这样做先退出当前 monitorCtrl ]然后不要按 BOOT直接按一下开发板上的RST / RESET / EN然后重新idf.py monitor或者更简单idf.py-p COM4 monitor正常情况下应该看到类似Hello world! This is ESP32-S3 chip with 2 CPU cores Chip revision: v0.2 ... Restarting in 10 seconds...如果你的hello_world是 ESP-IDF 自带的经典示例它会不断输出类似I (251) main_task: Calling app_main() Hello world! This is esp32s3 chip with 2 CPU core(s), WiFi/BLE, silicon revision v0.2, 2MB external flash Minimum free heap size: 391992 bytes Restarting in 10 seconds... Restarting in 9 seconds... Restarting in 8 seconds...