Make sure to use latest ESP-IDF & Arduino released version
We are going to integrate SparkFun_u-blox_GNSS_Arduino_Library
as a component to our sample ESP-IDF
project.
This Sparkfun
library is taken as an example so you could use any other library you need.
- Clone my ESP-IDF C++ template
git clone https://github.com/sukesh-ak/ESP-IDF-CPP-Template.git
- Set device target
idf.py set-target esp32
(or esp32s2 / esp32c3 / esp32s3)- Change firmware/project name in CMakeLists.txt file in the root CMakeLists.txt
- Create
components
foldermkdir components && cd components
- Add
Arduino
as submodule with folder namearduino
git submodule add https://github.com/espressif/arduino-esp32.git arduino
- Add
SparkFun_u-blox_GNSS_Arduino_Library
as submodule with folder nameSparkFun_u-blox_GNSS
git submodule add https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library.git SparkFun_u-blox_GNSS
- Create CMakeLists.txt file inside the
SparkFun_u-blox_GNSS
library folder
# CMakeFiles.txt inside "SparkFun_u-blox_GNSS" folder
cmake_minimum_required(VERSION 3.5)
idf_component_register(SRCS "src/SparkFun_u-blox_GNSS_Arduino_Library.cpp"
INCLUDE_DIRS "src/."
REQUIRES "arduino" # Library requires Arduino
)
project(SparkFun_u-blox_GNSS)
- Update CMakeLists.txt file in the main folder
See the file content here CMakeLists.txt
# Application requires SparkFun_u-blox_GNSS
set(COMPONENT_REQUIRES "SparkFun_u-blox_GNSS")
idf_component_register(SRCS "main.cpp"
INCLUDE_DIRS ".")
- Run
idf.py menuconfig
- Build
idf.py build
- Flash
idf.py -p <serial-port> flash
The project contains one source file in C++ language main.cpp. The file is located in folder main.
ESP-IDF projects are built using CMake. The project build configuration is contained in CMakeLists.txt
files that provide set of directives and instructions describing the project's source files and targets
(executable, library, or both).
Below is short explanation of remaining files in the project folder.
├── CMakeLists.txt
├── components [step 4]
│ ├── arduino [submodules - step 5]
│ └── SparkFun_u-blox_GNSS [submodules - step 6]
│ └── CMakeLists.txt [created in Step 7]
├── main
│ ├── CMakeLists.txt
│ └── main.cpp
└── README.md This is the file you are currently reading