1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-12 19:10:27 +03:00

[BUILD] Build F7 based targets with cmake

This commit is contained in:
Alberto García Hierro 2020-07-10 09:42:02 +01:00
parent 477fcfd52a
commit 65c04ae234
27 changed files with 267 additions and 20 deletions

22
cmake/cortex-m7.cmake Normal file
View file

@ -0,0 +1,22 @@
set(CORTEX_M7_COMMON_OPTIONS
-mthumb
-mcpu=cortex-m7
-mfloat-abi=hard
-mfpu=fpv5-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
)
set(CORTEX_M7_COMPILE_OPTIONS
)
set(CORTEX_M7_LINK_OPTIONS
)
set(CORTEX_M7_DEFINITIONS
__FPU_PRESENT=1
ARM_MATH_CM7
ARM_MATH_MATRIX_CHECK
ARM_MATH_ROUNDING
UNALIGNED_SUPPORT_DISABLE
)

View file

@ -0,0 +1,5 @@
set(STM32_STDPERIPH_SRC
drivers/bus_spi.c
drivers/serial_uart.c
)
main_sources(STM32_STDPERIPH_SRC)

View file

@ -1,6 +1,7 @@
include(arm-none-eabi)
include(stm32f3)
include(stm32f4)
include(stm32f7)
include(CMakeParseArguments)
@ -58,10 +59,15 @@ set(STM32_MSC_FLASH_SRC
)
main_sources(STM32_MSC_FLASH_SRC)
set(STM32_MSC_SDCARD_SRC
set(STM32_MSC_SDCARD_SPI_SRC
msc/usbd_storage_sd_spi.c
)
main_sources(STM32_MSC_SDCARD_SRC)
main_sources(STM32_MSC_SDCARD_SPI_SRC)
set(STM32_MSC_SDCARD_SDIO_SRC
msc/usbd_storage_sdio.c
)
main_sources(STM32_MSC_SDCARD_SDIO_SRC)
set(STM32_INCLUDE_DIRS
"${CMSIS_INCLUDE_DIR}"
@ -76,7 +82,7 @@ set(STM32_DEFAULT_HSE_MHZ 8)
set(STM32_LINKER_DIR "${INAV_MAIN_SRC_DIR}/target/link")
set(STM32_LIBS lnosys)
#if(SEMIHOSTING)
# set(SEMIHOSTING_DEFINITIONS "SEMIHOSTING")
# set(SEMIHOSTING_LDFLAGS
@ -102,6 +108,14 @@ set(STM32_LINK_LIBRARIES
-lc
)
if(SEMIHOSTING)
# TODO: Is -lc needed again here due to library order or can it be deleted?
list(APPEND STM32_LINK_LIBRARIES --specs=rdimon.specs -lc -lrdimon)
list(APPEND STM32_DEFINITIONS SEMIHOSTING)
else()
list(APPEND STM32_LINK_LIBRARIES -lnosys)
endif()
set(STM32_LINK_OPTIONS
-nostartfiles
--specs=nano.specs
@ -113,8 +127,17 @@ set(STM32_LINK_OPTIONS
-Wl,--print-memory-usage
)
macro(get_stm32_target_features) # out-var dir
file(READ "${ARGV1}/target.h" _contents)
macro(get_stm32_target_features output_var dir target_name)
execute_process(COMMAND "${CMAKE_C_COMPILER}" -E -dD -D${ARGV2} "${ARGV1}/target.h"
ERROR_VARIABLE _errors
RESULT_VARIABLE _result
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE _contents)
if(NOT _result EQUAL 0)
message(FATAL_ERROR "error extracting features for stm32 target ${ARGV2}: ${_errors}")
endif()
string(REGEX MATCH "#define[\t ]+USE_VCP" HAS_VCP ${_contents})
if(HAS_VCP)
list(APPEND ${ARGV0} VCP)
@ -126,6 +149,10 @@ macro(get_stm32_target_features) # out-var dir
string(REGEX MATCH "define[\t ]+USE_SDCARD" HAS_SDCARD ${_contents})
if (HAS_SDCARD)
list(APPEND ${ARGV0} SDCARD)
string(REGEX MATCH "define[\t ]+USE_SDCARD_SDIO" HAS_SDIO ${_contents})
if (HAS_SDIO)
list(APPEND ${ARGV0} SDIO)
endif()
endif()
if(HAS_FLASHFS OR HAS_SDCARD)
list(APPEND ${ARGV0} MSC)
@ -168,7 +195,7 @@ function(target_stm32 name startup ldscript)
endif()
target_compile_definitions(${name} PRIVATE ${target_definitions})
get_stm32_target_features(features "${CMAKE_CURRENT_SOURCE_DIR}")
get_stm32_target_features(features "${CMAKE_CURRENT_SOURCE_DIR}" ${name})
set_property(TARGET ${name} PROPERTY FEATURES ${features})
if(VCP IN_LIST features)
target_sources(${name} PRIVATE ${STM32_VCP_SRC})
@ -178,11 +205,16 @@ function(target_stm32 name startup ldscript)
endif()
if(NOT PARSED_ARGS_DISABLE_MSC AND MSC IN_LIST features)
target_sources(${name} PRIVATE ${STM32_MSC_SRC})
target_compile_definitions(${name} PRIVATE USE_USB_MSC)
if (FLASHFS IN_LIST features)
target_sources(${name} PRIVATE ${STM32_MSC_FLASH_SRC})
endif()
if (SDCARD IN_LIST features)
target_sources(${name} PRIVATE ${STM32_MSC_SDCARD_SRC})
if (SDIO IN_LIST features)
target_sources(${name} PRIVATE ${STM32_MSC_SDCARD_SDIO_SRC})
else()
target_sources(${name} PRIVATE ${STM32_MSC_SDCARD_SPI_SRC})
endif()
endif()
endif()
# Generate .hex

View file

@ -1,4 +1,5 @@
include(cortex-m4f)
include(stm32-stdperiph)
include(stm32f3-usb)
set(STM32F3_STDPERIPH_DIR "${INAV_LIB_DIR}/main/STM32F3/Drivers/STM32F30x_StdPeriph_Driver")
@ -61,7 +62,7 @@ set(STM32F303_DEFINITIONS
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_sources(${name} PRIVATE ${STM32_STDPERIPH_SRC} ${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})

View file

@ -1,4 +1,5 @@
include(cortex-m4f)
include(stm32-stdperiph)
include(stm32f4-usb)
set(STM32F4_STDPERIPH_DIR "${INAV_LIB_DIR}/main/STM32F4/Drivers/STM32F4xx_StdPeriph_Driver")
@ -36,7 +37,6 @@ set(STM32F4_SRC
drivers/adc_stm32f4xx.c
drivers/adc_stm32f4xx.c
drivers/bus_i2c_stm32f40x.c
drivers/serial_softserial.c
drivers/serial_uart_stm32f4xx.c
drivers/system_stm32f4xx.c
drivers/timer.c
@ -79,7 +79,7 @@ set(STM32F4_DEFINITIONS
function(target_stm32f4xx name startup ldscript)
target_stm32(${name} ${startup} ${ldscript} ${ARGN})
target_sources(${name} PRIVATE ${STM32F4_SRC})
target_sources(${name} PRIVATE ${STM32_STDPERIPH_SRC} ${STM32F4_SRC})
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})

48
cmake/stm32f7-usb.cmake Normal file
View file

@ -0,0 +1,48 @@
set(STM32F7_USBCORE_DIR "${INAV_LIB_DIR}/main/STM32F7/Middlewares/ST/STM32_USB_Device_Library/Core")
set(STM32F7_USBCORE_SRC
usbd_core.c
usbd_ctlreq.c
usbd_ioreq.c
)
list(TRANSFORM STM32F7_USBCORE_SRC PREPEND "${STM32F7_USBCORE_DIR}/Src/")
set(STM32F7_USBCDC_DIR "${INAV_LIB_DIR}/main/STM32F7/Middlewares/ST/STM32_USB_Device_Library/Class/CDC")
set(STM32F7_USBCDC_SRC
usbd_cdc.c
)
list(TRANSFORM STM32F7_USBCDC_SRC PREPEND "${STM32F7_USBCDC_DIR}/Src/")
set(STM32F7_USBHID_DIR "${INAV_LIB_DIR}/main/STM32F7/Middlewares/ST/STM32_USB_Device_Library/Class/HID")
set(STM32F7_USBHID_SRC
usbd_hid.c
)
list(TRANSFORM STM32F7_USBHID_SRC PREPEND "${STM32F7_USBHID_DIR}/Src/")
set(STM32F7_USBCDCHID_DIR "${INAV_LIB_DIR}/main/STM32F7/Middlewares/ST/STM32_USB_Device_Library/Class/CDC_HID")
set(STM32F7_USBCDCHID_SRC
usbd_cdc_hid.c
)
list(TRANSFORM STM32F7_USBCDCHID_SRC PREPEND "${STM32F7_USBCDCHID_DIR}/Src/")
set(STM32F7_USBMSC_DIR "${INAV_LIB_DIR}/main/STM32F7/Middlewares/ST/STM32_USB_Device_Library/Class/MSC")
set(STM32F7_USBMSC_SRC
usbd_msc.c
usbd_msc_bot.c
usbd_msc_data.c
usbd_msc_scsi.c
)
list(TRANSFORM STM32F7_USBMSC_SRC PREPEND "${STM32F7_USBMSC_DIR}/Src/")
set(STM32F7_USB_INCLUDE_DIRS
"${STM32F7_USBCORE_DIR}/Inc"
"${STM32F7_USBCDC_DIR}/Inc"
"${STM32F7_USBHID_DIR}/Inc"
"${STM32F7_USBCDCHID_DIR}/Inc"
"${STM32F7_USBMSC_DIR}/Inc"
)
list(APPEND STM32F7_USB_SRC ${STM32F7_USBCORE_SRC})
list(APPEND STM32F7_USB_SRC ${STM32F7_USBCDC_SRC})
list(APPEND STM32F7_USB_SRC ${STM32F7_USBHID_SRC})
list(APPEND STM32F7_USB_SRC ${STM32F7_USBCDCHID_SRC})
list(APPEND STM32F7_USB_SRC ${STM32F7_USBMSC_SRC})

121
cmake/stm32f7.cmake Normal file
View file

@ -0,0 +1,121 @@
include(cortex-m7)
include(stm32f7-usb)
set(STM32F7_HAL_DIR "${INAV_LIB_DIR}/main/STM32F7/Drivers/STM32F7xx_HAL_Driver")
set(STM32F7_HAL_SRC
stm32f7xx_hal.c
stm32f7xx_hal_adc.c
stm32f7xx_hal_adc_ex.c
stm32f7xx_hal_cortex.c
stm32f7xx_hal_dac.c
stm32f7xx_hal_dac_ex.c
stm32f7xx_hal_dma.c
stm32f7xx_hal_dma_ex.c
stm32f7xx_hal_flash.c
stm32f7xx_hal_flash_ex.c
stm32f7xx_hal_gpio.c
stm32f7xx_hal_i2c.c
stm32f7xx_hal_i2c_ex.c
stm32f7xx_hal_pcd.c
stm32f7xx_hal_pcd_ex.c
stm32f7xx_hal_pwr.c
stm32f7xx_hal_pwr_ex.c
stm32f7xx_hal_rcc.c
stm32f7xx_hal_rcc_ex.c
stm32f7xx_hal_rtc.c
stm32f7xx_hal_rtc_ex.c
stm32f7xx_hal_spi.c
stm32f7xx_hal_tim.c
stm32f7xx_hal_tim_ex.c
stm32f7xx_hal_uart.c
stm32f7xx_hal_usart.c
stm32f7xx_ll_dma.c
stm32f7xx_ll_dma2d.c
stm32f7xx_ll_gpio.c
stm32f7xx_ll_rcc.c
stm32f7xx_ll_spi.c
stm32f7xx_ll_tim.c
stm32f7xx_ll_usb.c
stm32f7xx_ll_utils.c
)
list(TRANSFORM STM32F7_HAL_SRC PREPEND "${STM32F7_HAL_DIR}/src/")
set(STM32F7_CMSIS_DEVICE_DIR "${INAV_LIB_DIR}/main/STM32F7/Drivers/CMSIS/Device/ST/STM32F7xx")
set(STM32F7_VCP_DIR "${INAV_MAIN_SRC_DIR}/vcp_hal")
set(STM32F7_VCP_SRC
usbd_desc.c
usbd_conf.c
usbd_cdc_interface.c
)
list(TRANSFORM STM32F7_VCP_SRC PREPEND "${STM32F7_VCP_DIR}/")
set(STM32F7_INCLUDE_DIRS
${STM32F7_HAL_DIR}/inc
${STM32F7_CMSIS_DEVICE_DIR}/Include
)
set(STM32F7_SRC
target/system_stm32f7xx.c
drivers/adc_stm32f7xx.c
drivers/bus_i2c_hal.c
drivers/dma_stm32f7xx.c
drivers/bus_spi_hal.c
drivers/timer.c
drivers/timer_impl_hal.c
drivers/timer_stm32f7xx.c
drivers/system_stm32f7xx.c
drivers/serial_uart_stm32f7xx.c
drivers/serial_uart_hal.c
drivers/sdcard/sdmmc_sdio_f7xx.c
)
main_sources(STM32F7_SRC)
set(STM32F7_MSC_SRC
drivers/usb_msc_f7xx.c
)
main_sources(STM32F7_MSC_SRC)
set(STM32F7_DEFINITIONS
${CORTEX_M7_DEFINITIONS}
USE_HAL_DRIVER
USE_FULL_LL_DRIVER
)
function(target_stm32f7xx name startup ldscript)
target_stm32(${name} ${startup} ${ldscript} ${ARGN})
target_sources(${name} PRIVATE ${STM32F7_HAL_SRC} ${STM32F7_SRC})
target_compile_options(${name} PRIVATE ${CORTEX_M7_COMMON_OPTIONS} ${CORTEX_M7_COMPILE_OPTIONS})
target_include_directories(${name} PRIVATE ${STM32F7_INCLUDE_DIRS})
target_compile_definitions(${name} PRIVATE ${STM32F7_DEFINITIONS})
target_link_options(${name} PRIVATE ${CORTEX_M7_COMMON_OPTIONS} ${CORTEX_M7_LINK_OPTIONS})
get_property(features TARGET ${name} PROPERTY FEATURES)
if(VCP IN_LIST features)
target_include_directories(${name} PRIVATE ${STM32F7_USB_INCLUDE_DIRS} ${STM32F7_VCP_DIR})
target_sources(${name} PRIVATE ${STM32F7_USB_SRC} ${STM32F7_VCP_SRC})
endif()
if(MSC IN_LIST features)
target_sources(${name} PRIVATE ${STM32F7_USBMSC_SRC} ${STM32F7_MSC_SRC})
endif()
endfunction()
macro(define_target_stm32f7 suffix flash_size)
function(target_stm32f7${suffix} name)
target_stm32f7xx(${name} startup_stm32f7${suffix}xx.s stm32_flash_f7${suffix}.ld ${ARGN})
set(definitions
STM32F7
STM32F7${suffix}xx
FLASH_SIZE=${flash_size}
)
target_compile_definitions(${name} PRIVATE ${definitions})
setup_firmware_target(${name})
endfunction()
endmacro()
define_target_stm32f7("22" 512)
define_target_stm32f7("45" 2048)
define_target_stm32f7("46" 2048)
define_target_stm32f7("65" 2048)

View file

@ -83,11 +83,5 @@ Data rate 496Hz 35806 bytes/s 358100 baud
```
## Developer Notes
Providing MSC for a target requires that the `.mk` file includes in `FEATURES` the key `MSC` and at least one of `ONBOARDFLASH` and /or `SDCARD`.
For F4 and F7 targets, `USE_USB_MSC` is set unconditionally in `common.h`; if your target does not support blackbox logging to either SD card or internal flash, you should over-ride this in `target.h`
```
#ifdef USE_USB_MSC
# undef USE_USB_MSC
#endif
```
Providing MSC is automatically enabled for all F4 and up a targets that support
`ONBOARDFLASH` and /or `SDCARD`.

View file

@ -95,7 +95,6 @@ set(COMMON_SRC
drivers/bus_busdev_i2c.c
drivers/bus_busdev_spi.c
drivers/bus_i2c_soft.c
drivers/bus_spi.c
drivers/compass/compass.h
drivers/compass/compass_ak8963.c
@ -133,6 +132,7 @@ set(COMMON_SRC
drivers/light_ws2811strip.c
drivers/lights_io.c
drivers/max7456.c
drivers/serial_softserial.c
drivers/opflow/opflow_fake.c
drivers/opflow/opflow_virtual.c
@ -160,7 +160,6 @@ set(COMMON_SRC
drivers/rx_spi.c
drivers/rx_xn297.c
drivers/serial.c
drivers/serial_uart.c
drivers/sound_beeper.c
drivers/stack_check.c
drivers/system.c

View file

@ -0,0 +1,2 @@
target_stm32f722(AIRBOTF7)
target_stm32f722(OMNIBUSF7NANOV7)

View file

@ -0,0 +1 @@
target_stm32f722(ALIENFLIGHTNGF7)

View file

@ -0,0 +1,2 @@
target_stm32f745(ANYFCF7)
target_stm32f745(ANYFCF7_EXTERNAL_BARO)

View file

@ -0,0 +1 @@
target_stm32f722(ASGARD32F7)

View file

@ -0,0 +1 @@
target_stm32f722(DALRCF722DUAL)

View file

@ -0,0 +1 @@
target_stm32f722(FOXEERF722DUAL)

View file

@ -0,0 +1 @@
target_stm32f722(IFLIGHTF7_TWING)

View file

@ -0,0 +1,3 @@
target_stm32f745(KAKUTEF7)
target_stm32f745(KAKUTEF7HDV)
target_stm32f745(KAKUTEF7MINI)

View file

@ -0,0 +1 @@
target_stm32f722(MAMBAF722)

View file

@ -0,0 +1,2 @@
target_stm32f722(MATEKF722)
target_stm32f722(MATEKF722_HEXSERVO)

View file

@ -0,0 +1 @@
target_stm32f722(MATEKF722PX)

View file

@ -0,0 +1,2 @@
target_stm32f722(MATEKF722SE)
target_stm32f722(MATEKF722MINI)

View file

@ -0,0 +1 @@
target_stm32f765(MATEKF765)

View file

@ -0,0 +1,2 @@
target_stm32f745(OMNIBUSF7)
target_stm32f745(OMNIBUSF7V2)

View file

@ -0,0 +1 @@
target_stm32f722(OMNIBUSF7NXT)

View file

@ -0,0 +1 @@
target_stm32f722(SPRACINGF7DUAL)

View file

@ -0,0 +1 @@
target_stm32f722(YUPIF7)

View file

@ -0,0 +1 @@
target_stm32f722(ZEEZF7)