Browse Source

[BUILD] Add support for building F3 targets with cmake

master
Alberto García Hierro 4 years ago
parent
commit
fedabef03e
  1. 2
      cmake/arm-none-eabi.cmake
  2. 23
      cmake/cortex-m4f.cmake
  3. 58
      cmake/stm32-usb.cmake
  4. 15
      cmake/stm32.cmake
  5. 16
      cmake/stm32f3-usb.cmake
  6. 81
      cmake/stm32f3.cmake
  7. 55
      cmake/stm32f4-usb.cmake
  8. 35
      cmake/stm32f4.cmake
  9. 2
      src/main/target/AIRHEROF3/CMakeLists.txt
  10. 1
      src/main/target/BETAFLIGHTF3/CMakeLists.txt
  11. 1
      src/main/target/FALCORE/CMakeLists.txt
  12. 1
      src/main/target/FRSKYF3/CMakeLists.txt
  13. 2
      src/main/target/FURYF3/CMakeLists.txt
  14. 1
      src/main/target/KFC32F3_INAV/CMakeLists.txt
  15. 1
      src/main/target/LUX_RACE/CMakeLists.txt
  16. 1
      src/main/target/MOTOLAB/CMakeLists.txt
  17. 1
      src/main/target/OMNIBUS/CMakeLists.txt
  18. 1
      src/main/target/PIKOBLX/CMakeLists.txt
  19. 1
      src/main/target/RCEXPLORERF3/CMakeLists.txt
  20. 1
      src/main/target/RMDO/CMakeLists.txt
  21. 1
      src/main/target/SPARKY/CMakeLists.txt
  22. 1
      src/main/target/SPRACINGF3/CMakeLists.txt
  23. 2
      src/main/target/SPRACINGF3EVO/CMakeLists.txt
  24. 1
      src/main/target/SPRACINGF3MINI/CMakeLists.txt

2
cmake/arm-none-eabi.cmake

@ -47,7 +47,7 @@ set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build Type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
set(arm_none_eabi_debug "-Og -g")
set(arm_none_eabi_release "-O2 -DNDEBUG -flto -fuse-linker-plugin")
set(arm_none_eabi_release "-Os -DNDEBUG -flto -fuse-linker-plugin")
set(arm_none_eabi_relwithdebinfo "-ggdb3 ${arm_none_eabi_release}")
SET(CMAKE_C_FLAGS_DEBUG ${arm_none_eabi_debug} CACHE INTERNAL "c compiler flags debug")

23
cmake/cortex-m4f.cmake

@ -0,0 +1,23 @@
set(CORTEX_M4F_COMMON_OPTIONS
-mthumb
-mcpu=cortex-m4
-march=armv7e-m
-mfloat-abi=hard
-mfpu=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
)
set(CORTEX_M4F_COMPILE_OPTIONS
)
set(CORTEX_M4F_LINK_OPTIONS
)
set(CORTEX_M4F_DEFINITIONS
__FPU_PRESENT=1
ARM_MATH_CM4
ARM_MATH_MATRIX_CHECK
ARM_MATH_ROUNDING
UNALIGNED_SUPPORT_DISABLE
)

58
cmake/stm32-usb.cmake

@ -1,58 +0,0 @@
set(STM32_STDPERIPH_USBOTG_DIR "${INAV_LIB_DIR}/main/STM32_USB_OTG_Driver")
set(STM32_STDPERIPH_USBCORE_DIR "${INAV_LIB_DIR}/main/STM32_USB_Device_Library/Core")
set(STM32_STDPERIPH_USBCDC_DIR "${INAV_LIB_DIR}/main/STM32_USB_Device_Library/Class/cdc")
set(STM32_STDPERIPH_USBHID_DIR "${INAV_LIB_DIR}/main/STM32_USB_Device_Library/Class/hid")
set(STM32_STDPERIPH_USBWRAPPER_DIR "${INAV_LIB_DIR}/main/STM32_USB_Device_Library/Class/hid_cdc_wrapper")
set(STM32_STDPERIPH_USBMSC_DIR "${INAV_LIB_DIR}/main/STM32_USB_Device_Library/Class/msc")
set(STM32_STDPERIPH_USBFS_DIR "${INAV_LIB_DIR}/main/STM32_USB-FS-Device_Driver")
set(STM32_STDPERIPH_USB_INCLUDE_DIRS
"${STM32_STDPERIPH_USBOTG_DIR}/inc"
"${STM32_STDPERIPH_USBCORE_DIR}/inc"
"${STM32_STDPERIPH_USBCDC_DIR}/inc"
"${STM32_STDPERIPH_USBHID_DIR}/inc"
"${STM32_STDPERIPH_USBWRAPPER_DIR}/inc"
"${STM32_STDPERIPH_USBMSC_DIR}/inc"
"${STM32_STDPERIPH_USBFS_DIR}/inc"
)
set(STM32_STDPERIPH_USBOTG_SRC
usb_core.c
usb_dcd.c
usb_dcd_int.c
)
list(TRANSFORM STM32_STDPERIPH_USBOTG_SRC PREPEND "${STM32_STDPERIPH_USBOTG_DIR}/src/")
set(STM32_STDPERIPH_USBCORE_SRC
usbd_core.c
usbd_ioreq.c
usbd_req.c
)
list(TRANSFORM STM32_STDPERIPH_USBCORE_SRC PREPEND "${STM32_STDPERIPH_USBCORE_DIR}/src/")
set(STM32_STDPERIPH_USBCDC_SRC
"${STM32_STDPERIPH_USBCDC_DIR}/src/usbd_cdc_core.c"
)
set(STM32_STDPERIPH_USBHID_SRC
"${STM32_STDPERIPH_USBHID_DIR}/src/usbd_hid_core.c"
)
set(STM32_STDPERIPH_USBWRAPPER_SRC
"${STM32_STDPERIPH_USBWRAPPER_DIR}/src/usbd_hid_cdc_wrapper.c"
)
set(STM32_STDPERIPH_USBMSC_SRC
usbd_msc_bot.c
usbd_msc_core.c
usbd_msc_data.c
usbd_msc_scsi.c
)
list(TRANSFORM STM32_STDPERIPH_USBMSC_SRC PREPEND "${STM32_STDPERIPH_USBMSC_DIR}/src/")
list(APPEND STM32_STDPERIPH_USB_SRC ${STM32_STDPERIPH_USBOTG_SRC})
list(APPEND STM32_STDPERIPH_USB_SRC ${STM32_STDPERIPH_USBCORE_SRC})
list(APPEND STM32_STDPERIPH_USB_SRC ${STM32_STDPERIPH_USBCDC_SRC})
list(APPEND STM32_STDPERIPH_USB_SRC ${STM32_STDPERIPH_USBHID_SRC})
list(APPEND STM32_STDPERIPH_USB_SRC ${STM32_STDPERIPH_USBWRAPPER_SRC})
list(APPEND STM32_STDPERIPH_USB_SRC ${STM32_STDPERIPH_USBMSC_SRC})

15
cmake/stm32.cmake

@ -1,6 +1,6 @@
include(arm-none-eabi)
include(stm32f3)
include(stm32f4)
include(stm32-usb)
include(CMakeParseArguments)
@ -137,10 +137,10 @@ function(target_stm32 name startup ldscript)
# Parse keyword arguments
cmake_parse_arguments(
PARSED_ARGS
"" # No boolean arguments
"HSE_MHZ" # Single value arguments
"" # No multi-value arguments
${ARGN} # Start parsing after the known arguments
"DISABLE_MSC" # Boolean arguments
"HSE_MHZ" # Single value arguments
"DEFINITIONS" # Multi-value arguments
${ARGN} # Start parsing after the known arguments
)
if (PARSED_ARGS_HSE_MHZ)
set(hse_mhz ${PARSED_ARGS_HSE_MHZ})
@ -163,6 +163,9 @@ function(target_stm32 name startup ldscript)
set(target_definitions ${STM32_DEFINITIONS})
math(EXPR hse_value "${hse_mhz} * 1000000")
list(APPEND target_definitions "HSE_VALUE=${hse_value}")
if(PARSED_ARGS_DEFINITIONS)
list(APPEND target_definitions ${PARSED_ARGS_DEFINITIONS})
endif()
target_compile_definitions(${name} PRIVATE ${target_definitions})
get_stm32_target_features(features "${CMAKE_CURRENT_SOURCE_DIR}")
@ -173,7 +176,7 @@ function(target_stm32 name startup ldscript)
if(SDCARD IN_LIST features)
target_sources(${name} PRIVATE ${STM32_SDCARD_SRC} ${STM32_ASYNCFATFS_SRC})
endif()
if(MSC IN_LIST features)
if(NOT PARSED_ARGS_DISABLE_MSC AND MSC IN_LIST features)
target_sources(${name} PRIVATE ${STM32_MSC_SRC})
if (FLASHFS IN_LIST features)
target_sources(${name} PRIVATE ${STM32_MSC_FLASH_SRC})

16
cmake/stm32f3-usb.cmake

@ -0,0 +1,16 @@
set(STM32_USBFS_DIR "${INAV_LIB_DIR}/main/STM32_USB-FS-Device_Driver")
set(STM32_USBFS_SRC
usb_core.c
usb_init.c
usb_int.c
usb_mem.c
usb_regs.c
usb_sil.c
)
list(TRANSFORM STM32_USBFS_SRC PREPEND "${STM32_USBFS_DIR}/src/")
set(STM32F3_USB_INCLUDE_DIRS
${STM32_USBFS_DIR}/inc
)
set(STM32F3_USB_SRC ${STM32_USBFS_SRC})

81
cmake/stm32f3.cmake

@ -0,0 +1,81 @@
include(cortex-m4f)
include(stm32f3-usb)
set(STM32F3_STDPERIPH_DIR "${INAV_LIB_DIR}/main/STM32F3/Drivers/STM32F30x_StdPeriph_Driver")
set(STM32F3_CMSIS_DEVICE_DIR "${INAV_LIB_DIR}/main/STM32F3/Drivers/CMSIS/Device/ST/STM32F30x")
set(STM32F3_CMSIS_DRIVERS_DIR "${INAV_LIB_DIR}/main/STM32F3/Drivers/CMSIS")
set(STM32F3_VCP_DIR "${INAV_MAIN_SRC_DIR}/vcp")
set(STM32F3_STDPERIPH_SRC_EXCLUDES
stm32f30x_crc.c
stm32f30x_can.c
)
set(STM32F3_STDPERIPH_SRC_DIR "${STM32F3_STDPERIPH_DIR}/Src")
glob_except(STM32F3_STDPERIPH_SRC "${STM32F3_STDPERIPH_SRC_DIR}/*.c" STM32F3_STDPERIPH_SRC_EXCLUDES)
set(STM32F3_SRC
target/system_stm32f30x.c
drivers/adc_stm32f30x.c
drivers/bus_i2c_stm32f30x.c
drivers/dma_stm32f3xx.c
drivers/serial_uart_stm32f30x.c
drivers/system_stm32f30x.c
drivers/timer_impl_stdperiph.c
drivers/timer_stm32f30x.c
)
main_sources(STM32F3_SRC)
set(STM32F3_VCP_SRC
hw_config.c
stm32_it.c
usb_desc.c
usb_endp.c
usb_istr.c
usb_prop.c
usb_pwr.c
)
list(TRANSFORM STM32F3_VCP_SRC PREPEND "${STM32F3_VCP_DIR}/")
set(STM32F3_INCLUDE_DIRS
"${CMSIS_INCLUDE_DIR}"
"${CMSIS_DSP_INCLUDE_DIR}"
"${STM32F3_STDPERIPH_DIR}/inc"
"${STM32F3_CMSIS_DEVICE_DIR}"
"${STM32F3_CMSIS_DRIVERS_DIR}"
"${STM32F3_VCP_DIR}"
)
set(STM32F3_DEFINITIONS
${CORTEX_M4F_DEFINITIONS}
STM32F3
USE_STDPERIPH_DRIVER
)
set(STM32F303_DEFINITIONS
STM32F303
STM32F303xC
FLASH_SIZE=256
)
function(target_stm32f3xx name startup ldscript)
# F3 targets don't support MSC
target_stm32(${name} ${startup} ${ldscript} DISABLE_MSC ${ARGN})
target_sources(${name} PRIVATE ${STM32F3_STDPERIPH_SRC} ${STM32F3_SRC})
target_compile_options(${name} PRIVATE ${CORTEX_M4F_COMMON_OPTIONS} ${CORTEX_M4F_COMPILE_OPTIONS})
target_include_directories(${name} PRIVATE ${STM32F3_INCLUDE_DIRS})
target_compile_definitions(${name} PRIVATE ${STM32F3_DEFINITIONS})
target_link_options(${name} PRIVATE ${CORTEX_M4F_COMMON_OPTIONS} ${CORTEX_M4F_LINK_OPTIONS})
get_property(features TARGET ${name} PROPERTY FEATURES)
if(VCP IN_LIST features)
target_include_directories(${name} PRIVATE ${STM32F3_USB_INCLUDE_DIRS})
target_sources(${name} PRIVATE ${STM32F3_USB_SRC} ${STM32F3_VCP_SRC})
endif()
endfunction()
function(target_stm32f303 name)
target_stm32f3xx(${name} startup_stm32f30x_md_gcc.S stm32_flash_f303_256k.ld ${ARGN})
target_compile_definitions(${name} PRIVATE ${STM32F303_DEFINITIONS})
setup_firmware_target(${name})
endfunction()

55
cmake/stm32f4-usb.cmake

@ -0,0 +1,55 @@
set(STM32_USBOTG_DIR "${INAV_LIB_DIR}/main/STM32_USB_OTG_Driver")
set(STM32_USBCORE_DIR "${INAV_LIB_DIR}/main/STM32_USB_Device_Library/Core")
set(STM32_USBCDC_DIR "${INAV_LIB_DIR}/main/STM32_USB_Device_Library/Class/cdc")
set(STM32_USBHID_DIR "${INAV_LIB_DIR}/main/STM32_USB_Device_Library/Class/hid")
set(STM32_USBWRAPPER_DIR "${INAV_LIB_DIR}/main/STM32_USB_Device_Library/Class/hid_cdc_wrapper")
set(STM32_USBMSC_DIR "${INAV_LIB_DIR}/main/STM32_USB_Device_Library/Class/msc")
set(STM32F4_USB_INCLUDE_DIRS
"${STM32_USBOTG_DIR}/inc"
"${STM32_USBCORE_DIR}/inc"
"${STM32_USBCDC_DIR}/inc"
"${STM32_USBHID_DIR}/inc"
"${STM32_USBWRAPPER_DIR}/inc"
"${STM32_USBMSC_DIR}/inc"
)
set(STM32_USBOTG_SRC
usb_core.c
usb_dcd.c
usb_dcd_int.c
)
list(TRANSFORM STM32_USBOTG_SRC PREPEND "${STM32_USBOTG_DIR}/src/")
set(STM32_USBCORE_SRC
usbd_core.c
usbd_ioreq.c
usbd_req.c
)
list(TRANSFORM STM32_USBCORE_SRC PREPEND "${STM32_USBCORE_DIR}/src/")
set(STM32_USBCDC_SRC
"${STM32_USBCDC_DIR}/src/usbd_cdc_core.c"
)
set(STM32_USBHID_SRC
"${STM32_USBHID_DIR}/src/usbd_hid_core.c"
)
set(STM32_USBWRAPPER_SRC
"${STM32_USBWRAPPER_DIR}/src/usbd_hid_cdc_wrapper.c"
)
set(STM32F4_USBMSC_SRC
usbd_msc_bot.c
usbd_msc_core.c
usbd_msc_data.c
usbd_msc_scsi.c
)
list(TRANSFORM STM32F4_USBMSC_SRC PREPEND "${STM32_USBMSC_DIR}/src/")
list(APPEND STM32F4_USB_SRC ${STM32_USBOTG_SRC})
list(APPEND STM32F4_USB_SRC ${STM32_USBCORE_SRC})
list(APPEND STM32F4_USB_SRC ${STM32_USBCDC_SRC})
list(APPEND STM32F4_USB_SRC ${STM32_USBHID_SRC})
list(APPEND STM32F4_USB_SRC ${STM32_USBWRAPPER_SRC})

35
cmake/stm32f4.cmake

@ -1,3 +1,6 @@
include(cortex-m4f)
include(stm32f4-usb)
set(STM32F4_STDPERIPH_DIR "${INAV_LIB_DIR}/main/STM32F4/Drivers/STM32F4xx_StdPeriph_Driver")
set(STM32F4_CMSIS_DEVICE_DIR "${INAV_LIB_DIR}/main/STM32F4/Drivers/CMSIS/Device/ST/STM32F4xx")
set(STM32F4_CMSIS_DRIVERS_DIR "${INAV_LIB_DIR}/main/STM32F4/Drivers/CMSIS")
@ -69,44 +72,26 @@ set(STM32F4_INCLUDE_DIRS
)
set(STM32F4_DEFINITIONS
${CORTEX_M4F_DEFINITIONS}
STM32F4
USE_STDPERIPH_DRIVER
ARM_MATH_MATRIX_CHECK
ARM_MATH_ROUNDING
__FPU_PRESENT=1
UNALIGNED_SUPPORT_DISABLE
ARM_MATH_CM4
)
set(STM32F4_COMMON_OPTIONS
-mthumb
-mcpu=cortex-m4
-march=armv7e-m
-mfloat-abi=hard
-mfpu=fpv4-sp-d16
-fsingle-precision-constant
)
set(STM32F4_COMPILE_OPTIONS
)
set(SETM32F4_LINK_OPTIONS
)
function(target_stm32f4xx name startup ldscript)
target_stm32(${name} ${startup} ${ldscript} ${ARGN})
target_sources(${name} PRIVATE ${STM32F4_SRC})
target_compile_options(${name} PRIVATE ${STM32F4_COMMON_OPTIONS} ${STM32F4_COMPILE_OPTIONS})
target_include_directories(${name} PRIVATE ${STM32_STDPERIPH_USB_INCLUDE_DIRS} ${STM32F4_INCLUDE_DIRS})
target_compile_options(${name} PRIVATE ${CORTEX_M4F_COMMON_OPTIONS} ${CORTEX_M4F_COMPILE_OPTIONS})
target_include_directories(${name} PRIVATE ${STM32F4_INCLUDE_DIRS})
target_compile_definitions(${name} PRIVATE ${STM32F4_DEFINITIONS})
target_link_options(${name} PRIVATE ${STM32F4_COMMON_OPTIONS} ${STM32F4_LINK_OPTIONS})
target_link_options(${name} PRIVATE ${CORTEX_M4F_COMMON_OPTIONS} ${CORTEX_M4F_LINK_OPTIONS})
get_property(features TARGET ${name} PROPERTY FEATURES)
if(VCP IN_LIST features)
target_sources(${name} PRIVATE ${STM32_STDPERIPH_USB_SRC} ${STM32F4_VCP_SRC})
target_include_directories(${name} PRIVATE ${STM32F4_USB_INCLUDE_DIRS})
target_sources(${name} PRIVATE ${STM32F4_USB_SRC} ${STM32F4_VCP_SRC})
endif()
if(MSC IN_LIST features)
target_sources(${name} PRIVATE ${STM32F4_MSC_SRC})
target_sources(${name} PRIVATE ${STM32F4_USBMSC_SRC} ${STM32F4_MSC_SRC})
endif()
endfunction()

2
src/main/target/AIRHEROF3/CMakeLists.txt

@ -0,0 +1,2 @@
target_stm32f303(AIRHEROF3 HSE_MHZ 12)
target_stm32f303(AIRHEROF3_QUAD HSE_MHZ 12)

1
src/main/target/BETAFLIGHTF3/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(BETAFLIGHTF3 DEFINITIONS "SPRACINGF3")

1
src/main/target/FALCORE/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(FALCORE HSE_MHZ 12)

1
src/main/target/FRSKYF3/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(FRSKYF3)

2
src/main/target/FURYF3/CMakeLists.txt

@ -0,0 +1,2 @@
target_stm32f303(FURYF3)
target_stm32f303(FURYF3_SPIFLASH)

1
src/main/target/KFC32F3_INAV/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(KFC32F3_INAV)

1
src/main/target/LUX_RACE/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(LUX_RACE)

1
src/main/target/MOTOLAB/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(MOTOLAB)

1
src/main/target/OMNIBUS/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(OMNIBUS)

1
src/main/target/PIKOBLX/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(PIKOBLX)

1
src/main/target/RCEXPLORERF3/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(RCEXPLORERF3)

1
src/main/target/RMDO/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(RMDO DEFINITIONS "SPRACINGF3")

1
src/main/target/SPARKY/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(SPARKY)

1
src/main/target/SPRACINGF3/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(SPRACINGF3)

2
src/main/target/SPRACINGF3EVO/CMakeLists.txt

@ -0,0 +1,2 @@
target_stm32f303(SPRACINGF3EVO)
target_stm32f303(SPRACINGF3EVO_1SS)

1
src/main/target/SPRACINGF3MINI/CMakeLists.txt

@ -0,0 +1 @@
target_stm32f303(SPRACINGF3MINI)
Loading…
Cancel
Save