Thank you! That was very helpful. I am now compiling again after following your suggestions.
Espressif, if you're listening, I have some feedback for you. Not trying to say the information presented is wrong. Just making a point that it didn't work for me. I read through all the documentation and looked at examples as best I could before making this post, but there were still many things unclear/confusing to me. I saw a dozen different possibilities of how I might potentially implement this and tried many of the approaches, all with various degrees of success.
What I would recommend (what would have worked better for me) is to post a more robust example. For anyone else reading this, I'll start by posting more details about my implementation to serve as an example. Note that this example also shows how to change away from the traditional "main" component.
- myProject/
------------ CMakeLists.txt
------------ sdkconfig
------------ _Middleware/
----------------------- CMakeLists.txt
----------------------- SYSTEM.c
----------------------- SYSTEM.h
----------------------- MCU/
---------------------------------- ADC.c
---------------------------------- ADC.h
---------------------------------- I2C.c
---------------------------------- I2C.h
---------------------------------- TEMPERATURE.c
---------------------------------- TEMPERATURE.h
----------------------- Tools/
---------------------------------- TIME.c
---------------------------------- TIME.h
---------------------------------- UNITS.c
---------------------------------- UNITS.h
------------ _App/
------------------------- CMakeLists.txt
------------------------- APP.c
------------------------- APP.h
------------------------- APP__CONFIG.h
------------- build/
myProject CMakeLists.txt file:
Code: Select all
# COMPONENT LOCATION: ${PROJECT_DIR}
# Minimum Version of CMake allowed.
cmake_minimum_required(VERSION 3.16)
# List the Component Directories.
# Each of these locations needs a CMakeLists.txt file.
set(EXTRA_COMPONENT_DIRS
"_App"
"_Middleware"
)
# Path to CMake
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# Project name
project(application)
# Enable C Language
enable_language(C)
_Middleware CMakeLists.txt file:
Code: Select all
# COMPONENT LOCATION: ${PROJECT_DIR}/_Middleware
# List directories that need to be referenced by code accessing this component
set(include_dirs
"."
"./MCU"
"./Tools"
)
# List all Components PRIVATELY REQUIRED by this Component.
set(priv_requires
""
)
# List all Components REQUIRED by this Component.
set(requires
"_App"
#ESP-IDF Components
"console"
"esp_adc"
"esp_driver_i2c"
"esp_driver_tsens"
"freertos"
)
# List all C/C++ files in this Component.
set(srcs
"SYSTEM.c"
"MCU/ADC.c"
"MCU/I2C.c"
"MCU/TEMPERATURE.c"
"Tools/TIME.c"
"Tools/UNITS.c"
)
# Register the Component.
idf_component_register(
INCLUDE_DIRS "${include_dirs}"
PRIV_REQUIRES "${priv_requires}"
REQUIRES "${requires}"
SRCS "${srcs}")
_App CMakeLists.txt file:
Code: Select all
# COMPONENT LOCATION: ${PROJECT_DIR}/_App
# List directories that need to be referenced by code accessing this component
set(include_dirs
"."
)
# List all Components PRIVATELY REQUIRED by this Component.
set(priv_requires
""
)
# List all Components REQUIRED by this Component.
set(requires
"_Middleware"
#ESP-IDF Components
"esp_driver_gpio"
"freertos"
"nvs_flash"
)
# List all C/C++ files in this Component.
set(srcs
"APP.c"
)
# Register the Component.
idf_component_register(
INCLUDE_DIRS "${include_dirs}"
PRIV_REQUIRES "${priv_requires}"
REQUIRES "${requires}"
SRCS "${srcs}")
Notes/Tips:
*_App & _Middleware have underscores because I like the visual appeal of those two items (plus any additional components I create) being grouped next to each other in alphabetical order.
*The project has been renamed to "application" in the top-level CMakeLists.txt file so that the output file is created as "application.bin". This will be helpful later on when instructing others to "load the application file".