FindSTM32HAL.cmake 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. SET(HAL_HEADERS
  12. stm32f0xx_hal.h
  13. stm32f0xx_hal_def.h
  14. )
  15. SET(HAL_SRCS
  16. stm32f0xx_hal.c
  17. )
  18. ELSEIF(STM32_FAMILY STREQUAL "F1")
  19. SET(HAL_COMPONENTS adc can cec cortex crc dac dma eth flash gpio hcd i2c
  20. i2s irda iwdg nand nor pccard pcd pwr rcc rtc sd smartcard
  21. spi sram tim uart usart wwdg fsmc sdmmc usb)
  22. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  23. # Components that have _ex sources
  24. SET(HAL_EX_COMPONENTS adc dac flash gpio pcd rcc rtc tim)
  25. # Components that have ll_ in names instead of hal_
  26. SET(HAL_LL_COMPONENTS fsmc sdmmc usb)
  27. SET(HAL_PREFIX stm32f1xx_)
  28. SET(HAL_HEADERS
  29. stm32f1xx_hal.h
  30. stm32f1xx_hal_def.h
  31. )
  32. SET(HAL_SRCS
  33. stm32f1xx_hal.c
  34. )
  35. ELSEIF(STM32_FAMILY STREQUAL "F2")
  36. SET(HAL_COMPONENTS adc can cortex crc cryp dac dcmi dma eth flash
  37. gpio hash hcd i2c i2s irda iwdg nand nor pccard
  38. pcd pwr rcc rng rtc sd smartcard spi sram tim
  39. uart usart wwdg fsmc sdmmc usb)
  40. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  41. # Components that have _ex sources
  42. SET(HAL_EX_COMPONENTS adc dac dma flash pwr rcc rtc tim)
  43. # Components that have ll_ in names instead of hal_
  44. SET(HAL_LL_COMPONENTS fsmc sdmmc usb)
  45. SET(HAL_PREFIX stm32f2xx_)
  46. SET(HAL_HEADERS
  47. stm32f2xx_hal.h
  48. stm32f2xx_hal_def.h
  49. )
  50. SET(HAL_SRCS
  51. stm32f2xx_hal.c
  52. )
  53. ELSEIF(STM32_FAMILY STREQUAL "F3")
  54. SET(HAL_COMPONENTS adc can cec comp cortex crc dac dma flash gpio i2c i2s
  55. irda nand nor opamp pccard pcd pwr rcc rtc sdadc
  56. smartcard smbus spi sram tim tsc uart usart wwdg)
  57. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  58. SET(HAL_EX_COMPONENTS adc crc dac flash i2c i2s opamp pcd pwr
  59. rcc rtc smartcard spi tim uart)
  60. SET(HAL_PREFIX stm32f3xx_)
  61. SET(HAL_HEADERS
  62. stm32f3xx_hal.h
  63. stm32f3xx_hal_def.h
  64. )
  65. SET(HAL_SRCS
  66. stm32f3xx_hal.c
  67. )
  68. ELSEIF(STM32_FAMILY STREQUAL "F4")
  69. SET(HAL_COMPONENTS adc can cec cortex crc cryp dac dcmi dma dma2d eth flash
  70. flash_ramfunc fmpi2c gpio hash hcd i2c i2s irda iwdg ltdc
  71. nand nor pccard pcd pwr qspi rcc rng rtc sai sd sdram
  72. smartcard spdifrx spi sram tim uart usart wwdg fmc fsmc
  73. sdmmc usb)
  74. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  75. # Components that have _ex sources
  76. SET(HAL_EX_COMPONENTS adc cryp dac dcmi dma flash fmpi2c hash i2c i2s pcd
  77. pwr rcc rtc sai tim)
  78. # Components that have ll_ in names instead of hal_
  79. SET(HAL_LL_COMPONENTS fmc fsmc sdmmc usb)
  80. SET(HAL_PREFIX stm32f4xx_)
  81. SET(HAL_HEADERS
  82. stm32f4xx_hal.h
  83. stm32f4xx_hal_def.h
  84. )
  85. SET(HAL_SRCS
  86. stm32f4xx_hal.c
  87. )
  88. ELSEIF(STM32_FAMILY STREQUAL "F7")
  89. SET(HAL_COMPONENTS adc can cec cortex crc cryp dac dcmi dma dma2d eth flash
  90. gpio hash hcd i2c i2s irda iwdg lptim ltdc nand nor pcd
  91. pwr qspi rcc rng rtc sai sd sdram smartcard spdifrx spi
  92. sram tim uart usart wwdg fmc sdmmc usb)
  93. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  94. # Components that have _ex sources
  95. SET(HAL_EX_COMPONENTS adc crc cryp dac dcmi dma flash hash i2c pcd
  96. pwr rcc rtc sai tim)
  97. # Components that have ll_ in names instead of hal_
  98. SET(HAL_LL_COMPONENTS fmc sdmmc usb)
  99. SET(HAL_PREFIX stm32f7xx_)
  100. SET(HAL_HEADERS
  101. stm32f7xx_hal.h
  102. stm32f7xx_hal_def.h
  103. )
  104. SET(HAL_SRCS
  105. stm32f7xx_hal.c
  106. )
  107. ELSEIF(STM32_FAMILY STREQUAL "L0")
  108. SET(HAL_COMPONENTS adc comp cortex crc crs cryp dac dma exti firewall flash gpio i2c
  109. i2s irda iwdg lcd lptim lpuart pcd pwr rcc rng rtc smartcard
  110. smbus spi tim tsc uart usart utils wwdg)
  111. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  112. # Components that have _ex sources
  113. SET(HAL_EX_COMPONENTS adc comp crc cryp dac flash i2c pcd pwr rcc rtc smartcard tim uart usart)
  114. # Components that have ll_ in names instead of hal_
  115. SET(HAL_LL_COMPONENTS crs exti lpuart utils)
  116. SET(HAL_PREFIX stm32l0xx_)
  117. SET(HAL_HEADERS
  118. stm32l0xx_hal.h
  119. stm32l0xx_hal_def.h
  120. )
  121. SET(HAL_SRCS
  122. stm32l0xx_hal.c
  123. )
  124. ELSEIF(STM32_FAMILY STREQUAL "L4")
  125. SET(HAL_COMPONENTS adc can comp cortex crc cryp dac dcmi dfsdm dma dma2d dsi
  126. firewall flash flash_ramfunc gfxmmu gpio hash hcd i2c irda iwdg
  127. lcd lptim ltdc nand nor opamp ospi pcd pwr qspi rcc rng rtc sai
  128. sd smartcard smbus spi sram swpmi tim tsc uart usart wwdg)
  129. SET(HAL_REQUIRED_COMPONENTS cortex pwr rcc)
  130. # Components that have _ex sources
  131. SET(HAL_EX_COMPONENTS adc crc cryp dac dfsdm dma flash hash i2c ltdc
  132. opamp pcd pwr rcc rtc sai sd smartcard spi tim uart usart)
  133. # Components that have ll_ in names instead of hal_
  134. SET(HAL_LL_COMPONENTS adc comp crc crs dac dma dma2d exti fmc gpio i2c lptim lpuart
  135. opamp pwr rcc rng rtc sdmmc spi swpmi tim usart usb utils)
  136. SET(HAL_PREFIX stm32l4xx_)
  137. SET(HAL_HEADERS
  138. stm32l4xx_hal.h
  139. stm32l4xx_hal_def.h
  140. )
  141. SET(HAL_SRCS
  142. stm32l4xx_hal.c
  143. )
  144. ENDIF()
  145. IF(NOT STM32HAL_FIND_COMPONENTS)
  146. SET(STM32HAL_FIND_COMPONENTS ${HAL_COMPONENTS})
  147. MESSAGE(STATUS "No STM32HAL components selected, using all: ${STM32HAL_FIND_COMPONENTS}")
  148. ENDIF()
  149. FOREACH(cmp ${HAL_REQUIRED_COMPONENTS})
  150. LIST(FIND STM32HAL_FIND_COMPONENTS ${cmp} STM32HAL_FOUND_INDEX)
  151. IF(${STM32HAL_FOUND_INDEX} LESS 0)
  152. LIST(APPEND STM32HAL_FIND_COMPONENTS ${cmp})
  153. ENDIF()
  154. ENDFOREACH()
  155. FOREACH(cmp ${STM32HAL_FIND_COMPONENTS})
  156. LIST(FIND HAL_COMPONENTS ${cmp} STM32HAL_FOUND_INDEX)
  157. IF(${STM32HAL_FOUND_INDEX} LESS 0)
  158. MESSAGE(FATAL_ERROR "Unknown STM32HAL component: ${cmp}. Available components: ${HAL_COMPONENTS}")
  159. ENDIF()
  160. LIST(FIND HAL_LL_COMPONENTS ${cmp} STM32HAL_FOUND_INDEX)
  161. IF(${STM32HAL_FOUND_INDEX} LESS 0)
  162. LIST(APPEND HAL_HEADERS ${HAL_PREFIX}hal_${cmp}.h)
  163. LIST(APPEND HAL_SRCS ${HAL_PREFIX}hal_${cmp}.c)
  164. ELSE()
  165. LIST(APPEND HAL_HEADERS ${HAL_PREFIX}ll_${cmp}.h)
  166. LIST(APPEND HAL_SRCS ${HAL_PREFIX}ll_${cmp}.c)
  167. ENDIF()
  168. LIST(FIND HAL_EX_COMPONENTS ${cmp} STM32HAL_FOUND_INDEX)
  169. IF(NOT (${STM32HAL_FOUND_INDEX} LESS 0))
  170. LIST(APPEND HAL_HEADERS ${HAL_PREFIX}hal_${cmp}_ex.h)
  171. LIST(APPEND HAL_SRCS ${HAL_PREFIX}hal_${cmp}_ex.c)
  172. ENDIF()
  173. ENDFOREACH()
  174. LIST(REMOVE_DUPLICATES HAL_HEADERS)
  175. LIST(REMOVE_DUPLICATES HAL_SRCS)
  176. STRING(TOLOWER ${STM32_FAMILY} STM32_FAMILY_LOWER)
  177. FIND_PATH(STM32HAL_INCLUDE_DIR ${HAL_HEADERS}
  178. PATH_SUFFIXES include stm32${STM32_FAMILY_LOWER}
  179. HINTS ${STM32Cube_DIR}/Drivers/STM32${STM32_FAMILY}xx_HAL_Driver/Inc
  180. CMAKE_FIND_ROOT_PATH_BOTH
  181. )
  182. FOREACH(HAL_SRC ${HAL_SRCS})
  183. STRING(MAKE_C_IDENTIFIER "${HAL_SRC}" HAL_SRC_CLEAN)
  184. SET(HAL_${HAL_SRC_CLEAN}_FILE HAL_SRC_FILE-NOTFOUND)
  185. FIND_FILE(HAL_${HAL_SRC_CLEAN}_FILE ${HAL_SRC}
  186. PATH_SUFFIXES src stm32${STM32_FAMILY_LOWER}
  187. HINTS ${STM32Cube_DIR}/Drivers/STM32${STM32_FAMILY}xx_HAL_Driver/Src
  188. CMAKE_FIND_ROOT_PATH_BOTH
  189. )
  190. LIST(APPEND STM32HAL_SOURCES ${HAL_${HAL_SRC_CLEAN}_FILE})
  191. ENDFOREACH()
  192. INCLUDE(FindPackageHandleStandardArgs)
  193. FIND_PACKAGE_HANDLE_STANDARD_ARGS(STM32HAL DEFAULT_MSG STM32HAL_INCLUDE_DIR STM32HAL_SOURCES)