| 1 | cmake_minimum_required(VERSION 3.22)
|
|---|
| 2 | # Enable CMake support for ASM and C languages
|
|---|
| 3 | enable_language(C ASM)
|
|---|
| 4 | # STM32CubeMX generated symbols (macros)
|
|---|
| 5 | set(MX_Defines_Syms
|
|---|
| 6 | USE_FULL_LL_DRIVER
|
|---|
| 7 | USBPD_PORT_COUNT=1
|
|---|
| 8 | _SRC
|
|---|
| 9 | USBPDCORE_LIB_PD3_FULL
|
|---|
| 10 | USE_HAL_DRIVER
|
|---|
| 11 | STM32G473xx
|
|---|
| 12 | $<$<CONFIG:Debug>:DEBUG>
|
|---|
| 13 | )
|
|---|
| 14 |
|
|---|
| 15 | # STM32CubeMX generated include paths
|
|---|
| 16 | set(MX_Include_Dirs
|
|---|
| 17 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Inc
|
|---|
| 18 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USBPD/App
|
|---|
| 19 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USBPD/Target
|
|---|
| 20 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USBPD
|
|---|
| 21 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USB_Device/App
|
|---|
| 22 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USB_Device/Target
|
|---|
| 23 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Inc
|
|---|
| 24 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy
|
|---|
| 25 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Core/inc
|
|---|
| 26 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/inc
|
|---|
| 27 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Core/Inc
|
|---|
| 28 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
|
|---|
| 29 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Device/ST/STM32G4xx/Include
|
|---|
| 30 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Include
|
|---|
| 31 | )
|
|---|
| 32 |
|
|---|
| 33 | # STM32CubeMX generated application sources
|
|---|
| 34 | set(MX_Application_Src
|
|---|
| 35 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USBPD/App/usbpd.c
|
|---|
| 36 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USBPD/App/usbpd_pwr_if.c
|
|---|
| 37 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USBPD/App/usbpd_dpm_core.c
|
|---|
| 38 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USBPD/Target/usbpd_dpm_user.c
|
|---|
| 39 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USBPD/Target/usbpd_pwr_user.c
|
|---|
| 40 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USBPD/Target/usbpd_vdm_user.c
|
|---|
| 41 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USB_Device/App/usb_device.c
|
|---|
| 42 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USB_Device/App/usbd_desc.c
|
|---|
| 43 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USB_Device/App/usbd_cdc_if.c
|
|---|
| 44 | ${CMAKE_CURRENT_SOURCE_DIR}/../../USB_Device/Target/usbd_conf.c
|
|---|
| 45 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/main.c
|
|---|
| 46 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/gpio.c
|
|---|
| 47 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/adc.c
|
|---|
| 48 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/crc.c
|
|---|
| 49 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/dma.c
|
|---|
| 50 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/i2c.c
|
|---|
| 51 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/iwdg.c
|
|---|
| 52 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/rtc.c
|
|---|
| 53 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/spi.c
|
|---|
| 54 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/tim.c
|
|---|
| 55 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/ucpd.c
|
|---|
| 56 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/usart.c
|
|---|
| 57 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/stm32g4xx_it.c
|
|---|
| 58 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/stm32g4xx_hal_msp.c
|
|---|
| 59 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/sysmem.c
|
|---|
| 60 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/syscalls.c
|
|---|
| 61 | ${CMAKE_CURRENT_SOURCE_DIR}/../../startup_stm32g473xx.s
|
|---|
| 62 | )
|
|---|
| 63 |
|
|---|
| 64 | # STM32 HAL/LL Drivers
|
|---|
| 65 | set(STM32_Drivers_Src
|
|---|
| 66 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/system_stm32g4xx.c
|
|---|
| 67 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_utils.c
|
|---|
| 68 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_exti.c
|
|---|
| 69 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pcd.c
|
|---|
| 70 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pcd_ex.c
|
|---|
| 71 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_usb.c
|
|---|
| 72 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal.c
|
|---|
| 73 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc.c
|
|---|
| 74 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc_ex.c
|
|---|
| 75 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash.c
|
|---|
| 76 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ex.c
|
|---|
| 77 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ramfunc.c
|
|---|
| 78 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_gpio.c
|
|---|
| 79 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_exti.c
|
|---|
| 80 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma.c
|
|---|
| 81 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma_ex.c
|
|---|
| 82 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr.c
|
|---|
| 83 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr_ex.c
|
|---|
| 84 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_cortex.c
|
|---|
| 85 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_rcc.c
|
|---|
| 86 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_pwr.c
|
|---|
| 87 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc.c
|
|---|
| 88 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc_ex.c
|
|---|
| 89 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_adc.c
|
|---|
| 90 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_crc.c
|
|---|
| 91 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_crc_ex.c
|
|---|
| 92 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c.c
|
|---|
| 93 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c_ex.c
|
|---|
| 94 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_iwdg.c
|
|---|
| 95 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rtc.c
|
|---|
| 96 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rtc_ex.c
|
|---|
| 97 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_spi.c
|
|---|
| 98 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_spi_ex.c
|
|---|
| 99 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim.c
|
|---|
| 100 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim_ex.c
|
|---|
| 101 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_ucpd.c
|
|---|
| 102 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_gpio.c
|
|---|
| 103 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_dma.c
|
|---|
| 104 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart.c
|
|---|
| 105 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart_ex.c
|
|---|
| 106 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_tim.c
|
|---|
| 107 | )
|
|---|
| 108 |
|
|---|
| 109 | # Drivers Midllewares
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | set(USB_Device_Library_Src
|
|---|
| 113 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
|
|---|
| 114 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
|
|---|
| 115 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
|
|---|
| 116 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c
|
|---|
| 117 | )
|
|---|
| 118 | set(USBPD_Src
|
|---|
| 119 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Core/src/usbpd_trace.c
|
|---|
| 120 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_cad_hw_if.c
|
|---|
| 121 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_hw.c
|
|---|
| 122 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_hw_if_it.c
|
|---|
| 123 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_phy.c
|
|---|
| 124 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_phy_hw_if.c
|
|---|
| 125 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_pwr_hw_if.c
|
|---|
| 126 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Devices/STM32G4XX/src/usbpd_timersserver.c
|
|---|
| 127 | )
|
|---|
| 128 |
|
|---|
| 129 | # Link directories setup
|
|---|
| 130 | set(MX_LINK_DIRS
|
|---|
| 131 |
|
|---|
| 132 | ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/ST/STM32_USBPD_Library/Core/lib
|
|---|
| 133 | )
|
|---|
| 134 | # Project static libraries
|
|---|
| 135 | set(MX_LINK_LIBS
|
|---|
| 136 | :USBPDCORE_PD3_FULL_CM4_wc32.a
|
|---|
| 137 | STM32_Drivers
|
|---|
| 138 | ${TOOLCHAIN_LINK_LIBRARIES}
|
|---|
| 139 | USB_Device_Library
|
|---|
| 140 | USBPD
|
|---|
| 141 |
|
|---|
| 142 | )
|
|---|
| 143 | # Interface library for includes and symbols
|
|---|
| 144 | add_library(stm32cubemx INTERFACE)
|
|---|
| 145 | target_include_directories(stm32cubemx INTERFACE ${MX_Include_Dirs})
|
|---|
| 146 | target_compile_definitions(stm32cubemx INTERFACE ${MX_Defines_Syms})
|
|---|
| 147 |
|
|---|
| 148 | # Create STM32_Drivers static library
|
|---|
| 149 | add_library(STM32_Drivers OBJECT)
|
|---|
| 150 | target_sources(STM32_Drivers PRIVATE ${STM32_Drivers_Src})
|
|---|
| 151 | target_link_libraries(STM32_Drivers PUBLIC stm32cubemx)
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 | # Create USB_Device_Library static library
|
|---|
| 155 | add_library(USB_Device_Library OBJECT)
|
|---|
| 156 | target_sources(USB_Device_Library PRIVATE ${USB_Device_Library_Src})
|
|---|
| 157 | target_link_libraries(USB_Device_Library PUBLIC stm32cubemx)
|
|---|
| 158 |
|
|---|
| 159 | # Create USBPD static library
|
|---|
| 160 | add_library(USBPD OBJECT)
|
|---|
| 161 | target_sources(USBPD PRIVATE ${USBPD_Src})
|
|---|
| 162 | target_link_libraries(USBPD PUBLIC stm32cubemx)
|
|---|
| 163 |
|
|---|
| 164 | # Add STM32CubeMX generated application sources to the project
|
|---|
| 165 | target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${MX_Application_Src})
|
|---|
| 166 |
|
|---|
| 167 | # Link directories setup
|
|---|
| 168 | target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${MX_LINK_DIRS})
|
|---|
| 169 |
|
|---|
| 170 | # Add libraries to the project
|
|---|
| 171 | target_link_libraries(${CMAKE_PROJECT_NAME} ${MX_LINK_LIBS})
|
|---|
| 172 |
|
|---|
| 173 | # Add the map file to the list of files to be removed with 'clean' target
|
|---|
| 174 | set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_PROJECT_NAME}.map)
|
|---|
| 175 |
|
|---|
| 176 | # Validate that STM32CubeMX code is compatible with C standard
|
|---|
| 177 | if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99))
|
|---|
| 178 | message(ERROR "Generated code requires C11 or higher")
|
|---|
| 179 | endif()
|
|---|