FindSTM32HAL.cmake 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. IF(STM32_FAMILY STREQUAL "F0")
  2. SET(HAL_COMPONENTS adc can cec comp cortex crc dac dma flash gpio i2c
  3. i2s irda iwdg pcd pwr rcc rtc smartcard smbus
  4. spi tim tsc uart usart wwdg)
  5. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  6. # Components that have _ex sources
  7. SET(HAL_EX_COMPONENTS adc crc dac flash i2c pcd pwr rcc rtc smartcard spi tim uart)
  8. # Components that have ll_ in names instead of hal_
  9. SET(HAL_LL_COMPONENTS "")
  10. SET(HAL_PREFIX stm32f0xx_)
  11. ELSEIF(STM32_FAMILY STREQUAL "F1")
  12. SET(HAL_COMPONENTS adc can cec cortex crc dac dma eth flash gpio hcd i2c
  13. i2s irda iwdg nand nor pccard pcd pwr rcc rtc sd smartcard
  14. spi sram tim uart usart wwdg fsmc sdmmc usb)
  15. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  16. # Components that have _ex sources
  17. SET(HAL_EX_COMPONENTS adc dac flash gpio pcd rcc rtc tim)
  18. # Components that have ll_ in names instead of hal_
  19. SET(HAL_LL_COMPONENTS fsmc sdmmc usb)
  20. SET(HAL_PREFIX stm32f1xx_)
  21. ELSEIF(STM32_FAMILY STREQUAL "F2")
  22. SET(HAL_COMPONENTS adc can cortex crc cryp dac dcmi dma eth flash
  23. gpio hash hcd i2c i2s irda iwdg nand nor pccard
  24. pcd pwr rcc rng rtc sd smartcard spi sram tim
  25. uart usart wwdg fsmc sdmmc usb)
  26. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  27. # Components that have _ex sources
  28. SET(HAL_EX_COMPONENTS adc dac dma flash pwr rcc rtc tim)
  29. # Components that have ll_ in names instead of hal_
  30. SET(HAL_LL_COMPONENTS fsmc sdmmc usb)
  31. SET(HAL_PREFIX stm32f2xx_)
  32. ELSEIF(STM32_FAMILY STREQUAL "F3")
  33. SET(HAL_COMPONENTS adc can cec comp cortex crc dac dma flash gpio i2c i2s
  34. irda nand nor opamp pccard pcd pwr rcc rtc sdadc
  35. smartcard smbus spi sram tim tsc uart usart wwdg)
  36. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  37. SET(HAL_EX_COMPONENTS adc crc dac flash i2c i2s opamp pcd pwr
  38. rcc rtc smartcard spi tim uart)
  39. SET(HAL_PREFIX stm32f3xx_)
  40. ELSEIF(STM32_FAMILY STREQUAL "F4")
  41. SET(HAL_COMPONENTS adc can cec cortex crc cryp dac dcmi dma dma2d eth flash
  42. flash_ramfunc fmpi2c gpio hash hcd i2c i2s irda iwdg ltdc
  43. nand nor pccard pcd pwr qspi rcc rng rtc sai sd sdram
  44. smartcard spdifrx spi sram tim uart usart wwdg fmc fsmc
  45. sdmmc usb)
  46. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  47. # Components that have _ex sources
  48. SET(HAL_EX_COMPONENTS adc cryp dac dcmi dma flash fmpi2c hash i2c i2s pcd
  49. pwr rcc rtc sai tim)
  50. # Components that have ll_ in names instead of hal_
  51. SET(HAL_LL_COMPONENTS fmc fsmc sdmmc usb)
  52. SET(HAL_PREFIX stm32f4xx_)
  53. ELSEIF(STM32_FAMILY STREQUAL "F7")
  54. SET(HAL_COMPONENTS adc can cec cortex crc cryp dac dcmi dma dma2d eth flash
  55. gpio hash hcd i2c i2s irda iwdg lptim ltdc nand nor pcd
  56. pwr qspi rcc rng rtc sai sd sdram smartcard spdifrx spi
  57. sram tim uart usart wwdg fmc sdmmc usb)
  58. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  59. # Components that have _ex sources
  60. SET(HAL_EX_COMPONENTS adc crc cryp dac dcmi dma flash hash i2c pcd
  61. pwr rcc rtc sai tim)
  62. # Components that have ll_ in names instead of hal_
  63. SET(HAL_LL_COMPONENTS fmc sdmmc usb)
  64. SET(HAL_PREFIX stm32f7xx_)
  65. ELSEIF(STM32_FAMILY STREQUAL "L0")
  66. SET(HAL_COMPONENTS adc comp cortex crc crs cryp dac dma exti firewall flash gpio i2c
  67. i2s irda iwdg lcd lptim lpuart pcd pwr rcc rng rtc smartcard
  68. smbus spi tim tsc uart usart utils wwdg)
  69. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  70. # Components that have _ex sources
  71. SET(HAL_EX_COMPONENTS adc comp crc cryp dac flash i2c pcd pwr rcc rtc smartcard tim uart usart)
  72. # Components that have ll_ in names instead of hal_
  73. SET(HAL_LL_COMPONENTS crs exti lpuart utils)
  74. SET(HAL_PREFIX stm32l0xx_)
  75. ELSEIF(STM32_FAMILY STREQUAL "L4")
  76. SET(HAL_COMPONENTS adc can comp cortex crc cryp dac dcmi dfsdm dma dma2d dsi
  77. firewall flash flash_ramfunc gfxmmu gpio hash hcd i2c irda iwdg
  78. lcd lptim ltdc nand nor opamp ospi pcd pwr qspi rcc rng rtc sai
  79. sd smartcard smbus spi sram swpmi tim tsc uart usart wwdg)
  80. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  81. # Components that have _ex sources
  82. SET(HAL_EX_COMPONENTS adc crc cryp dac dfsdm dma flash hash i2c ltdc
  83. opamp pcd pwr rcc rtc sai sd smartcard spi tim uart usart)
  84. # Components that have ll_ in names instead of hal_
  85. SET(HAL_LL_COMPONENTS adc comp crc crs dac dma dma2d exti fmc gpio i2c lptim lpuart
  86. opamp pwr rcc rng rtc sdmmc spi swpmi tim usart usb utils)
  87. SET(HAL_PREFIX stm32l4xx_)
  88. ENDIF()
  89. SET(HAL_HEADERS
  90. ${HAL_PREFIX}hal.h
  91. ${HAL_PREFIX}hal_def.h
  92. )
  93. SET(HAL_SRCS
  94. ${HAL_PREFIX}hal.c
  95. )
  96. IF(NOT STM32HAL_FIND_COMPONENTS)
  97. SET(STM32HAL_FIND_COMPONENTS ${HAL_COMPONENTS})
  98. MESSAGE(STATUS "No STM32HAL components selected, using all: ${STM32HAL_FIND_COMPONENTS}")
  99. ENDIF()
  100. FOREACH(cmp ${HAL_REQUIRED_COMPONENTS})
  101. LIST(FIND STM32HAL_FIND_COMPONENTS ${cmp} STM32HAL_FOUND_INDEX)
  102. IF(${STM32HAL_FOUND_INDEX} LESS 0)
  103. LIST(APPEND STM32HAL_FIND_COMPONENTS ${cmp})
  104. ENDIF()
  105. ENDFOREACH()
  106. FOREACH(cmp ${STM32HAL_FIND_COMPONENTS})
  107. LIST(FIND HAL_COMPONENTS ${cmp} STM32HAL_FOUND_INDEX)
  108. IF(${STM32HAL_FOUND_INDEX} LESS 0)
  109. MESSAGE(FATAL_ERROR "Unknown STM32HAL component: ${cmp}. Available components: ${HAL_COMPONENTS}")
  110. ENDIF()
  111. LIST(FIND HAL_LL_COMPONENTS ${cmp} STM32HAL_FOUND_INDEX)
  112. IF(${STM32HAL_FOUND_INDEX} LESS 0)
  113. LIST(APPEND HAL_HEADERS ${HAL_PREFIX}hal_${cmp}.h)
  114. LIST(APPEND HAL_SRCS ${HAL_PREFIX}hal_${cmp}.c)
  115. ELSE()
  116. LIST(APPEND HAL_HEADERS ${HAL_PREFIX}ll_${cmp}.h)
  117. LIST(APPEND HAL_SRCS ${HAL_PREFIX}ll_${cmp}.c)
  118. ENDIF()
  119. LIST(FIND HAL_EX_COMPONENTS ${cmp} STM32HAL_FOUND_INDEX)
  120. IF(NOT (${STM32HAL_FOUND_INDEX} LESS 0))
  121. LIST(APPEND HAL_HEADERS ${HAL_PREFIX}hal_${cmp}_ex.h)
  122. LIST(APPEND HAL_SRCS ${HAL_PREFIX}hal_${cmp}_ex.c)
  123. ENDIF()
  124. ENDFOREACH()
  125. LIST(REMOVE_DUPLICATES HAL_HEADERS)
  126. LIST(REMOVE_DUPLICATES HAL_SRCS)
  127. STRING(TOLOWER ${STM32_FAMILY} STM32_FAMILY_LOWER)
  128. FIND_PATH(STM32HAL_INCLUDE_DIR ${HAL_HEADERS}
  129. PATH_SUFFIXES include stm32${STM32_FAMILY_LOWER}
  130. HINTS ${STM32Cube_DIR}/Drivers/STM32${STM32_FAMILY}xx_HAL_Driver/Inc
  131. CMAKE_FIND_ROOT_PATH_BOTH
  132. )
  133. FOREACH(HAL_SRC ${HAL_SRCS})
  134. STRING(MAKE_C_IDENTIFIER "${HAL_SRC}" HAL_SRC_CLEAN)
  135. SET(HAL_${HAL_SRC_CLEAN}_FILE HAL_SRC_FILE-NOTFOUND)
  136. FIND_FILE(HAL_${HAL_SRC_CLEAN}_FILE ${HAL_SRC}
  137. PATH_SUFFIXES src stm32${STM32_FAMILY_LOWER}
  138. HINTS ${STM32Cube_DIR}/Drivers/STM32${STM32_FAMILY}xx_HAL_Driver/Src
  139. CMAKE_FIND_ROOT_PATH_BOTH
  140. )
  141. LIST(APPEND STM32HAL_SOURCES ${HAL_${HAL_SRC_CLEAN}_FILE})
  142. ENDFOREACH()
  143. INCLUDE(FindPackageHandleStandardArgs)
  144. FIND_PACKAGE_HANDLE_STANDARD_ARGS(STM32HAL DEFAULT_MSG STM32HAL_INCLUDE_DIR STM32HAL_SOURCES)