Как настроить VisualStudioCode для работы с ESP-IDF? Windows 10
в наличии esp-wroom-32-devkit, Windows 10, Visual Studio Code, проставка между монитором и креслом желающая подключить к муфельной печи всю мощщь двух ядер и С++. (и да, у меня алергия на ардуино)
(а если серъезно, то если продавать продукт, то он не должен быть написан на детском конструкторе)
А ещё я пробовал с микропитоном: очень легко, очень удобно, но медленно, криво и взрослые дядьки так не делают.
Что у нас есть. Репозиторий от Espressif.
Инструкция по установке два (от производителя).
Еще есть три но я там ничего не высмотрел. И четыре, но там субтитры не подключаются. И ещё есть пять но с Eclipse у меня вообще ничего не получилось.
Ну и get started от китайцев.
Ну помигать светодиодом у меня получилось. А ещё получилось запустить тестовый файл с SPI_TFT_ST7735 (обязательно подключайте LED/подсветку)
Теперь открываем товарища Нейла Колбана. Я честно пыталя повторить за ним по Eclipse для виндовс, но не получилось, короче.
Методом проб и ошибок я нашаманил себе следующий файл c_cpp_properties.json (мануалов-то нет человеческих с объяснением ПОШАГОВЫМ зачем что как, для тупеньких вроде меня)
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${default}",
"C:/cidf/**",
"C:/.espressif/**",
"C:/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/**",
"C:/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}
Да, все что связано с ESP-IDF я установил в корень С:.
После команды idf.py build в папке проекта генерируется огромная папка в которой, в том числе, компилируется "прошивка" - бинарный файл который через команду idf.py -p COM# flash мы отправляем на ESP32. В том числе папка build и файл compile_commands.json. Вот после всего этого шаманизма VScode выдает вот такую штуку (штук двадцать таких штук).
[20.02.2021, 02:29:23] Для исходных файлов C IntelliSenseMode был
изменен с "windows-msvc-x64" на "windows-gcc-x64" на основе аргументов
компилятора и compilerPath запроса: "C:\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-
esp32-elf\bin\xtensa-esp32-elf-gcc.exe"
И перестает ругаться, что ему не видно стандартных файлов заголовков. Файл compile_commands.json, в свою очередь содердит чуть больше тычачи вот таких вот строчек.
{
"directory": "C:/cpp/one/build",
"command": "C:\\.espressif\\tools\\xtensa-esp32-elf\\esp-2020r3-8.4.0\\xtensa-esp32-elf\\bin\\xtensa-esp32-elf-gcc.exe -DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE=\\\"mbedtls/esp_config.h\\\" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -IC:/cidf/components/esp_pm/include -Iconfig -IC:/cidf/components/newlib/platform_include -IC:/cidf/components/freertos/include -IC:/cidf/components/freertos/port/xtensa/include -IC:/cidf/components/esp_hw_support/include -IC:/cidf/components/esp_hw_support/port/esp32/. -IC:/cidf/components/heap/include -IC:/cidf/components/log/include -IC:/cidf/components/lwip/include/apps -IC:/cidf/components/lwip/include/apps/sntp -IC:/cidf/components/lwip/lwip/src/include -IC:/cidf/components/lwip/port/esp32/include -IC:/cidf/components/lwip/port/esp32/include/arch -IC:/cidf/components/soc/include -IC:/cidf/components/soc/esp32/. -IC:/cidf/components/soc/esp32/include -IC:/cidf/components/hal/esp32/include -IC:/cidf/components/hal/include -IC:/cidf/components/esp_rom/include -IC:/cidf/components/esp_rom/esp32 -IC:/cidf/components/esp_common/include -IC:/cidf/components/esp_system/include -IC:/cidf/components/esp32/include -IC:/cidf/components/driver/include -IC:/cidf/components/driver/esp32/include -IC:/cidf/components/esp_ringbuf/include -IC:/cidf/components/efuse/include -IC:/cidf/components/efuse/esp32/include -IC:/cidf/components/xtensa/include -IC:/cidf/components/xtensa/esp32/include -IC:/cidf/components/espcoredump/include -IC:/cidf/components/esp_timer/include -IC:/cidf/components/esp_ipc/include -IC:/cidf/components/vfs/include -IC:/cidf/components/esp_wifi/include -IC:/cidf/components/esp_wifi/esp32/include -IC:/cidf/components/esp_event/include -IC:/cidf/components/esp_netif/include -IC:/cidf/components/esp_eth/include -IC:/cidf/components/tcpip_adapter/include -IC:/cidf/components/app_trace/include -IC:/cidf/components/mbedtls/port/include -IC:/cidf/components/mbedtls/mbedtls/include -IC:/cidf/components/mbedtls/esp_crt_bundle/include -IC:/cidf/components/bootloader_support/include -IC:/cidf/components/app_update/include -IC:/cidf/components/spi_flash/include -IC:/cidf/components/nvs_flash/include -IC:/cidf/components/pthread/include -IC:/cidf/components/esp_gdbstub/include -IC:/cidf/components/esp_gdbstub/xtensa -IC:/cidf/components/esp_gdbstub/esp32 -IC:/cidf/components/wpa_supplicant/include -IC:/cidf/components/wpa_supplicant/port/include -IC:/cidf/components/wpa_supplicant/include/esp_supplicant -IC:/cidf/components/perfmon/include -IC:/cidf/components/asio/asio/asio/include -IC:/cidf/components/asio/port/include -IC:/cidf/components/cbor/port/include -IC:/cidf/components/unity/include -IC:/cidf/components/unity/unity/src -IC:/cidf/components/cmock/CMock/src -IC:/cidf/components/coap/port/include -IC:/cidf/components/coap/port/include/coap -IC:/cidf/components/coap/libcoap/include -IC:/cidf/components/coap/libcoap/include/coap2 -IC:/cidf/components/console -IC:/cidf/components/nghttp/port/include -IC:/cidf/components/nghttp/nghttp2/lib/includes -IC:/cidf/components/esp-tls -IC:/cidf/components/esp-tls/esp-tls-crypto -IC:/cidf/components/esp_adc_cal/include -IC:/cidf/components/esp_hid/include -IC:/cidf/components/tcp_transport/include -IC:/cidf/components/esp_http_client/include -IC:/cidf/components/esp_http_server/include -IC:/cidf/components/esp_https_ota/include -IC:/cidf/components/protobuf-c/protobuf-c -IC:/cidf/components/protocomm/include/common -IC:/cidf/components/protocomm/include/security -IC:/cidf/components/protocomm/include/transports -IC:/cidf/components/mdns/include -IC:/cidf/components/esp_local_ctrl/include -IC:/cidf/components/sdmmc/include -IC:/cidf/components/esp_serial_slave_link/include -IC:/cidf/components/esp_websocket_client/include -IC:/cidf/components/expat/expat/expat/lib -IC:/cidf/components/expat/port/include -IC:/cidf/components/wear_levelling/include -IC:/cidf/components/fatfs/diskio -IC:/cidf/components/fatfs/vfs -IC:/cidf/components/fatfs/src -IC:/cidf/components/freemodbus/common/include -IC:/cidf/components/idf_test/include -IC:/cidf/components/idf_test/include/esp32 -IC:/cidf/components/jsmn/include -IC:/cidf/components/json/cJSON -IC:/cidf/components/libsodium/libsodium/src/libsodium/include -IC:/cidf/components/libsodium/port_include -IC:/cidf/components/mqtt/esp-mqtt/include -IC:/cidf/components/openssl/include -IC:/cidf/components/spiffs/include -IC:/cidf/components/ulp/include -IC:/cidf/components/wifi_provisioning/include -I../main -mlongcalls -Wno-frame-address -o CMakeFiles\\main.elf.dir\\project_elf_src_esp32.c.obj -c C:\\cpp\\one\\build\\project_elf_src_esp32.c",
"file": "C:/cpp/one/build/project_elf_src_esp32.c"
},
Возвращаемся к колбану и пытаемся скомпилировать и запустить его пример Файл компилируется и естественно ничего не происходит. С замиранием сердца немного правим код.
static char tag[]="cpp_helloworld";
extern "C" {
void app_main(void);
}
class Greeting {
public:
void helloEnglish() {
//ESP_LOGD(tag, "Hello %s", name.c_str());
std::cout << tag << "hello" <<name.c_str();
}
void helloFrench() {
ESP_LOGD(tag, "Bonjour %s", name.c_str());
}
void setName(std::string name) {
this->name = name;
}
private:
std::string name = "";
};
void app_main(void)
{
Greeting myGreeting;
myGreeting.setName("Neil");
myGreeting.helloEnglish();
myGreeting.helloFrench();
}
Компилируем командой build, заливаем idf.py -p COM# flash
c:\cpp\one>idf.py -p COM6 monitor
Executing action: monitor
Running idf_monitor in directory c:\cpp\one
Executing "C:\.espressif\python_env\idf4.4_py3.9_env\Scripts\python.exe C:\cidf\tools/idf_monitor.py
-p COM6 -b 115200 --toolchain-prefix xtensa-esp32-elf- c:\cpp\one\build\main.elf -m
'C:\.espressif\python_env\idf4.4_py3.9_env\Scripts\python.exe' 'C:\cidf\tools\idf.py' '-p' 'COM6'"...
[0;33m--- WARNING: GDB cannot open serial ports accessed as COMx[0m
[0;33m--- Using \\.\COM6 instead...[0m
--- idf_monitor on \\.\COM6 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)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6828
ho 0 tail 12 room 4
load:0x40078000,len:14336
load:0x40080400,len:3672
0x40080400: _init at ??:?
entry 0x40080678
I (28) boot: ESP-IDF v4.4-dev-4-g73db14240 2nd stage bootloader
I (28) boot: compile time 22:57:00
I (29) boot: chip revision: 1
I (33) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (40) boot.esp32: SPI Speed : 40MHz
I (44) boot.esp32: SPI Mode : DIO
I (49) boot.esp32: SPI Flash Size : 2MB
I (53) boot: Enabling RNG early entropy source...
I (59) boot: Partition Table:
I (62) boot: ## Label Usage Type ST Offset Length
I (70) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (77) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (85) boot: 2 factory factory app 00 00 00010000 00100000
I (92) boot: End of partition table
I (96) boot_comm: chip revision: 1, min. application chip revision: 0
I (103) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=17268h ( 94824) map
I (145) esp_image: segment 1: paddr=00027290 vaddr=3ffb0000 size=02904h ( 10500) load
I (150) esp_image: segment 2: paddr=00029b9c vaddr=40080000 size=0647ch ( 25724) load
I (161) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=3daa4h (252580) map
I (251) esp_image: segment 4: paddr=0006dacc vaddr=4008647c size=04a40h ( 19008) load
I (265) boot: Loaded app from partition at offset 0x10000
I (265) boot: Disabling RNG early entropy source...
I (276) cpu_start: Pro cpu up.
I (276) cpu_start: Starting app cpu, entry point is 0x400810b8
0x400810b8: call_start_cpu1 at C:/cidf/components/esp_system/port/cpu_start.c:143
I (0) cpu_start: App cpu up.
I (291) cpu_start: Pro cpu start user code
I (291) cpu_start: cpu freq: 160000000
I (291) cpu_start: Application information:
I (295) cpu_start: Project name: main
I (300) cpu_start: App version: 1
I (304) cpu_start: Compile time: Feb 19 2021 22:56:38
I (311) cpu_start: ELF file SHA256: f6d675f2bc8996f4...
I (316) cpu_start: ESP-IDF: v4.4-dev-4-g73db14240
I (323) heap_init: Initializing. RAM available for dynamic allocation:
I (330) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (336) heap_init: At 3FFB4788 len 0002B878 (174 KiB): DRAM
I (342) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (349) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (355) heap_init: At 4008AEBC len 00015144 (84 KiB): IRAM
I (362) spi_flash: detected chip: generic
I (366) spi_flash: flash io: dio
W (370) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using
the size in the binary image header.
I (387) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
И снова ничего. Читаем.
/*
* 1. Open up the project properties
* 2. Visit C/C++ General > Preprocessor Include Paths, Macros, etc
* 3. Select the Providers tab
* 4. Check the box for "CDT GCC Built-in Compiler Settings"
* 5. Set the compiler spec command to "xtensa-esp32-elf-gcc ${FLAGS} -E -P -v -dD "${INPUTS}""
* 6. Rebuild the index
*/
Set the compiler spec command to "xtensa-esp32-elf-gcc ${FLAGS} -E -P -v -dD "${INPUTS}""
Ну в общем как-то так. Я даже не знаю что у гугла спросить. при этом пишу я в VScode, а команды через терминал ввожу. Из расширений на данный момент только С/С++. Даже Espressif-IDF (из инструкции) снес.
что и где изменить, чтобы мой микроконтроллер воспроизводил код с классами на С++ (просто <iostream> cout<<X; работают. но без классов можно и на С писать)
Ну и каак настроить VScode для работы с ESP-IDF.
Ответы (2 шт):
Сделайте все точно по инструкции от производителя. Причем, очень важно выполнить часть "Open Example Project" так, как там показано, и у вас автоматом создаются все файлы JSON в папке .vscode проекта.
До этого я установил ESP-IDF по инструкции отдельно, и проверил, а потом уже в VS Code подключил ESP-IDF extension, выбрав EXISTING.
Все работает.
Для меньшего порога вхождения используйте PlatformIO. https://docs.platformio.org/en/latest/frameworks/espidf.html настраивается сама, качает все сама.