Починаєм новий проект
Нам потрібна нова діректорія для нового проєкту
Активуєм оточення
$ get_idf
Новий проект
$ idf.py create-project test_idf
$ cd test_idf
# Додаємо лінк на файл, щоб корректно працював coc LSP для vim
$ ln -sf build/compile_commands.json .
Настройка проекту
Універмальна команда, яку завжди потрібно пам'ятати
idf.py menuconfigАле якщо потрібно просто швидке налаштування, то читаємо далі
$ idf.py set-target esp32s3
Якщо потрібна додаткова інформація, то
$ idf.py help
Компіляція та прошивка
Build the project by running:
$ idf.py build
This command compiles the application and all ESP-IDF components, then it generates the bootloader, partition table, and application binaries.
$ idf.py build
Running cmake in directory /path/to/hello_world/build
Executing "cmake -G Ninja --warn-uninitialized /path/to/hello_world"...
Warn about uninitialized values.
-- Found Git: /usr/bin/git (found version "2.17.0")
-- Building empty aws_iot component due to configuration
-- Component names: ...
-- Component paths: ...
... (more lines of build system output)
[527/527] Generating hello_world.bin
esptool.py v2.3.1
Project build complete. To flash, run this command:
../../../components/esptool_py/esptool/esptool.py -p (PORT) -b 921600 write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x10000 build/hello_world.bin build 0x1000 build/bootloader/bootloader.bin 0x8000 build/partition_table/partition-table.bin
or run 'idf.py -p PORT flash'
If there are no errors, the build finishes by generating the firmware binary .bin files.
Flash onto the Device
To flash the binaries that you just built for the ESP32 in the previous step, you need to run the following command:
$ idf.py -p PORT flash
Replace PORT with your ESP32 board's USB port name.
If the PORT is not defined, the idf.py will try to connect automatically using the available USB ports.
For more information on idf.py arguments, see idf.py.
Note
The option flash automatically builds and flashes the project, so running idf.py build is not necessary.
Encountered Issues While Flashing? See the "Additional Tips" below. You can also refer to Flashing Troubleshooting page or Establish Serial Connection with ESP32 for more detailed information. Normal Operation
When flashing, you will see the output log similar to the following:
...
esptool.py --chip esp32 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 2MB 0x8000 partition_table/partition-table.bin 0x1000 bootloader/bootloader.bin 0x10000 hello_world.bin
esptool.py v3.0-dev
Serial port /dev/ttyUSB0
Connecting........_
Chip is ESP32D0WDQ6 (revision 0)
Features: WiFi, BT, Dual Core, Coding Scheme None
Crystal is 40MHz
MAC: 24:0a:c4:05:b9:14
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Compressed 3072 bytes to 103...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 5962.8 kbit/s)...
Hash of data verified.
Compressed 26096 bytes to 15408...
Writing at 0x00001000... (100 %)
Wrote 26096 bytes (15408 compressed) at 0x00001000 in 0.4 seconds (effective 546.7 kbit/s)...
Hash of data verified.
Compressed 147104 bytes to 77364...
Writing at 0x00010000... (20 %)
Writing at 0x00014000... (40 %)
Writing at 0x00018000... (60 %)
Writing at 0x0001c000... (80 %)
Writing at 0x00020000... (100 %)
Wrote 147104 bytes (77364 compressed) at 0x00010000 in 1.9 seconds (effective 615.5 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
Done
If there are no issues by the end of the flash process, the board will reboot and start up the application.
Monitor the Output
Type
$ idf.py -p PORT monitor
(Do not forget to replace PORT with your serial port name).
This command launches the IDF Monitor application.
$ idf.py -p <PORT> monitor
Running idf_monitor in directory [...]/esp/hello_world/build
Executing "python [...]/esp-idf/tools/idf_monitor.py -b 115200 [...]/esp/hello_world/build/hello_world.elf"...
--- idf_monitor on <PORT> 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun 8 2016 00:22:57
...
To exit IDF monitor use the shortcut Ctrl+].
If you have such a problem, do the following:
Exit the monitor.
Go back to menuconfig.
Go to Component config
--> Hardware Settings
--> Main XTAL Config
--> Main XTAL frequency,
then change CONFIG_XTAL_FREQ to 26 MHz.
After that, build and flash the application again.
In the current version of ESP-IDF, main XTAL frequencies supported by ESP32 are as follows:
26 MHz
40 MHz
Note
You can combine building, flashing and monitoring into one step by running:
$ idf.py -p PORT flash monitor
See also:
- IDF Monitor for handy shortcuts and more details on using IDF monitor.
- idf.py for a full reference of idf.py commands and options.
That is all that you need to get started with ESP32!
Now you are ready to try some other examples, or go straight to developing your own applications.
Important
Some of examples do not support ESP32 because required hardware is not included in ESP32 so it cannot be supported.
If building an example, please check the README file for the Supported Targets table. If this is present including ESP32 target, or the table does not exist at all, the example will work on ESP32.