Espressif IDF – Menuconfig

Last Updated on 8 January 2021 by Suffocation

One of the nice achievements of the IDF is the menu-driven configuration. What I find even nicer is that custom configuration points can be created. These are then automatically integrated into the main menu. First of all:

  • The library „esp_system.h“ is required in the source code, otherwise it won't work.
  • After making changes to the menu, perform an idf.py clean.

To create such a configuration point, I'll use the program from the example Console output and replace the text with a configuration item. These are generally named CONFIG_, followed by a meaningful name.

For this configuration to be displayed in the menuconfig, a file called "Kconfig.projbuild" must still be created. This contains additional information about the configuration item:

Now, start Menuconfig (>idf.py menuconfig):

Still building and seeing what it looks like (idf.py build flash -p COM7 monitor)

Output with configured text.

It is not only possible to format text; numbers and dropdown lists are also possible. Here are a few examples

menu "Example Configuration"
config MOSI_GPIO
       int "MOSI GPIO number"
       range 0 46
       default 23 if IDF_TARGET_ESP32
       default 35 if IDF_TARGET_ESP32S2
       help
           GPIO number (IOxx) to SPI MOSI. ...

config INVERSION
       bool "Enable Display Inversion"
       default false
       help
           Enable Display Inversion.

choice
      bool "Mesh AP Authentication Mode"
      default WIFI_AUTH_WPA2_PSK
      help
          Authentication mode.

      config WIFI_AUTH_OPEN
          bool "WIFI_AUTH_OPEN"
      config WIFI_AUTH_WPA_PSK
          bool "WIFI_AUTH_WPA_PSK"
      config WIFI_AUTH_WPA2_PSK
          bool "WIFI_AUTH_WPA2_PSK"
      config WIFI_AUTH_WPA_WPA2_PSK
          bool "WIFI_AUTH_WPA_WPA2_PSK"
endchoice

config MESH_GLOBAL_DNS_IP
       hex "Global DNS"
       depends on MESH_USE_GLOBAL_DNS_IP
       default 0x08080808
       help
           The IP address of global DNS server that is used
           for internal IP subnet formed by the mesh network
           if MESH_USE_GLOBAL_DNS_IP is enabled.
           Note: The IP address is in platform (not network)
           format.
...

endmenu

Dependencies between configuration points are also possible. These are indicated by the keyword "depends on" followed by one or more configuration names with logical operators. Logical operators are || (or) or && (and).

.config SW1_PIN
		int "SW1 pin"
		range 0 39
        default 36
		depends on SW1_ENABLE
		help
			Switch 1 Gpio pin
config SW2_ENABLE
		bool "SW2 Enable"
        default false
		help
			Enable Switch 2
config SW2_PIN
		int "SW2 pin"
		range 0 39
        default 35
		depends on SW2_ENABLE
		help
			SW2 Gpio pin
config LONG_PRESS_ENABLED
		bool "Long press enabled"
        default false
		depends on (SW1_ENABLE || SW2_ENABLE)
		help
		   If this is enabled the system
		   distinguishes between long pressed buttons
                   and short pressed buttons
	config LONG_PRESS_TIME_MS
		int "Long press time ms"
		range 1000 8000
        default 2000
		depends on LONG_PRESS_ENABLED
		help
		  How long should a button be pressed to be
                  marked as a long press; if it is not long pressed
                  it is a short press
...

Conclusion

The idea of externalising configurations is not new. However, I find it a charmingly solved problem to provide them with a menu.

Related Posts

Main contribution

Sources

IDF - Configuration

KConfig Guide

KConfig Extensions

2 thoughts on “Espressif IDF – Menuconfig

  1. Hello Jürgen,

    As stated in the imprint, I do not create guides for beginners but merely document what I develop myself. I don't think professionals need this guide. However, I am happy to make adjustments/additions if you write to me exactly where the problem lies.

    To illustrate the project structure, an example project is linked on GitHub, where all necessary files are in the correct positions. Is that not enough? What can I do better here?

    Your comment is about a report on using Menuconfig via the console; where does VSCode fit into that? Yes, operation is also possible with VSCode, but here it's based on a menu controlled by the mouse. However, it's also the case for me that VSCode works one day and then doesn't with the next version. Therefore, I would first try to get the IDF running on the console (CMD).

    NCurses menus were/are often used under Linux (or similar in the Windows console), which is why I haven't gone into more detail here. Basically, you only need Enter to get into a submenu or edit a menu item, and Esc to get back out. The arrow keys help with navigation, possibly plus Tab to jump or S to save.

    The IDF is definitely not particularly suitable for beginners, unfortunately there's no way around it for new ESPs, as the implementation for the Arduino GUI always lags a bit behind. Otherwise, as a beginner, I would recommend using the Arduino GUI.

    Hello
    Stefan

  2. Hello,

    I can't share your enthusiasm for menuconfig.

    Yes, it can be called from VS Code/PlatformIO. The madness starts with some keyboard shortcuts at the bottom, but the most important ones (j and k) are missing.

    And it's not as simple as just creating a „kconfig.projbuild“ and starting menuconfig. Where does it need to be so that it's recognised?

    There is an „o“ key for loading, but 'j' and 'k' don't even work in the window that appears. So how do I navigate to the path where kconfig.projbuild is located?

    Your blog seems geared more towards professionals who already know everything. As a beginner, you just spend hours wading through the internet, and Espressif's documentation is also of little help.

    Greetings

Leave a Reply

Your email address will not be published. Required fields are marked *