Set up a minimal ESP-IDF Project

Quick reference on setting up a minimal ESP-IDF project.

Set up a minimal ESP-IDF Project

ESP-IDF uses CMake for it's build system. At the minimum we need a root CMakeLists.txt and an optional sdkconfig.defaults. We also need a main folder with it's own CMakeLists.txt and a main.c source file.

Create a CMakeLists.txt with the following contents, replace the projectname with something.

cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(projectnamehere)
CMakeLists.txt

Create a sdkconfig.defaults and fill it with the defaults for your esp32 platform. The ones given here are for an odroid go. You can leave this file out if you do not want to specify any custom options at this time.

#
# Compiler options
#
CONFIG_COMPILER_OPTIMIZATION_PERF=y

#
# Serial flasher config
#
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y

#
# ESP32-specific
#
CONFIG_ESP32_DEFAULT_CPU_FREQ_80=y
CONFIG_ESP32_SPIRAM_SUPPORT=y

#
# SPI RAM config
#
CONFIG_SPIRAM_USE_CAPS_ALLOC=y
sdkconfig.defaults

Inside the main folder create the following files

idf_component_register(SRCS "main.c"
                INCLUDE_DIRS "")
main/CMakeLists.txt
#include <stdio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>

void app_main() {
  for(;;) {
  	printf("Hello, World!\n");
  	vTaskDelay(1000 / portTICK_PERIOD_MS);
  }
}
main/main.c

These are the files required for a minimal project. You can then use idf.py build to build the project, refer to the esp-idf documentation to get started setting up the esp-idf environment.