Custom KCONFIG variable with custom board revisions

Hi,

I'm having an issue getting KCONFIG to work with multiple board revisions. I have defined a custom board. It has all the files needed and we can build product code on that. We are now making some hardware changes and want to have a C flag defined in the newer board versions. I have tried defining the flag in different places but build still seems to fail.

I want to have a flag like #define APP_TOUCH_PT8041. The code works when I do this in a C code file. I check the flag with a macro like this COND_CODE_1(CONFIG_APP_TOUCH_PT8041, (), (iqs323_sleep();)). Now what I want to do is have this flag defined in KCONFIG instead of doing it in the C code files. And what I really want is to use the board revision files to define this flag. So lets say my board is called plank. I have a lot of things defined in plank.defconfig but for each revision of my board there are two files (plank_1_0_0.overlay and plank_1_0_0.conf) - my understanding is that I can use the plank_1_0_0.conf file to define flags specific to that board revision. But whatever I do I can't seem to get the build system to accept my flag like this. I have tried putting the following thing in many different places but so far it has not worked.

config APP_TOUCH_PT8041
    bool "Board version using the older PT8041 touch chip"
    default n

I want this flag to be defined and default to "n" in all versions of my board except for specific ones where I put CONFIG_APP_TOUCH_PT8041 = y in the board revision conf file.

Is this possible or or should I just check the revision information in a code file and do the definition there. I think this would be kind of ugly but that seems to work. 

Tiit

  • Hi Tiit,

    First you can include additional conf files in the build for the specific revisions, including references to specific kconfig files, you can also have nested kconfig files specific to the subfolders.

    Based on your description, looks like a configuration issue between build script, conf and kconfig files (and of course CMakeFiles). Start by adding custom config with y to project main kconfig and see if you access it in C code, using either #ifdef or #if defined or IS_ENABLED macros.

    Would suggest deriving from a simple sample (Empty project).

    Reuven

  • Hi Tilt,

    Reuven's tips give a direction to approach this issue by setting up files in the project.

    I think you can also look into setting up revision files for your custom board. I will link the documentation and the implementation we have for the nRF9160 DK below.

    For your case, you likely can just set the default value in the <board>_<revision>.defconfig file.
    See: Board Porting Guide — Zephyr Project documentation (nRF Connect SDK) (nordicsemi.com)
    sdk-zephyr/boards/arm/nrf9160dk_nrf9160 at v3.5.99-ncs1 · nrfconnect/sdk-zephyr (github.com)

    For more complex approach, you could also explore the concepts of no-prompt Kconfig, setting Kconfig value in .cmake files, and conditional default value.
    See: kernel.org/doc/Documentation/kbuild/kconfig-language.txt

    Hieu

  • I can add a custom config to the main kconfig and I can access that in the c code. But doing the same thing through the board revision files fails in all sorts of fun ways. I have no previous kconfig (or any Zephyr/Linux build experience) so I really have no idea how to debug this. Is it possible to privately send you the project files and you can see what is wrong there? I got to a point now where I can build my project successfully for some board versions (where I don't set APP_TOUCH_PT8041=y) but versions that do set that will fail with completely unrelated issues. Right now I'm getting errors from devicetree, mcuboot and an undefined CONFIG_BOARD error when setting APP_TOUCH_PT8041=y. It does not seem related at all so I'm guessing something is failing in kconfig causing everything to be misconfigured.

    Tiit

  • I looked at the github code you linked and tried changing mine to be more inline with that. And I think I made progress but everything is still failing. My Kconfig.board now looks like this

     

    # Copyright (c) 2023 Nordic Semiconductor ASA
    # SPDX-License-Identifier: Apache-2.0
    
    config BOARD_PLANK3
    	bool "plank3"
    
    config APP_TOUCH_PT8041
        bool "Board version using the older PT8041 touch chip"

    And building versions where I have empty plank3_3_0_x.conf files also works. But if I try to set the CONFIG_APP_TOUCH_PT8041=y in one of the version specific .conf files the build fails with completely unrelated errors. 

  • I think I found the issue and got it working now. I never paid attention to it but I had spaces around the equals sign in the "CONFIG_APP_TOUCH_PT8041 = y" part. This causes it to fail. It has to be "CONFIG_APP_TOUCH_PT8041=y". I can't put anything in the Kconfig.board file without everything breaking in the weirdest ways possible. But putting the definition and default value for the config in the Kconfig.defconfig file works now and I can read the flag in code. As far as I'm concerned this fixes the issue and I have a solution to my problem.

Related