菜单选项

1 - config 配置项

config  MODVERSIONS
   bool  "Set version information on all module symbols"
   depends  MODULES
   default y
   help
      Usually, modules have to be recompiled whenever you switch to a new
      kernel. ...

选项的(1)类型,(2)输入提示(input prompt),(3)依赖关系,(4)默认值,(5)帮助信息
类型:”bool/tristate/string/hex/int”
tristate三态:内建、模块、移除
依赖关系:”depends on/requires”
depends on与if等价

bool "foo" if BAR
   default y if BAR

depends on BAR
bool "foo"
default y
depends on BAR

2 - menuconfig 带菜单的配置项
此关键字和前面的关键字很相似,但它在前面的基础上要求所有的子选项作为独立的行显示
3 - choice/endchoice 单选配置项

choice
    prompt "Device type"
    default STM32F100RC
    config STM32F100RC
        bool "STM32F100RC"
    config STM32F100RD
        bool "STM32F100RD"
endchoice

4 - menu/endmenu 菜单
5 - comment 注释
定义了在配置过程中显示给用户的注释,该注释还将写进输出文件中
6 - if/endif 条件判断
7 - source 读取其他配置文件.
读取其他具体的配置文件,其他配置文件会被解析

菜单结构

  • 直接树状结构
    menu/endmenu
  • 依赖关系生成菜单结构
    depends

例子

menu "Hardware Drivers Config"      #定义1级菜单

config SOC_STM32F429IG              #选择MCU
    bool                            #bool数据类型后面为空,表示配置界面不会显示
    select SOC_SERIES_STM32F4
    default y

menu "Onboard Peripheral Drivers"   #定义2级菜单

    config BSP_USING_USB_TO_USART   #2级菜单中的一行新的配置项,BSP_USING_USB_TO_USART只是标识
        bool "Enable USB TO USART (uart1)"   #配置项显示的内容,配置类型为bool
        select BSP_USING_UART       #
        select BSP_USING_UART1      #如果使能该配置项,select表示会在rtconfig.h文件增加宏定义
        default y                   #使能配置项,决定上面宏定义是否增加

    config BSP_USING_COM2
        bool "Enable COM2 (uart2 pin conflict with Ethernet and PWM)"
        select BSP_USING_UART
        select BSP_USING_UART2
        default n

endmenu                             # 2级菜单的结束

menu "On-chip Peripheral Drivers"   # 新的2级菜单

    config BSP_USING_GPIO
        bool "Enable GPIO"
        select RT_USING_PIN
        default y

    menuconfig BSP_USING_UART       # 带菜单的配置项,配置后可以进入该菜单继续配置
        bool "Enable UART"
        default y                   # 没有select 选项,说明该菜单配置项强制选中
        select RT_USING_SERIAL
        if BSP_USING_UART           # 带菜单的配置项如果被配置,则if生效
            config BSP_USING_UART1
                bool "Enable UART1"
                default y

            config BSP_UART1_RX_USING_DMA
                bool "Enable UART1 RX DMA"
                depends on BSP_USING_UART1 && RT_SERIAL_USING_DMA  #依赖两个宏定义
                default n 
        endif

    config BSP_USING_ON_CHIP_FLASH
        bool "Enable on-chip FLASH"
        default n

    menuconfig BSP_USING_SPI
        bool "Enable SPI BUS"
        default n
        select RT_USING_SPI
        if BSP_USING_SPI
            config BSP_USING_SPI1
                bool "Enable SPI1 BUS"
                default n

            config BSP_SPI1_TX_USING_DMA
                bool "Enable SPI1 TX DMA"
                depends on BSP_USING_SPI1
                default n
                
            config BSP_SPI1_RX_USING_DMA
                bool "Enable SPI1 RX DMA"
                depends on BSP_USING_SPI1
                select BSP_SPI1_TX_USING_DMA
                default n
        endif

    menuconfig BSP_USING_I2C1
        bool "Enable I2C1 BUS (software simulation)"
        default n
        select RT_USING_I2C
        select RT_USING_I2C_BITOPS
        select RT_USING_PIN
        if BSP_USING_I2C1
            comment "Notice: PH4 --> 116; PH5 --> 117"   #配置项的注释说明
            config BSP_I2C1_SCL_PIN
                int "I2C1 scl pin number"                #配置项类型为整型
                range 1 176                              #配置项的值取值范围设定
                default 116
        endif

    menuconfig BSP_USING_TIM
        bool "Enable timer"
        default n
        select RT_USING_HWTIMER
        if BSP_USING_TIM
            config BSP_USING_TIM11
                bool "Enable TIM11"
                default n
        endif

    menuconfig BSP_USING_ONCHIP_RTC
        bool "Enable RTC"
        select RT_USING_RTC
        select RT_USING_LIBC
        default n
        if BSP_USING_ONCHIP_RTC               #条件判断
            choice                            #选择配置项,其值可选,类似单选框功能
                prompt "Select clock source"  #配置项的显示名称
                default BSP_RTC_USING_LSE     #默认选择的配置

                config BSP_RTC_USING_LSE      #配置选项
                    bool "RTC USING LSE"

                config BSP_RTC_USING_LSI
                    bool "RTC USING LSI"
            endchoice                         #结束选择配置项
        endif

    config BSP_USING_WDT
        bool "Enable Watchdog Timer"
        select RT_USING_WDT
        default n

endmenu

menu "Board extended module Drivers"

endmenu

endmenu

参考

https://www.jianshu.com/p/aba588d380c2