Using esp-idf with vscode adding custom component

Thread Starter

zazas321

Joined Nov 29, 2015
926
Hello. I am trying to use esp-idf with vscode but so far I only hate it. Everyting is made very complex compared to Arduino platform and I cannot get anything to work out of the box. Everything needs tinkering, changing various configurations, environemnt paths and etc.


I have now got an issue with adding a custom component. According to the esp-idf documentation all I need to do to create to include my own custom component is to create components directory, in that directory, I create a folder for my library which includes 3 files:
1. .c file
2. .h file
3. CMakeLists.txt file


1628679069145.png

And that is exactly what I have done. In my project directory, I have created created components/test and in there I have test.c, test.h, and CMakeLists.txt

In my CMakeLists.txt I have added the following:
Code:
idf_component_register(SRCS "test.c"
                    INCLUDE_DIRS "")

All I am trying to do now, is to include "test.h" in my main.c but I am getting an error :
Code:
> Executing task: cmake --build . <

[1/9] Performing build step for 'bootloader'
ninja: no work to do.
[2/7] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/main.c.obj
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/main.c.obj 
C:\Users\petrikas.lu\.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 -Iconfig -IC:/Users/petrikas.lu/esp/esp-idf/components/newlib/platform_include -IC:/Users/petrikas.lu/esp/esp-idf/components/freertos/include -IC:/Users/petrikas.lu/esp/esp-idf/components/freertos/port/xtensa/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_hw_support/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_hw_support/port/esp32/. -IC:/Users/petrikas.lu/esp/esp-idf/components/heap/include -IC:/Users/petrikas.lu/esp/esp-idf/components/log/include -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/include/apps -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/include/apps/sntp -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/lwip/src/include -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/port/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/port/esp32/include/arch -IC:/Users/petrikas.lu/esp/esp-idf/components/soc/include -IC:/Users/petrikas.lu/esp/esp-idf/components/soc/esp32/. -IC:/Users/petrikas.lu/esp/esp-idf/components/soc/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/hal/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/hal/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_rom/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_rom/esp32 -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_common/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_system/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/driver/include -IC:/Users/petrikas.lu/esp/esp-idf/components/driver/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_ringbuf/include -IC:/Users/petrikas.lu/esp/esp-idf/components/efuse/include -IC:/Users/petrikas.lu/esp/esp-idf/components/efuse/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/xtensa/include -IC:/Users/petrikas.lu/esp/esp-idf/components/xtensa/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/espcoredump/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_timer/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_ipc/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_pm/include -IC:/Users/petrikas.lu/esp/esp-idf/components/vfs/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_wifi/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_wifi/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_event/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_netif/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_eth/include -IC:/Users/petrikas.lu/esp/esp-idf/components/tcpip_adapter/include -IC:/Users/petrikas.lu/esp/esp-idf/components/app_trace/include -IC:/Users/petrikas.lu/esp/esp-idf/components/mbedtls/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/mbedtls/mbedtls/include -IC:/Users/petrikas.lu/esp/esp-idf/components/mbedtls/esp_crt_bundle/include -IC:/Users/petrikas.lu/esp/esp-idf/components/app_update/include -IC:/Users/petrikas.lu/esp/esp-idf/components/spi_flash/include -IC:/Users/petrikas.lu/esp/esp-idf/components/bootloader_support/include -IC:/Users/petrikas.lu/esp/esp-idf/components/nvs_flash/include -IC:/Users/petrikas.lu/esp/esp-idf/components/pthread/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_gdbstub/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_gdbstub/xtensa -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_gdbstub/esp32 -IC:/Users/petrikas.lu/esp/esp-idf/components/wpa_supplicant/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wpa_supplicant/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wpa_supplicant/include/esp_supplicant -IC:/Users/petrikas.lu/esp/esp-idf/components/perfmon/include -IC:/Users/petrikas.lu/esp/esp-idf/components/asio/asio/asio/include -IC:/Users/petrikas.lu/esp/esp-idf/components/asio/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/cbor/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/unity/include -IC:/Users/petrikas.lu/esp/esp-idf/components/unity/unity/src -IC:/Users/petrikas.lu/esp/esp-idf/components/cmock/CMock/src -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/port/include/coap -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/libcoap/include -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/libcoap/include/coap2 -IC:/Users/petrikas.lu/esp/esp-idf/components/console -IC:/Users/petrikas.lu/esp/esp-idf/components/nghttp/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/nghttp/nghttp2/lib/includes -IC:/Users/petrikas.lu/esp/esp-idf/components/esp-tls -IC:/Users/petrikas.lu/esp/esp-idf/components/esp-tls/esp-tls-crypto -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_adc_cal/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_hid/include -IC:/Users/petrikas.lu/esp/esp-idf/components/tcp_transport/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_http_client/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_http_server/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_https_ota/include -IC:/Users/petrikas.lu/esp/esp-idf/components/protobuf-c/protobuf-c -IC:/Users/petrikas.lu/esp/esp-idf/components/protocomm/include/common -IC:/Users/petrikas.lu/esp/esp-idf/components/protocomm/include/security -IC:/Users/petrikas.lu/esp/esp-idf/components/protocomm/include/transports -IC:/Users/petrikas.lu/esp/esp-idf/components/mdns/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_local_ctrl/include -IC:/Users/petrikas.lu/esp/esp-idf/components/sdmmc/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_serial_slave_link/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_websocket_client/include -IC:/Users/petrikas.lu/esp/esp-idf/components/expat/expat/expat/lib -IC:/Users/petrikas.lu/esp/esp-idf/components/expat/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wear_levelling/include -IC:/Users/petrikas.lu/esp/esp-idf/components/fatfs/diskio -IC:/Users/petrikas.lu/esp/esp-idf/components/fatfs/vfs -IC:/Users/petrikas.lu/esp/esp-idf/components/fatfs/src -IC:/Users/petrikas.lu/esp/esp-idf/components/freemodbus/common/include -IC:/Users/petrikas.lu/esp/esp-idf/components/jsmn/include -IC:/Users/petrikas.lu/esp/esp-idf/components/json/cJSON -IC:/Users/petrikas.lu/esp/esp-idf/components/libsodium/libsodium/src/libsodium/include -IC:/Users/petrikas.lu/esp/esp-idf/components/libsodium/port_include -IC:/Users/petrikas.lu/esp/esp-idf/components/mqtt/esp-mqtt/include -IC:/Users/petrikas.lu/esp/esp-idf/components/openssl/include -IC:/Users/petrikas.lu/esp/esp-idf/components/spiffs/include -IC:/Users/petrikas.lu/esp/esp-idf/components/ulp/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wifi_provisioning/include -mlongcalls -Wno-frame-address   -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -std=gnu99 -Wno-old-style-declaration -D_GNU_SOURCE -DIDF_VER=\"v4.3-dirty\" -DESP_PLATFORM -MD -MT esp-idf/main/CMakeFiles/__idf_main.dir/main.c.obj -MF esp-idf\main\CMakeFiles\__idf_main.dir\main.c.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/main.c.obj   -c ../main/main.c
../main/main.c:18:10: fatal error: test.h: No such file or directory
 #include "test.h"
          ^~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command cmake --build ." terminated with exit code: 1.

Please can someone help me understand how to do it properly when creating my own custom libraries
 
Hello. I am trying to use esp-idf with vscode but so far I only hate it. Everyting is made very complex compared to Arduino platform and I cannot get anything to work out of the box. Everything needs tinkering, changing various configurations, environemnt paths and etc.


I have now got an issue with adding a custom component. According to the esp-idf documentation all I need to do to create to include my own custom component is to create components directory, in that directory, I create a folder for my library which includes 3 files:
1. .c file
2. .h file
3. CMakeLists.txt file


View attachment 245374

And that is exactly what I have done. In my project directory, I have created created components/test and in there I have test.c, test.h, and CMakeLists.txt

In my CMakeLists.txt I have added the following:
Code:
idf_component_register(SRCS "test.c"
                    INCLUDE_DIRS "")

All I am trying to do now, is to include "test.h" in my main.c but I am getting an error :
Code:
> Executing task: cmake --build . <

[1/9] Performing build step for 'bootloader'
ninja: no work to do.
[2/7] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/main.c.obj
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/main.c.obj
C:\Users\petrikas.lu\.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 -Iconfig -IC:/Users/petrikas.lu/esp/esp-idf/components/newlib/platform_include -IC:/Users/petrikas.lu/esp/esp-idf/components/freertos/include -IC:/Users/petrikas.lu/esp/esp-idf/components/freertos/port/xtensa/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_hw_support/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_hw_support/port/esp32/. -IC:/Users/petrikas.lu/esp/esp-idf/components/heap/include -IC:/Users/petrikas.lu/esp/esp-idf/components/log/include -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/include/apps -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/include/apps/sntp -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/lwip/src/include -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/port/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/port/esp32/include/arch -IC:/Users/petrikas.lu/esp/esp-idf/components/soc/include -IC:/Users/petrikas.lu/esp/esp-idf/components/soc/esp32/. -IC:/Users/petrikas.lu/esp/esp-idf/components/soc/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/hal/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/hal/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_rom/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_rom/esp32 -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_common/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_system/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/driver/include -IC:/Users/petrikas.lu/esp/esp-idf/components/driver/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_ringbuf/include -IC:/Users/petrikas.lu/esp/esp-idf/components/efuse/include -IC:/Users/petrikas.lu/esp/esp-idf/components/efuse/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/xtensa/include -IC:/Users/petrikas.lu/esp/esp-idf/components/xtensa/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/espcoredump/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_timer/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_ipc/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_pm/include -IC:/Users/petrikas.lu/esp/esp-idf/components/vfs/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_wifi/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_wifi/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_event/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_netif/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_eth/include -IC:/Users/petrikas.lu/esp/esp-idf/components/tcpip_adapter/include -IC:/Users/petrikas.lu/esp/esp-idf/components/app_trace/include -IC:/Users/petrikas.lu/esp/esp-idf/components/mbedtls/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/mbedtls/mbedtls/include -IC:/Users/petrikas.lu/esp/esp-idf/components/mbedtls/esp_crt_bundle/include -IC:/Users/petrikas.lu/esp/esp-idf/components/app_update/include -IC:/Users/petrikas.lu/esp/esp-idf/components/spi_flash/include -IC:/Users/petrikas.lu/esp/esp-idf/components/bootloader_support/include -IC:/Users/petrikas.lu/esp/esp-idf/components/nvs_flash/include -IC:/Users/petrikas.lu/esp/esp-idf/components/pthread/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_gdbstub/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_gdbstub/xtensa -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_gdbstub/esp32 -IC:/Users/petrikas.lu/esp/esp-idf/components/wpa_supplicant/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wpa_supplicant/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wpa_supplicant/include/esp_supplicant -IC:/Users/petrikas.lu/esp/esp-idf/components/perfmon/include -IC:/Users/petrikas.lu/esp/esp-idf/components/asio/asio/asio/include -IC:/Users/petrikas.lu/esp/esp-idf/components/asio/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/cbor/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/unity/include -IC:/Users/petrikas.lu/esp/esp-idf/components/unity/unity/src -IC:/Users/petrikas.lu/esp/esp-idf/components/cmock/CMock/src -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/port/include/coap -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/libcoap/include -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/libcoap/include/coap2 -IC:/Users/petrikas.lu/esp/esp-idf/components/console -IC:/Users/petrikas.lu/esp/esp-idf/components/nghttp/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/nghttp/nghttp2/lib/includes -IC:/Users/petrikas.lu/esp/esp-idf/components/esp-tls -IC:/Users/petrikas.lu/esp/esp-idf/components/esp-tls/esp-tls-crypto -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_adc_cal/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_hid/include -IC:/Users/petrikas.lu/esp/esp-idf/components/tcp_transport/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_http_client/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_http_server/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_https_ota/include -IC:/Users/petrikas.lu/esp/esp-idf/components/protobuf-c/protobuf-c -IC:/Users/petrikas.lu/esp/esp-idf/components/protocomm/include/common -IC:/Users/petrikas.lu/esp/esp-idf/components/protocomm/include/security -IC:/Users/petrikas.lu/esp/esp-idf/components/protocomm/include/transports -IC:/Users/petrikas.lu/esp/esp-idf/components/mdns/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_local_ctrl/include -IC:/Users/petrikas.lu/esp/esp-idf/components/sdmmc/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_serial_slave_link/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_websocket_client/include -IC:/Users/petrikas.lu/esp/esp-idf/components/expat/expat/expat/lib -IC:/Users/petrikas.lu/esp/esp-idf/components/expat/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wear_levelling/include -IC:/Users/petrikas.lu/esp/esp-idf/components/fatfs/diskio -IC:/Users/petrikas.lu/esp/esp-idf/components/fatfs/vfs -IC:/Users/petrikas.lu/esp/esp-idf/components/fatfs/src -IC:/Users/petrikas.lu/esp/esp-idf/components/freemodbus/common/include -IC:/Users/petrikas.lu/esp/esp-idf/components/jsmn/include -IC:/Users/petrikas.lu/esp/esp-idf/components/json/cJSON -IC:/Users/petrikas.lu/esp/esp-idf/components/libsodium/libsodium/src/libsodium/include -IC:/Users/petrikas.lu/esp/esp-idf/components/libsodium/port_include -IC:/Users/petrikas.lu/esp/esp-idf/components/mqtt/esp-mqtt/include -IC:/Users/petrikas.lu/esp/esp-idf/components/openssl/include -IC:/Users/petrikas.lu/esp/esp-idf/components/spiffs/include -IC:/Users/petrikas.lu/esp/esp-idf/components/ulp/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wifi_provisioning/include -mlongcalls -Wno-frame-address   -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -std=gnu99 -Wno-old-style-declaration -D_GNU_SOURCE -DIDF_VER=\"v4.3-dirty\" -DESP_PLATFORM -MD -MT esp-idf/main/CMakeFiles/__idf_main.dir/main.c.obj -MF esp-idf\main\CMakeFiles\__idf_main.dir\main.c.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/main.c.obj   -c ../main/main.c
../main/main.c:18:10: fatal error: test.h: No such file or directory
#include "test.h"
          ^~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command cmake --build ." terminated with exit code: 1.

Please can someone help me understand how to do it properly when creating my own custom libraries
Try creating a "include" folder inside "test", it is working for me, and edit CMakeLists.txt like this:

idf_component_register(
SRCS "test.c"
INCLUDE_DIRS "include"
)
 

Attachments

nvmd

Joined Jan 6, 2019
1
Everyting is made very complex compared to Arduino platform and I cannot get anything to work out of the box. Everything needs tinkering, changing various configurations, environemnt paths and etc.
And I hate Arduino for sacrificing power to cater to casuals and people who won't bother to read. But such is life.
You can have idf tools create the component for you to save you from such arduous task.
idf.py create-component -C components/ test
 
Top