|
|
@ -1,6 +1,9 @@ |
|
|
|
include(arm-none-eabi) |
|
|
|
include(stm32f4) |
|
|
|
include(stm32-usb) |
|
|
|
|
|
|
|
include(CMakeParseArguments) |
|
|
|
|
|
|
|
set(CMSIS_DIR "${INAV_LIB_DIR}/main/CMSIS") |
|
|
|
set(CMSIS_INCLUDE_DIR "${CMSIS_DIR}/Core/Include") |
|
|
|
set(CMSIS_DSP_DIR "${INAV_LIB_DIR}/main/CMSIS/DSP") |
|
|
@ -27,6 +30,21 @@ set(STM32_VCP_SRC |
|
|
|
) |
|
|
|
main_sources(STM32_VCP_SRC) |
|
|
|
|
|
|
|
set(STM32_SDCARD_SRC |
|
|
|
drivers/sdcard/sdcard.c |
|
|
|
drivers/sdcard/sdcard_spi.c |
|
|
|
drivers/sdcard/sdcard_sdio.c |
|
|
|
drivers/sdcard/sdcard_standard.c |
|
|
|
) |
|
|
|
main_sources(STM32_SDCARD_SRC) |
|
|
|
|
|
|
|
# XXX: This code is not STM32 specific |
|
|
|
set(STM32_ASYNCFATFS_SRC |
|
|
|
io/asyncfatfs/asyncfatfs.c |
|
|
|
io/asyncfatfs/fat_standard.c |
|
|
|
) |
|
|
|
main_sources(STM32_ASYNCFATFS_SRC) |
|
|
|
|
|
|
|
set(STM32_MSC_SRC |
|
|
|
msc/usbd_msc_desc.c |
|
|
|
msc/usbd_storage.c |
|
|
@ -40,65 +58,25 @@ set(STM32_MSC_FLASH_SRC |
|
|
|
) |
|
|
|
main_sources(STM32_MSC_FLASH_SRC) |
|
|
|
|
|
|
|
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") |
|
|
|
set(STM32F4_VCP_DIR "${INAV_MAIN_SRC_DIR}/vcpf4") |
|
|
|
|
|
|
|
set(STM32F4_STDPERIPH_SRC_EXCLUDES |
|
|
|
stm32f4xx_can.c |
|
|
|
stm32f4xx_cec.c |
|
|
|
stm32f4xx_crc.c |
|
|
|
stm32f4xx_cryp.c |
|
|
|
stm32f4xx_cryp_aes.c |
|
|
|
stm32f4xx_cryp_des.c |
|
|
|
stm32f4xx_cryp_tdes.c |
|
|
|
stm32f4xx_dbgmcu.c |
|
|
|
stm32f4xx_dsi.c |
|
|
|
stm32f4xx_flash_ramfunc.c |
|
|
|
stm32f4xx_fmpi2c.c |
|
|
|
stm32f4xx_fmc.c |
|
|
|
stm32f4xx_hash.c |
|
|
|
stm32f4xx_hash_md5.c |
|
|
|
stm32f4xx_hash_sha1.c |
|
|
|
stm32f4xx_lptim.c |
|
|
|
stm32f4xx_qspi.c |
|
|
|
stm32f4xx_sai.c |
|
|
|
stm32f4xx_spdifrx.c |
|
|
|
set(STM32_MSC_SDCARD_SRC |
|
|
|
msc/usbd_storage_sd_spi.c |
|
|
|
) |
|
|
|
main_sources(STM32_MSC_SDCARD_SRC) |
|
|
|
|
|
|
|
set(STM32F4_STDPERIPH_SRC_DIR "${STM32F4_STDPERIPH_DIR}/Src") |
|
|
|
glob_except(STM32F4_STDPERIPH_SRC "${STM32F4_STDPERIPH_SRC_DIR}/*.c" STM32F4_STDPERIPH_SRC_EXCLUDES) |
|
|
|
|
|
|
|
set(STM32F4_VCP_SRC |
|
|
|
stm32f4xx_it.c |
|
|
|
usb_bsp.c |
|
|
|
usbd_desc.c |
|
|
|
usbd_usr.c |
|
|
|
usbd_cdc_vcp.c |
|
|
|
) |
|
|
|
list(TRANSFORM STM32F4_VCP_SRC PREPEND "${STM32F4_VCP_DIR}/") |
|
|
|
|
|
|
|
set(STM32F4_MSC_SRC |
|
|
|
drivers/usb_msc_f4xx.c |
|
|
|
) |
|
|
|
main_sources(STM32F4_MSC_SRC) |
|
|
|
|
|
|
|
set(STM32F4_INCLUDE_DIRS |
|
|
|
set(STM32_INCLUDE_DIRS |
|
|
|
"${CMSIS_INCLUDE_DIR}" |
|
|
|
"${CMSIS_DSP_INCLUDE_DIR}" |
|
|
|
"${STM32F4_STDPERIPH_DIR}/inc" |
|
|
|
"${STM32F4_CMSIS_DEVICE_DIR}" |
|
|
|
"${STM32F4_CMSIS_DRIVERS_DIR}" |
|
|
|
"${STM32F4_VCP_DIR}" |
|
|
|
"${INAV_MAIN_SRC_DIR}/target" |
|
|
|
) |
|
|
|
|
|
|
|
set(STM32_INCLUDE_DIRS |
|
|
|
"${INAV_MAIN_SRC_DIR}/target" |
|
|
|
set(STM32_DEFINITIONS |
|
|
|
) |
|
|
|
|
|
|
|
set(STM32_DEFAULT_HSE_MHZ 8) |
|
|
|
|
|
|
|
set(STM32_LINKER_DIR "${INAV_MAIN_SRC_DIR}/target/link") |
|
|
|
|
|
|
|
|
|
|
|
#if(SEMIHOSTING) |
|
|
|
# set(SEMIHOSTING_DEFINITIONS "SEMIHOSTING") |
|
|
|
# set(SEMIHOSTING_LDFLAGS |
|
|
@ -135,57 +113,6 @@ set(STM32_LINK_OPTIONS |
|
|
|
-Wl,--print-memory-usage |
|
|
|
) |
|
|
|
|
|
|
|
set(STM32F4_SRC |
|
|
|
target/system_stm32f4xx.c |
|
|
|
drivers/accgyro/accgyro.c |
|
|
|
drivers/accgyro/accgyro_mpu.c |
|
|
|
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 |
|
|
|
drivers/timer_impl_stdperiph.c |
|
|
|
drivers/timer_stm32f4xx.c |
|
|
|
drivers/uart_inverter.c |
|
|
|
drivers/dma_stm32f4xx.c |
|
|
|
drivers/sdcard/sdmmc_sdio_f4xx.c |
|
|
|
) |
|
|
|
|
|
|
|
main_sources(STM32F4_SRC) |
|
|
|
|
|
|
|
set(STM32F4_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 |
|
|
|
) |
|
|
|
|
|
|
|
set(STM32F411_STDPERIPH_SRC_EXCLUDES "stm32f4xx_fsmc.c") |
|
|
|
|
|
|
|
set(STM32F411_COMPILE_DEFINITIONS |
|
|
|
FLASH_SIZE=512 |
|
|
|
) |
|
|
|
|
|
|
|
macro(get_stm32_target_features) # out-var dir |
|
|
|
file(READ "${ARGV1}/target.h" _contents) |
|
|
|
string(REGEX MATCH "#define[\t ]+USE_VCP" HAS_VCP ${_contents}) |
|
|
@ -196,30 +123,63 @@ macro(get_stm32_target_features) # out-var dir |
|
|
|
if(HAS_FLASHFS) |
|
|
|
list(APPEND ${ARGV0} FLASHFS) |
|
|
|
endif() |
|
|
|
if (HAS_FLASHFS) # || SDCARD |
|
|
|
string(REGEX MATCH "define[\t ]+USE_SDCARD" HAS_SDCARD ${_contents}) |
|
|
|
if (HAS_SDCARD) |
|
|
|
list(APPEND ${ARGV0} SDCARD) |
|
|
|
endif() |
|
|
|
if(HAS_FLASHFS OR HAS_SDCARD) |
|
|
|
list(APPEND ${ARGV0} MSC) |
|
|
|
endif() |
|
|
|
endmacro() |
|
|
|
|
|
|
|
function(target_stm32 name) |
|
|
|
function(target_stm32 name startup ldscript) |
|
|
|
set(target_definitions) |
|
|
|
# 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 |
|
|
|
) |
|
|
|
if (PARSED_ARGS_HSE_MHZ) |
|
|
|
set(hse_mhz ${PARSED_ARGS_HSE_MHZ}) |
|
|
|
else() |
|
|
|
set(hse_mhz ${STM32_DEFAULT_HSE_MHZ}) |
|
|
|
endif() |
|
|
|
|
|
|
|
# Main .elf target |
|
|
|
add_executable(${name} ${COMMON_SRC} ${CMSIS_DSP_SRC}) |
|
|
|
file(GLOB target_c_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.c") |
|
|
|
file(GLOB target_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.h") |
|
|
|
target_sources(${name} PRIVATE ${target_c_sources} ${target_h_sources}) |
|
|
|
target_sources(${name} PRIVATE "${STM32_STARTUP_DIR}/${startup}") |
|
|
|
target_link_options(${name} PRIVATE "-T${STM32_LINKER_DIR}/${ldscript}") |
|
|
|
target_include_directories(${name} PRIVATE . ${STM32_INCLUDE_DIRS}) |
|
|
|
target_link_libraries(${name} PRIVATE ${STM32_LINK_LIBRARIES}) |
|
|
|
target_link_options(${name} PRIVATE ${STM32_LINK_OPTIONS}) |
|
|
|
|
|
|
|
set(target_definitions ${STM32_DEFINITIONS}) |
|
|
|
math(EXPR hse_value "${hse_mhz} * 1000000") |
|
|
|
list(APPEND target_definitions "HSE_VALUE=${hse_value}") |
|
|
|
target_compile_definitions(${name} PRIVATE ${target_definitions}) |
|
|
|
|
|
|
|
get_stm32_target_features(features "${CMAKE_CURRENT_SOURCE_DIR}") |
|
|
|
set_property(TARGET ${name} PROPERTY FEATURES ${features}) |
|
|
|
if(VCP IN_LIST features) |
|
|
|
target_sources(${name} PRIVATE ${STM32_VCP_SRC}) |
|
|
|
endif() |
|
|
|
if(SDCARD IN_LIST features) |
|
|
|
target_sources(${name} PRIVATE ${STM32_SDCARD_SRC} ${STM32_ASYNCFATFS_SRC}) |
|
|
|
endif() |
|
|
|
if(MSC IN_LIST features) |
|
|
|
target_sources(${name} PRIVATE ${STM32_MSC_SRC}) |
|
|
|
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}) |
|
|
|
endif() |
|
|
|
endif() |
|
|
|
# Generate .hex |
|
|
|
set(hexdir "${CMAKE_BINARY_DIR}/hex") |
|
|
@ -232,32 +192,8 @@ function(target_stm32 name) |
|
|
|
add_custom_target(${clean_target} |
|
|
|
COMMAND cmake -E rm -r "${CMAKE_CURRENT_BINARY_DIR}" |
|
|
|
COMMENT "Removeng intermediate files for ${name}") |
|
|
|
set_property(TARGET ${clean_target} PROPERTY TARGET_MESSAGES OFF) |
|
|
|
endfunction() |
|
|
|
|
|
|
|
function(target_stm32f4xx name) |
|
|
|
target_stm32(${name}) |
|
|
|
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_definitions(${name} PRIVATE ${STM32F4_DEFINITIONS}) |
|
|
|
target_link_options(${name} PRIVATE ${STM32F4_COMMON_OPTIONS} ${STM32F4_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}) |
|
|
|
endif() |
|
|
|
if(MSC IN_LIST features) |
|
|
|
target_sources(${name} PRIVATE ${STM32F4_MSC_SRC}) |
|
|
|
endif() |
|
|
|
endfunction() |
|
|
|
|
|
|
|
function(target_stm32f411 name) |
|
|
|
target_stm32f4xx(${name}) |
|
|
|
set(STM32F411_STDPERIPH_SRC ${STM32F4_STDPERIPH_SRC}) |
|
|
|
exclude_basenames(STM32F411_STDPERIPH_SRC STM32F411_STDPERIPH_SRC_EXCLUDES) |
|
|
|
target_sources(${name} PRIVATE "${STM32_STARTUP_DIR}/startup_stm32f411xe.s" ${STM32F411_STDPERIPH_SRC}) |
|
|
|
target_link_options(${name} PRIVATE "-T${STM32_LINKER_DIR}/stm32_flash_f411.ld") |
|
|
|
target_compile_definitions(${name} PRIVATE STM32F411xE ${STM32F411_COMPILE_DEFINITIONS}) |
|
|
|
setup_firmware_target(${name}) |
|
|
|
set_property(TARGET ${clean_target} PROPERTY |
|
|
|
TARGET_MESSAGES OFF |
|
|
|
EXCLUDE_FROM_ALL 1 |
|
|
|
EXCLUDE_FROM_DEFAULT_BUILD 1) |
|
|
|
endfunction() |