{"id":4657,"date":"2019-06-05T17:05:16","date_gmt":"2019-06-06T00:05:16","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=4657"},"modified":"2025-09-09T19:29:18","modified_gmt":"2025-09-10T02:29:18","slug":"using-esp32-arduino-core-as-a-component-in-esp-idf-projects","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/esp32\/arduino\/component\/","title":{"rendered":"Using ESP32 Arduino Core as a Component in ESP-IDF Projects"},"content":{"rendered":"<p>This tutorial shows how to use the <a href=\"https:\/\/github.com\/espressif\/arduino-esp32\">ESP32 Arduino core<\/a> as a component in the Advanced ESP-IDF-based projects. This setup allows combining the easy Arduino-style APIs with the advanced libraries and configuration options of the ESP-IDF. However, it requires additional initial setup that will be shown in this tutorial.<\/p>\n<p>Before you begin, install VisualGDB 5.4R6 or later.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB ESP32 Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4658\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/01-newprj.png\" alt=\"\" width=\"941\" height=\"653\" \/><\/a><\/li>\n<li>On the first page of the wizard select the CMake build subsystem instead of GNU Make and click &#8220;Next&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/02-cmake.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4659\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/02-cmake.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>Then select the toolchain you would like to use. For the best development experience, it is always recommended to use the latest available toolchain:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/03-toolchain.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4660\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/03-toolchain.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><strong>Update:<\/strong> For better compatibility with the latest ESP32 tools, we recommend selecting the <a href=\"https:\/\/visualgdb.com\/documentation\/espidf\/consolidated\/\">consolidated toolchain<\/a> instead.<\/li>\n<li>On the next page select the &#8220;blink&#8221; sample project. We will later replace the code of the main source file with an equivalent version using the Arduino APIs:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/04-blink.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4661\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/04-blink.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>Finally, select Debug parameters that are compatible with your hardware. Use the &#8220;Test&#8221; button to verify that all the underlying tools work as expected:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/05-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4662\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/05-debug.png\" alt=\"\" width=\"856\" height=\"693\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to generate the project and wait for Visual Studio to load it. Once the project is loaded, right-click on the &#8220;Components&#8221; item in Solution Explorer and select &#8220;Add-&gt;Reference ESP32 Arduino Core&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/06-refcore.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4663\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/06-refcore.png\" alt=\"\" width=\"1336\" height=\"825\" \/><\/a><\/li>\n<li>VisualGDB will automatically clone the ESP32 Arduino Core into the <strong>&lt;Project Directory&gt;\\components\\arduino<\/strong> folder and will ensure that the ESP-IDF build system can find it:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/07-cloning.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4664\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/07-cloning.png\" alt=\"\" width=\"1336\" height=\"825\" \/><\/a><\/li>\n<li>Before you proceed with building the project, we recommend switching your ESP-IDF checkout to the specific commit that was used by Espressif to develop the core. Open the git history for the <strong>&lt;Project Folder&gt;\\components\\arduino<\/strong> folder and locate the most recent record that mentions ESP-IDF update. Take a note of the git commit ID (e.g. in this example the commit ID is is <a href=\"https:\/\/github.com\/espressif\/esp-idf\/commit\/977854975\">977854975<\/a>):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/08-tag-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4680\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/08-tag-1.png\" alt=\"\" width=\"741\" height=\"611\" \/><\/a><\/li>\n<li>Open VisualGDB Project Properties -&gt; ESP-IDF Project -&gt; Toolchain and click &#8220;Clone an SDK release from GitHub&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/09-clone.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4666\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/09-clone.png\" alt=\"\" width=\"1336\" height=\"825\" \/><\/a><\/li>\n<li>In the release clone window select &#8220;Specific commit&#8221; and enter the commit ID from the Arduino core log:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/10-commit.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4667\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/10-commit.png\" alt=\"\" width=\"586\" height=\"200\" \/><\/a><\/li>\n<li>Confirm the checkout by pressing &#8220;OK&#8221;. VisualGDB will begin checking out the selected commit as a separate ESP-IDF checkout:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/11-clone.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4668\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/11-clone.png\" alt=\"\" width=\"1336\" height=\"825\" \/><\/a><\/li>\n<li>Once the checkout is completed, ensure that it is shown in the &#8220;ESP-IDF checkout&#8221; field in VisualGDB Project Properties and click &#8220;OK&#8221; to apply the changes:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/12-selected.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4669\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/12-selected.png\" alt=\"\" width=\"921\" height=\"600\" \/><\/a><\/li>\n<li>Now you can build the project. Depending on the configuration of the initial project sample and the Arduino core version, you may need additional steps to get the project to build correctly. We will show the steps required as of June 2019 below. The first build problem would be the missing &#8220;mbedtls_ssl_conf_psk&#8221; function used by the Arduino\u00a0 core:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/13-mbed.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4670\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/13-mbed.png\" alt=\"\" width=\"1336\" height=\"825\" \/><\/a><\/li>\n<li>It can be enabled by checking the &#8220;Enable pre-shared-key ciphersuites&#8221; checkbox in VisualGDB Project Properties:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/14-psk.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4671\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/14-psk.png\" alt=\"\" width=\"921\" height=\"600\" \/><\/a><\/li>\n<li>The second issue would be the miss<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/15-exceptions.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4672\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/15-exceptions.png\" alt=\"\" width=\"1286\" height=\"725\" \/><\/a><\/li>\n<li>It can be enabled via VisualGDB Project Properties -&gt; ESP-IDF Configuration -&gt; Enable C++ exceptions:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/16-exceptconfig.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4673\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/16-exceptconfig.png\" alt=\"\" width=\"886\" height=\"500\" \/><\/a><\/li>\n<li>Once the project builds without errors, we can begin modifying the source code of the main file. Rename <strong>blink.c<\/strong> to <strong>blink.cpp<\/strong> and click &#8220;Refresh&#8221; when VisualGDB suggests updating the file status:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/07-rename.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4681\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/07-rename.png\" alt=\"\" width=\"1150\" height=\"828\" \/><\/a><\/li>\n<li>Replace the contents of the main file with the following code:\n<pre class=\"\">#include \"Arduino.h\"\r\n\r\nextern \"C\" void app_main()\r\n{\r\n    initArduino();    \r\n    pinMode(CONFIG_BLINK_GPIO, OUTPUT);\r\n    \r\n    for (;;)\r\n    {\r\n        digitalWrite(CONFIG_BLINK_GPIO, HIGH);\r\n        delay(500);\r\n        digitalWrite(CONFIG_BLINK_GPIO, LOW);\r\n        delay(500);\r\n    }\r\n}<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/18-arduino.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4675\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/18-arduino.png\" alt=\"\" width=\"1152\" height=\"828\" \/><\/a><\/li>\n<li>Press F5 to build the project and begin debugging it. Ensure that the LED starts blinking when controlled by the Arduino-style <strong>digitalWrite()<\/strong> functions:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/19-stopped.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4676\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/19-stopped.png\" alt=\"\" width=\"1152\" height=\"828\" \/><\/a><\/li>\n<li>If you are porting an existing Arduino-based project, consider enabling the &#8220;Autostart Arduino setup and loop on boot&#8221; setting:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/20-autostart.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4677\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/20-autostart.png\" alt=\"\" width=\"928\" height=\"572\" \/><\/a><\/li>\n<li>This allows structuring your code into the <strong>setup()<\/strong> and <strong>loop()<\/strong> functions similar to the Arduino projects:\n<pre class=\"\">#include \"Arduino.h\"\r\n\r\nvoid setup()\r\n{\r\n    pinMode(CONFIG_BLINK_GPIO, OUTPUT);\r\n}\r\n\r\nvoid loop()\r\n{\r\n    for (;;)\r\n    {\r\n        digitalWrite(CONFIG_BLINK_GPIO, HIGH);\r\n        delay(500);\r\n        digitalWrite(CONFIG_BLINK_GPIO, LOW);\r\n        delay(500);\r\n    }\r\n}\r\n<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/21-loop.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4678\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/21-loop.png\" alt=\"\" width=\"1152\" height=\"828\" \/><\/a><\/li>\n<li>The VisualGDB&#8217;s IntelliSense engine will automatically index both ESP-IDF and the ESP32 Arduino core, so you can use the Code Map or CodeJumps to quickly explore the relations between different functions or methods:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/22-codejumps.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4679\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/22-codejumps.png\" alt=\"\" width=\"1223\" height=\"745\" \/><\/a><\/li>\n<li>Because the project is using both the Arduino core and the ESP-IDF framework, your code can use both of the APIs, as long as it doesn&#8217;t cause conflicts. E.g. use the following code to add another FreeRTOS thread printing &#8220;Hello&#8221; messages to the serial port while the LED is being controlled by the main Arduino-style loop:\n<pre class=\"\">#include &lt;FreeRTOS.h&gt;\r\n\r\nvoid UARTTask(void *)\r\n{\r\n    Serial.begin(115200);\r\n    \r\n    for(;;)\r\n    {\r\n        Serial.println(\"Hello\");\r\n        delay(1000);\r\n    }\r\n}\r\n\r\nstatic TaskHandle_t uartDemoTaskHandle = NULL;\r\n\r\nvoid setup()\r\n{\r\n    pinMode(CONFIG_BLINK_GPIO, OUTPUT);\r\n    xTaskCreateUniversal(UARTTask,\r\n                         \"UARTTask\",\r\n                         8192,\r\n                         NULL, \r\n                         1,\r\n                         &amp;uartDemoTaskHandle,\r\n                         CONFIG_ARDUINO_RUNNING_CORE);\r\n}<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/23-hello.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4683\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/06\/23-hello.png\" alt=\"\" width=\"1185\" height=\"855\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to use the ESP32 Arduino core as a component in the Advanced ESP-IDF-based projects. This setup<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[170,160,138],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4657"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=4657"}],"version-history":[{"count":5,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4657\/revisions"}],"predecessor-version":[{"id":9043,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/4657\/revisions\/9043"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=4657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=4657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=4657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}