Page 1 of 1

[IDFGH-2940] sdkconfig not defining values used in component

Posted: Sun Mar 22, 2020 10:49 pm
by skibbidy
Hi,

I'm using the idf_as_lib method and trying to add a component to my design based off the i2c_self_test example. However the sdkconfig does not seem to be defining the required variables.

For instance I expect CONFIG_I2C_SLAVE_ADDRESS to be defined in my main sdkconfig (as it is when I run i2c_self_test) and therefore available to my components/i2c_self_test/main/i2c_example.main, but it is not.

In fact my sdkconfig does not have ANY of the definitions used in the i2c_example_main.c defined. Am I missing a call to some cmake API?

I have poured through the build_system and the cmake files. I am trying to understand how kconfig detects and sets these variables, but it is a lot to learn.

Here is my toplevel CMakeLists.txt

Code: Select all

cmake_minimum_required(VERSION 3.5)
project(MYPROJECT C)
set(elf_file ${CMAKE_PROJECT_NAME}.elf)
set(SUPPORTED_TARGETS esp32)
include($ENV{IDF_PATH}/tools/cmake/idf.cmake)
idf_build_component(${CMAKE_HOME_DIRECTORY}/components/i2c_self_test)
idf_build_process(esp32
	COMPONENTS esp32 freertos esptool_py i2c_self_test
	SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig
	BUILD_DIR ${CMAKE_BINARY_DIR})	    
add_executable(${elf_file} main.c)
target_link_libraries(${elf_file} idf::esp32 idf::freertos idf::spi_flash idf::i2c_self_test)
idf_build_executable(${elf_file})
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
the components/i2c_self_test/CMakeLists.txt is

Code: Select all

idf_component_register(SRC_DIRS main)
I build simply by

Code: Select all

cd build 
cmake .. -DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-esp32.cmake -DTARGET=esp32 -G 'Unix Makefiles'
cmake --build .
My file structure is
-components/i2c_self_test/
-main/i2c_example_main.c
-CMakeLists.txti
CMakeLists.txt
main.c

Re: [IDFGH-2940] sdkconfig not defining values used in component

Posted: Mon Mar 23, 2020 3:39 am
by ESP_Alvin
Moderator's note: edit the topic title for issue tracking, thanks.

Re: [IDFGH-2940] sdkconfig not defining values used in component

Posted: Mon Mar 23, 2020 5:57 am
by ESP_igrr
Can you please check if i2c_example_main.c includes sdkconfig.h?

Re: [IDFGH-2940] sdkconfig not defining values used in component

Posted: Mon Mar 23, 2020 4:01 pm
by skibbidy
ESP_igrr wrote:
Mon Mar 23, 2020 5:57 am
Can you please check if i2c_example_main.c includes sdkconfig.h?
Thanks for the reply. Yes i2c_example_main.c has sdkconfig.h

Code: Select all

#include <stdio.h>
#include "esp_log.h"
#include "driver/i2c.h"
#include "sdkconfig.h"

Re: [IDFGH-2940] sdkconfig not defining values used in component

Posted: Mon Mar 23, 2020 8:33 pm
by ESP_igrr
In that case, is CONFIG_I2C_SLAVE_ADDRESS present in sdkconfig.h? In sdkconfig (in the project root directory)? If not, then likely the Kconfig file where CONFIG_I2C_SLAVE_ADDRESS is defined is not seen by the build system.

Re: [IDFGH-2940] sdkconfig not defining values used in component

Posted: Tue Mar 24, 2020 4:11 pm
by skibbidy
ESP_igrr wrote:
Mon Mar 23, 2020 8:33 pm
In that case, is CONFIG_I2C_SLAVE_ADDRESS present in sdkconfig.h? In sdkconfig (in the project root directory)? If not, then likely the Kconfig file where CONFIG_I2C_SLAVE_ADDRESS is defined is not seen by the build system.
I've been digging into the kconfig stuff, but just to give an update it seems you are right. my components/i2c_self_test/main/kconfig.projbuild does not seem to be picked up during component build. Is there another way to include Kconfig.projbuild I am missing?

In my top level CMakeLists.txt I added

Code: Select all

 
idf_component_set_property(i2c_self_test KCONFIG_PROJBUILD ${CMAKE_HOME_DIRECTORY}/components/i2c_self_test/main/Kconfig.projbuild)
idf_build_component(${CMAKE_HOME_DIRECTORY}/components/i2c_self_test)
I've also tried manually defining it in my components/i2c_self_test/CMakeLists.txt

Code: Select all

set(KCONFIG_PROJBUILD main/Kconfig.projbuild)
idf_component_register(SRC_DIRS main)
I2C_SLAVE_ADDRESS is defined in the components/i2c_self_test/main/Kconfig.projbuild (which is taken from the example

I will continue my research and update if I find anything.

Re: [IDFGH-2940] sdkconfig not defining values used in component

Posted: Wed Mar 25, 2020 7:11 am
by ESP_renz
Since you specified that '${CMAKE_HOME_DIRECTORY}/components/i2c_self_test' is a component directory, the IDF build expects, Kconfig.projbuild to be there, i.e. '.../i2c_self_test/Kconfig.projbuild'.

I guess the thing here is that in the examples, 'i2c_self_test' is not a component, it is a project - 'main' is a component under project 'i2c_self_test'. From the code you posted, it seems you want a component 'i2c_self_test'?

So either you point `idf_build_component` to '.../i2c_self_test/main' or move Kconfig.projbuild one level up.