My Projects

Getting the esp-idf to compile and upload code using Eclipse Oxygen first thing we need to do is download Eclipse and we want to install the CDT version as this installs the C/C++ tool-chains download the installer.Once the installer is downloaded open it and select.

Eclipse IDE for C/C++ Developers
and work through the installation steps when prompted. after the install has finished open eclipse it will prompt you for a workspace directory which by default will be in your documents folder but you can put it any where , in my case a have esp32dev directory and i put the workspace in it. The next part seems to have many different ways of achieving the same goal i originally followed the install method in Neil Kolbans free book on the esp32 which worked fine fine with my older neon eclipse but had some unresolved problems with Oxygen so decide to start from scratch taking pointers from the book and a few other tutorials on the web. If you don't want to wade through the step by step process you can download the template that we'll create in this article unzip it somewhere then in eclipse click file / import then in the dialog choose existing projects into workspace and select the unzipped project. and you will have everything described in this article. then pop over to the much smaller article about creating a project from the template.
  • Open the new project wizard by clicking File / New then select New Project to bring up the new project wizard as shown below.
  • step1
  •   in the project wizard select c/c++ project and click next.


  • On the Next screen select C Managed Build and click next.


  •  On the next screen choose Make file project / empty project and choose ----other toolchain----- give your project a name it will in fact work with the other toolchain options as we pretty much get rid of what is already there.


  • Now click finish and your new project will appear in the list of projects on the left side of the screen.
  • Right click on your project and select properties from the pop up menu its at the bottom.


  • click on c/c++ build , uncheck use default bind command and in the build command edit box type                            python ${IDF_PATH}/tools/windows/   
  • click the little > net to the c/c++ build to open up the section and click environment you should have a couple of entries PWD CWD, click the add button and in the popup box Name edit box type IDF_PATH in the value type the path where your esp-idf is installed use linux / and not microsoft \ in my case the idf is located c:/msys32/home/paul/esp/esp-idf Press ok.
  • click the add button again and in the name type BATCH_BUILD and value 1 click ok
  • if you already have PATH the click edit if you don't click add if path is already set remove the contents and replace it with C:\msys32\usr\bin;C:\msys32\mingw32\bin;C:\msys32\opt\xtensa-esp32-elf\bin note if you installed minggw and your xtensa toolchain elsewhere change the directorys accordingly.
  • Now click settings and tick elf parser under the binary parsers tab make sure all the others are unchecked. click the error parsers tab and make sure only the Gnu assembler , Gnu Gmake , Gnu gcc/g++ , Gnu Linker and pushd/popd cwd locator are checked all others unchecked.
  • next we need to setup the tool-chain so click tool chain editor click the drop down current toolchain now depending on what tool-chains you have installed this list could have many compilers choose the Cross GCC and in the make under it choose GNU Make if you don't see these uncheck the compatible tool chains only then they should appear.
  • next step click on the > next c/c++ general and then click on the preprocessor include paths, Macros etc. then click the providers Tab. Make sure that the  CDT Cross GCC Built-in compiler settings tab is checked and highlighted then the edit box below you will have ${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}" change this to the following by replacing the ${command}  to xtensa-esp32-elf-gcc  so the edit box should now look like this xtensa-esp32-elf-gcc ${FLAGS} -E -P -v -dD "${INPUTS}".
  • make sure that the CDT GCC Build Output Parser is check and highlighted and th editbox below should look like this       (g?cc)|([gc]\+\+)|(clang)    change it to this xtensa-esp32-elf-(g?cc)|([gc]\+\+)|(clang) by prepending xtensa-esp32-elf-
  • now you have to add the include paths and theres quite a few i have exported my paths here  unzip the xml file somwhere, The open properties if its not still open by right clicking on your project its at the bottom of the menu. Then click the > next to C/C++ General and then click paths and symbols followed by clicking import. in the input dialog click browse find the index.xml file you extracted and  both symbols and include paths should be checked then click finish.


  • nearly done if you look at the include paths they are all relative to the ${IDF_PATH} variable we set up earlier so will point to the same place on your system there is also a workspace relative path to a directory build/include which will have an exlamation mark inidcating that the directory does not exist don't worry about it as will once the project is built. If the import doesn't work it is down to a bug in eclipse that it incorrectly identifies the toolchain just go back reselect the Cross GCC and apply and close then it should work you'll know it work as you'll have an include directory in your project.
  • we now need to add some directories and files. right click on your project then at the top of the menu new then folder and name the folder main , repeat this process and name the second folder components. Now the main folder will hold your main.c  which must have an void app_main(void) function in it and if you want to add your own stuff to menuconfig it will require a Kconfig.projbuild file laslty it must have a file to hold special make instructions for main in most cases it is empty as shown below if you don't create this file you'll get a linker error telling cpu_start.c can't find app_main.

# "main" pseudo-component makefile.
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 

which as you can is comments 

now each directory needs to have a component,mk or it doesn't get included in the build process. The components directory is where you add the component parts that make up your application i have one for each task that i'm running ie a wifitask directory inside the components directory for my wifi operations another web server each of these directory's also has an include folder where i keep the associated include files. So if we take the wifitask as an example , inside the components directory is a wifitask directory containing an include directory a wifitask.c and a file, the include directory has a wifitask.h file. the file in the wifi directory looks like this.

# "main" pseudo-component makefile.
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

So our next step is to create a main.c in the main directory so right click the main directory in your project then New and select C source file and name it main.c we just going to create a replica of the hello world example in the IDF so you could just open it and copy into your main.c.

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"

void app_main()
    printf("Hello world!\n");

    /* Print chip information */
    esp_chip_info_t chip_info;
    printf("This is ESP32 chip with %d CPU cores, WiFi%s%s, ",
            (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
            (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");

    printf("silicon revision %d, ", chip_info.revision);

    printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
            (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

    for (int i = 10; i >= 0; i--) {
        printf("Restarting in %d seconds...\n", i);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    printf("Restarting now.\n");

 you'll probably have lots of red error markers don't worry about these for now as we haven't compiled the program yet the build include directory doesn't exist now create your file right click the main folder new file and call it put the comments in that were shown above and save it. now in the root directory of your project we need to create a new Makefile so right click on your project new file and call it Makefile , then copy or type the following into it.

# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.

PROJECT_NAME := template

include $(IDF_PATH)/make/

note that the project name defines the name of the elf binary file created so if you copy your template to another project remember to change the name if you want the bin file to match your project. 

The last step is to create our build targets so right click on your project and move your mouse over build target then click create from the menu in the target name type 'all' with out the quote leave everything checked and click Ok. now repeat this step this time in the target name type 'clean' without the quote and click Ok then finally do the same again and type 'flash' in the target name without the quote you will now say a green circle in you project  labeled Build targets double clicking on all will build your project clean will remove all object files from your project and flash will build and flash your project to your board. But before we can do that we have to run make menuconfig on your project or it won't build iv'e tried several ways to do this from inside eclipse on windows but the built in terminal refuse to play ball at some point i'll revisit it and see if we can get it to work. any way open your mingw console cd to your project directory and run make menuconfig set any options you need in your project and save it. once its done right click your project and choose refresh you should now have some sdkconfig files in the project root. so double click all in the build targets and your project will compile first time takes a while as it builds all of the idf. And your done if you get errors you have probably missed a step above. 

There a few different methods and tutorials on the web and most differ slightly and most gave me a problem or two in my environment and i suspect my setup may not work for everyone. the best way start is to use a template that some one has already written


Add comment

Security code