diff --git a/README.md b/README.md index a7365f8e..992e1a8c 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR TRUE) HAL module will search all drivers supported by family and create the following targets: * `HAL::STM32::` (e.g. `HAL::STM32::F4`) - common HAL source, depends on `CMSIS::STM32::` -* `HAL::STM32::::` (e.g. `HAL::STM32::F4::GPIO`) - HAL driver , depends on `HAL::STM32::` +* `HAL::STM32::::_ENABLE` (e.g. `HAL::STM32::F4::GPIO_ENABLE`) - Enables HAL driver , by setting the `HAL__MODULE_ENABLED` macro. +* `HAL::STM32::::` (e.g. `HAL::STM32::F4::GPIO`) - HAL driver , depends on `HAL::STM32::` and `HAL::STM32::::_ENABLE`. Causes the source file for the driver to be built. * `HAL::STM32::::Ex` (e.g. `HAL::STM32::F4::ADCEx`) - HAL Extension driver , depends on `HAL::STM32::::` * `HAL::STM32::::LL_` (e.g. `HAL::STM32::F4::LL_ADC`) - HAL LL (Low-Level) driver , depends on `HAL::STM32::` @@ -170,6 +171,7 @@ Here is typical usage: add_executable(stm32-blinky-f4 blinky.c stm32f4xx_hal_conf.h) target_link_libraries(stm32-blinky-f4 HAL::STM32::F4::RCC + HAL::STM32::F4::FLASH_ENABLE HAL::STM32::F4::GPIO HAL::STM32::F4::CORTEX CMSIS::STM32::F407VG diff --git a/cmake/FindHAL.cmake b/cmake/FindHAL.cmake index b714ed14..70af2fd0 100644 --- a/cmake/FindHAL.cmake +++ b/cmake/FindHAL.cmake @@ -25,10 +25,35 @@ function(get_list_hal_drivers out_list_hal_drivers hal_drivers_path hal_driver_t list(FILTER filtered_files INCLUDE REGEX ${file_pattern}) # From the files names keep only the driver type part using the regex (stm32xx_hal_(rcc).c or stm32xx_ll_(rcc).c => catches rcc) list(TRANSFORM filtered_files REPLACE ${file_pattern} "\\1") - #Making a return by reference by seting the output variable to PARENT_SCOPE + # Making a return by reference by seting the output variable to PARENT_SCOPE set(${out_list_hal_drivers} ${filtered_files} PARENT_SCOPE) endfunction() +# This function removes excluded drivers from the drivers_list +# +# drivers_list name of HAL drivers list +# +function(drop_excluded_hal_drivers drivers_list_name) + if(DEFINED EXCLUDED_${drivers_list_name}_OVERRIDE) + # User has overidden excluded drivers list + set(excluded_drivers_list_name "EXCLUDED_${drivers_list_name}_OVERRIDE") + else() + # User has not overridden excluded drivers list + # Fall back on default excluded drivers list + set(excluded_drivers_list_name "EXCLUDED_${drivers_list_name}") + endif() + + set(excluded_drivers_list ${${excluded_drivers_list_name}}) + if(excluded_drivers_list) + message(STATUS "Ignoring drivers listed in ${excluded_drivers_list_name}: ${excluded_drivers_list}") + foreach(excluded_driver ${excluded_drivers_list}) + string(TOLOWER ${excluded_driver} excluded_driver) + list(REMOVE_ITEM ${drivers_list_name} ${excluded_driver}) + endforeach() + # Update the original drivers list in the parent scope + set(${drivers_list_name} ${${drivers_list_name}} PARENT_SCOPE) + endif() +endfunction() ################################################################################ # Checking the parameters provided to the find_package(HAL ...) call # The expected parameters are families and or drivers in *any orders* @@ -75,9 +100,16 @@ foreach(family_comp ${HAL_FIND_COMPONENTS_FAMILIES}) set(HAL_${family_comp}_FOUND TRUE) endif() if(CMAKE_MATCH_1) #Matches the family part of the provided STM32[..] component + # HAL drivers get_list_hal_drivers(HAL_DRIVERS_${FAMILY} ${HAL_${FAMILY}_PATH} "hal") + drop_excluded_hal_drivers(HAL_DRIVERS_${FAMILY}) + get_list_hal_drivers(HAL_EX_DRIVERS_${FAMILY} ${HAL_${FAMILY}_PATH} "ex") + drop_excluded_hal_drivers(HAL_EX_DRIVERS_${FAMILY}) + get_list_hal_drivers(HAL_LL_DRIVERS_${FAMILY} ${HAL_${FAMILY}_PATH} "ll") + drop_excluded_hal_drivers(HAL_LL_DRIVERS_${FAMILY}) + list(APPEND HAL_DRIVERS ${HAL_DRIVERS_${FAMILY}}) list(APPEND HAL_LL_DRIVERS ${HAL_LL_DRIVERS_${FAMILY}}) else() @@ -212,9 +244,11 @@ foreach(COMP ${HAL_FIND_COMPONENTS_FAMILIES}) continue() endif() + # Add the overall target HAL library if(NOT (TARGET HAL::STM32::${FAMILY}${CORE_C})) message(TRACE "FindHAL: creating library HAL::STM32::${FAMILY}${CORE_C}") add_library(HAL::STM32::${FAMILY}${CORE_C} INTERFACE IMPORTED) + target_compile_definitions(HAL::STM32::${FAMILY}${CORE_C} INTERFACE "USE_HAL_DRIVER") target_link_libraries(HAL::STM32::${FAMILY}${CORE_C} INTERFACE STM32::${FAMILY}${CORE_C} CMSIS::STM32::${FAMILY}${CORE_C}) @@ -225,7 +259,7 @@ foreach(COMP ${HAL_FIND_COMPONENTS_FAMILIES}) foreach(DRV_COMP ${HAL_FIND_COMPONENTS_DRIVERS}) string(TOLOWER ${DRV_COMP} DRV_L) string(TOUPPER ${DRV_COMP} DRV) - + if(NOT (DRV_L IN_LIST HAL_DRIVERS_${FAMILY})) continue() endif() @@ -241,15 +275,26 @@ foreach(COMP ${HAL_FIND_COMPONENTS_FAMILIES}) set(HAL_${DRV_COMP}_FOUND FALSE) continue() endif() - + + # Add the individual target HAL libraries set(HAL_${DRV_COMP}_FOUND TRUE) if(HAL_${FAMILY}${CORE_U}_${DRV}_SOURCE AND (NOT (TARGET HAL::STM32::${FAMILY}::${DRV}))) message(TRACE "FindHAL: creating library HAL::STM32::${FAMILY}${CORE_C}::${DRV}") + + # Target to add a "MODULE_ENABLED" define + add_library(HAL::STM32::${FAMILY}${CORE_C}::${DRV}_ENABLE INTERFACE IMPORTED) + target_compile_definitions(HAL::STM32::${FAMILY}${CORE_C}::${DRV}_ENABLE INTERFACE "HAL_${DRV}_MODULE_ENABLED") + + # Target to build the source file (and also enable) add_library(HAL::STM32::${FAMILY}${CORE_C}::${DRV} INTERFACE IMPORTED) - target_link_libraries(HAL::STM32::${FAMILY}${CORE_C}::${DRV} INTERFACE HAL::STM32::${FAMILY}${CORE_C}) + target_link_libraries(HAL::STM32::${FAMILY}${CORE_C}::${DRV} + INTERFACE + HAL::STM32::${FAMILY}${CORE_C} + HAL::STM32::${FAMILY}${CORE_C}::${DRV}_ENABLE) target_sources(HAL::STM32::${FAMILY}${CORE_C}::${DRV} INTERFACE "${HAL_${FAMILY}${CORE_U}_${DRV}_SOURCE}") endif() - + + # Add the individual target HAL Ex libraries if(HAL_${FAMILY}${CORE_U}_${DRV}_SOURCE AND (${DRV_L} IN_LIST HAL_EX_DRIVERS_${FAMILY})) find_file(HAL_${FAMILY}${CORE_U}_${DRV}_EX_SOURCE NAMES stm32${FAMILY_L}xx_hal_${DRV_L}_ex.c diff --git a/cmake/stm32/mp1.cmake b/cmake/stm32/mp1.cmake index 4c8afd63..9e58aa11 100644 --- a/cmake/stm32/mp1.cmake +++ b/cmake/stm32/mp1.cmake @@ -18,6 +18,12 @@ set(STM32_MP1_CCRAM_SIZES 0K 0K 0K 0K) +# The MDIOS module is broken in STM32CubeMP1 up to and including v. 1.6.0 +# Exclude it by default +set(EXCLUDED_HAL_DRIVERS_MP1 + MDIOS +) + stm32_util_create_family_targets(MP1 M4) target_compile_options(STM32::MP1::M4 INTERFACE -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard) diff --git a/cmake/stm32/utilities.cmake b/cmake/stm32/utilities.cmake index d6405be5..1a8ce777 100644 --- a/cmake/stm32/utilities.cmake +++ b/cmake/stm32/utilities.cmake @@ -44,9 +44,9 @@ include(FetchContent) # A CMSIS or HAL driver can specify 'cube' as version number to indicate that the driver is taken from the Cube repository set(STM32_FETCH_FAMILIES F0 F1 F2 F3 F4 F7 G0 G4 H7 L0 L1 L4 L5 MP1 U5 WB WL ) -set(STM32_FETCH_CUBE_VERSIONS v1.11.2 v1.8.4 v1.9.3 v1.11.2 v1.26.1 v1.16.1 v1.4.1 v1.4.0 v1.9.0 v1.12.0 v1.10.3 v1.17.0 v1.4.0 1.5.0 v1.0.0 v1.12.0 v1.1.0) -set(STM32_FETCH_CMSIS_VERSIONS v2.3.5 v4.3.3 v2.2.5 v2.3.5 v2.6.6 v1.2.6 v1.4.0 v1.2.1 v1.10.0 v1.9.1 v2.3.2 v1.7.1 v1.0.4 cube v1.0.0 v1.9.0 v1.1.0) -set(STM32_FETCH_HAL_VERSIONS v1.7.5 v1.1.8 v1.2.7 v1.5.5 v1.7.12 v1.2.9 v1.4.1 v1.2.1 v1.10.0 v1.10.4 v1.4.4 v1.13.0 v1.0.4 cube v1.0.0 v1.9.0 v1.1.0) +set(STM32_FETCH_CUBE_VERSIONS v1.11.2 v1.8.4 v1.9.3 v1.11.2 v1.26.1 v1.16.1 v1.6.1 v1.4.0 v1.9.0 v1.12.0 v1.10.3 v1.17.0 v1.4.0 1.5.0 v1.0.0 v1.12.0 v1.1.0) +set(STM32_FETCH_CMSIS_VERSIONS v2.3.5 v4.3.3 v2.2.5 v2.3.5 v2.6.6 v1.2.6 v1.4.3 v1.2.1 v1.10.0 v1.9.1 v2.3.2 v1.7.1 v1.0.4 cube v1.0.0 v1.9.0 v1.1.0) +set(STM32_FETCH_HAL_VERSIONS v1.7.5 v1.1.8 v1.2.7 v1.5.5 v1.7.12 v1.2.9 v1.4.5 v1.2.1 v1.10.0 v1.10.4 v1.4.4 v1.13.0 v1.0.4 cube v1.0.0 v1.9.0 v1.1.0) FetchContent_Declare( STM32-CMSIS diff --git a/examples/blinky/CMakeLists.txt b/examples/blinky/CMakeLists.txt index 2924c91a..af8f6c0e 100644 --- a/examples/blinky/CMakeLists.txt +++ b/examples/blinky/CMakeLists.txt @@ -19,7 +19,7 @@ endif() set(CMAKE_INCLUDE_CURRENT_DIR TRUE) -set(HAL_COMP_LIST RCC GPIO CORTEX) +set(HAL_COMP_LIST RCC GPIO CORTEX FLASH) set(CMSIS_COMP_LIST "") if(BLINKY_F4_EXAMPLE) @@ -53,6 +53,7 @@ find_package(HAL COMPONENTS "${HAL_COMP_LIST}" REQUIRED) if(BLINKY_F4_EXAMPLE) add_executable(stm32-blinky-f4 ${MAIN_SOURCE_FILE} stm32f4xx_hal_conf.h) target_link_libraries(stm32-blinky-f4 + HAL::STM32::F4::FLASH_ENABLE HAL::STM32::F4::RCC HAL::STM32::F4::GPIO HAL::STM32::F4::CORTEX @@ -66,6 +67,7 @@ endif() if(BLINKY_F1_EXAMPLE) add_executable(stm32-blinky-f1 ${MAIN_SOURCE_FILE} stm32f1xx_hal_conf.h) target_link_libraries(stm32-blinky-f1 + HAL::STM32::F1::FLASH_ENABLE HAL::STM32::F1::RCC HAL::STM32::F1::GPIO HAL::STM32::F1::CORTEX @@ -79,6 +81,7 @@ endif() if(BLINKY_L0_EXAMPLE) add_executable(stm32-blinky-l0 ${MAIN_SOURCE_FILE} stm32l0xx_hal_conf.h) target_link_libraries(stm32-blinky-l0 + HAL::STM32::L0::FLASH_ENABLE HAL::STM32::L0::RCC HAL::STM32::L0::GPIO HAL::STM32::L0::CORTEX diff --git a/examples/blinky/stm32f1xx_hal_conf.h b/examples/blinky/stm32f1xx_hal_conf.h index 1d0488c3..2e69f9a7 100755 --- a/examples/blinky/stm32f1xx_hal_conf.h +++ b/examples/blinky/stm32f1xx_hal_conf.h @@ -33,20 +33,25 @@ extern "C" { /* ########################## Module Selection ############################## */ /** * @brief This is the list of modules to be used in the HAL driver + * + * `stm32-cmake` automatically defines the `HAL_*_MODULE_ENABLED` variables + * when a driver is added to a project using `target_link_libraries`, so they + * don't need to be defined here + * */ #define HAL_MODULE_ENABLED // #define HAL_ADC_MODULE_ENABLED // #define HAL_CAN_MODULE_ENABLED // #define HAL_CAN_LEGACY_MODULE_ENABLED // #define HAL_CEC_MODULE_ENABLED -#define HAL_CORTEX_MODULE_ENABLED +// #define HAL_CORTEX_MODULE_ENABLED // #define HAL_CRC_MODULE_ENABLED // #define HAL_DAC_MODULE_ENABLED -#define HAL_DMA_MODULE_ENABLED +// #define HAL_DMA_MODULE_ENABLED // #define HAL_ETH_MODULE_ENABLED // #define HAL_EXTI_MODULE_ENABLED -#define HAL_FLASH_MODULE_ENABLED -#define HAL_GPIO_MODULE_ENABLED +// #define HAL_FLASH_MODULE_ENABLED +// #define HAL_GPIO_MODULE_ENABLED // #define HAL_HCD_MODULE_ENABLED // #define HAL_I2C_MODULE_ENABLED // #define HAL_I2S_MODULE_ENABLED @@ -57,7 +62,7 @@ extern "C" { // #define HAL_PCCARD_MODULE_ENABLED // #define HAL_PCD_MODULE_ENABLED // #define HAL_PWR_MODULE_ENABLED -#define HAL_RCC_MODULE_ENABLED +// #define HAL_RCC_MODULE_ENABLED // #define HAL_RTC_MODULE_ENABLED // #define HAL_SD_MODULE_ENABLED // #define HAL_SMARTCARD_MODULE_ENABLED diff --git a/examples/blinky/stm32f4xx_hal_conf.h b/examples/blinky/stm32f4xx_hal_conf.h index a934b1cc..44e10197 100755 --- a/examples/blinky/stm32f4xx_hal_conf.h +++ b/examples/blinky/stm32f4xx_hal_conf.h @@ -33,6 +33,11 @@ /* ########################## Module Selection ############################## */ /** * @brief This is the list of modules to be used in the HAL driver + * + * `stm32-cmake` automatically defines the `HAL_*_MODULE_ENABLED` variables + * when a driver is added to a project using `target_link_libraries`, so they + * don't need to be defined here + * */ #define HAL_MODULE_ENABLED // #define HAL_ADC_MODULE_ENABLED @@ -43,17 +48,17 @@ // #define HAL_CRYP_MODULE_ENABLED // #define HAL_DAC_MODULE_ENABLED // #define HAL_DCMI_MODULE_ENABLED -#define HAL_DMA_MODULE_ENABLED +// #define HAL_DMA_MODULE_ENABLED // #define HAL_DMA2D_MODULE_ENABLED // #define HAL_ETH_MODULE_ENABLED -#define HAL_FLASH_MODULE_ENABLED +// #define HAL_FLASH_MODULE_ENABLED // #define HAL_NAND_MODULE_ENABLED // #define HAL_NOR_MODULE_ENABLED // #define HAL_PCCARD_MODULE_ENABLED // #define HAL_SRAM_MODULE_ENABLED // #define HAL_SDRAM_MODULE_ENABLED // #define HAL_HASH_MODULE_ENABLED -#define HAL_GPIO_MODULE_ENABLED +// #define HAL_GPIO_MODULE_ENABLED // #define HAL_EXTI_MODULE_ENABLED // #define HAL_I2C_MODULE_ENABLED // #define HAL_SMBUS_MODULE_ENABLED @@ -61,9 +66,9 @@ // #define HAL_IWDG_MODULE_ENABLED // #define HAL_LTDC_MODULE_ENABLED // #define HAL_DSI_MODULE_ENABLED -#define HAL_PWR_MODULE_ENABLED +// #define HAL_PWR_MODULE_ENABLED // #define HAL_QSPI_MODULE_ENABLED -#define HAL_RCC_MODULE_ENABLED +// #define HAL_RCC_MODULE_ENABLED // #define HAL_RNG_MODULE_ENABLED // #define HAL_RTC_MODULE_ENABLED // #define HAL_SAI_MODULE_ENABLED @@ -75,7 +80,7 @@ // #define HAL_IRDA_MODULE_ENABLED // #define HAL_SMARTCARD_MODULE_ENABLED // #define HAL_WWDG_MODULE_ENABLED -#define HAL_CORTEX_MODULE_ENABLED +// #define HAL_CORTEX_MODULE_ENABLED // #define HAL_PCD_MODULE_ENABLED // #define HAL_HCD_MODULE_ENABLED // #define HAL_FMPI2C_MODULE_ENABLED diff --git a/examples/blinky/stm32l0xx_hal_conf.h b/examples/blinky/stm32l0xx_hal_conf.h index f835cc06..47ad4be4 100755 --- a/examples/blinky/stm32l0xx_hal_conf.h +++ b/examples/blinky/stm32l0xx_hal_conf.h @@ -33,6 +33,11 @@ /* ########################## Module Selection ############################## */ /** * @brief This is the list of modules to be used in the HAL driver + * + * `stm32-cmake` automatically defines the `HAL_*_MODULE_ENABLED` variables + * when a driver is added to a project using `target_link_libraries`, so they + * don't need to be defined here + * */ #define HAL_MODULE_ENABLED // #define HAL_ADC_MODULE_ENABLED @@ -40,18 +45,18 @@ // #define HAL_CRC_MODULE_ENABLED // #define HAL_CRYP_MODULE_ENABLED // #define HAL_DAC_MODULE_ENABLED -#define HAL_DMA_MODULE_ENABLED +// #define HAL_DMA_MODULE_ENABLED // #define HAL_EXTI_MODULE_ENABLED // #define HAL_FIREWALL_MODULE_ENABLED -#define HAL_FLASH_MODULE_ENABLED -#define HAL_GPIO_MODULE_ENABLED +// #define HAL_FLASH_MODULE_ENABLED +// #define HAL_GPIO_MODULE_ENABLED // #define HAL_I2C_MODULE_ENABLED // #define HAL_I2S_MODULE_ENABLED // #define HAL_IWDG_MODULE_ENABLED // #define HAL_LCD_MODULE_ENABLED // #define HAL_LPTIM_MODULE_ENABLED // #define HAL_PWR_MODULE_ENABLED -#define HAL_RCC_MODULE_ENABLED +// #define HAL_RCC_MODULE_ENABLED // #define HAL_RNG_MODULE_ENABLED // #define HAL_RTC_MODULE_ENABLED // #define HAL_SPI_MODULE_ENABLED @@ -63,7 +68,7 @@ // #define HAL_SMARTCARD_MODULE_ENABLED // #define HAL_SMBUS_MODULE_ENABLED // #define HAL_WWDG_MODULE_ENABLED -#define HAL_CORTEX_MODULE_ENABLED +// #define HAL_CORTEX_MODULE_ENABLED // #define HAL_PCD_MODULE_ENABLED /* ########################## Oscillator Values adaptation ####################*/