|
| 1 | +include_guard() |
| 2 | + |
| 3 | +if (NOT BOARD) |
| 4 | + message(FATAL_ERROR "BOARD not specified") |
| 5 | +endif () |
| 6 | + |
| 7 | +set(ST_FAMILY g0) |
| 8 | +set(ST_PREFIX stm32${ST_FAMILY}xx) |
| 9 | + |
| 10 | +set(ST_HAL_DRIVER ${TOP}/hw/mcu/st/stm32${ST_FAMILY}xx_hal_driver) |
| 11 | +set(ST_CMSIS ${TOP}/hw/mcu/st/cmsis_device_${ST_FAMILY}) |
| 12 | +set(CMSIS_5 ${TOP}/lib/CMSIS_5) |
| 13 | + |
| 14 | +# enable LTO |
| 15 | +#set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) |
| 16 | + |
| 17 | +# toolchain set up |
| 18 | +set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus CACHE INTERNAL "System Processor") |
| 19 | +set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake) |
| 20 | + |
| 21 | +set(FAMILY_MCUS STM32G0 CACHE INTERNAL "") |
| 22 | + |
| 23 | +# include board specific |
| 24 | +include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) |
| 25 | + |
| 26 | + |
| 27 | +#------------------------------------ |
| 28 | +# BOARD_TARGET |
| 29 | +#------------------------------------ |
| 30 | +# only need to be built ONCE for all examples |
| 31 | +set(BOARD_TARGET board_${BOARD}) |
| 32 | +if (NOT TARGET ${BOARD_TARGET}) |
| 33 | + add_library(${BOARD_TARGET} STATIC |
| 34 | + ${ST_CMSIS}/Source/Templates/system_${ST_PREFIX}.c |
| 35 | + ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal.c |
| 36 | + ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_cortex.c |
| 37 | + ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_pwr_ex.c |
| 38 | + ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc.c |
| 39 | + ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc_ex.c |
| 40 | + ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_gpio.c |
| 41 | + ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart.c |
| 42 | + ${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart_ex.c |
| 43 | + ) |
| 44 | + target_include_directories(${BOARD_TARGET} PUBLIC |
| 45 | + ${CMAKE_CURRENT_LIST_DIR} |
| 46 | + ${CMSIS_5}/CMSIS/Core/Include |
| 47 | + ${ST_CMSIS}/Include |
| 48 | + ${ST_HAL_DRIVER}/Inc |
| 49 | + ) |
| 50 | + target_compile_options(${BOARD_TARGET} PUBLIC |
| 51 | + ) |
| 52 | + target_compile_definitions(${BOARD_TARGET} PUBLIC |
| 53 | + ) |
| 54 | + update_board(${BOARD_TARGET}) |
| 55 | + |
| 56 | + target_sources(${BOARD_TARGET} PUBLIC |
| 57 | + ${STARTUP_FILE_${TOOLCHAIN}} |
| 58 | + ) |
| 59 | + |
| 60 | + if (TOOLCHAIN STREQUAL "gcc") |
| 61 | + target_link_options(${BOARD_TARGET} PUBLIC |
| 62 | + "LINKER:--script=${LD_FILE_gcc}" |
| 63 | + -nostartfiles |
| 64 | + # nanolib |
| 65 | + --specs=nosys.specs |
| 66 | + --specs=nano.specs |
| 67 | + ) |
| 68 | + else () |
| 69 | + # TODO support IAR |
| 70 | + target_link_options(${BOARD_TARGET} PUBLIC |
| 71 | + "LINKER:--config=${LD_FILE_iar}" |
| 72 | + ) |
| 73 | + endif () |
| 74 | +endif () # BOARD_TARGET |
| 75 | + |
| 76 | + |
| 77 | +#------------------------------------ |
| 78 | +# Functions |
| 79 | +#------------------------------------ |
| 80 | +function(family_configure_example TARGET) |
| 81 | + family_configure_common(${TARGET}) |
| 82 | + |
| 83 | + #---------- Port Specific ---------- |
| 84 | + # These files are built for each example since it depends on example's tusb_config.h |
| 85 | + target_sources(${TARGET} PUBLIC |
| 86 | + # TinyUSB Port |
| 87 | + ${TOP}/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c |
| 88 | + # BSP |
| 89 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c |
| 90 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c |
| 91 | + ) |
| 92 | + target_include_directories(${TARGET} PUBLIC |
| 93 | + # family, hw, board |
| 94 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR} |
| 95 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../ |
| 96 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD} |
| 97 | + ) |
| 98 | + |
| 99 | + #---------- TinyUSB ---------- |
| 100 | + # tinyusb target is built for each example since it depends on example's tusb_config.h |
| 101 | + set(TINYUSB_TARGET_PREFIX ${TARGET}-) |
| 102 | + add_library(${TARGET}-tinyusb_config INTERFACE) |
| 103 | + |
| 104 | + target_include_directories(${TARGET}-tinyusb_config INTERFACE |
| 105 | + ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 106 | + ) |
| 107 | + target_compile_definitions(${TARGET}-tinyusb_config INTERFACE |
| 108 | + CFG_TUSB_MCU=OPT_MCU_STM32G0 |
| 109 | + ) |
| 110 | + |
| 111 | + # tinyusb's CMakeList.txt |
| 112 | + add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb) |
| 113 | + |
| 114 | + # Link dependencies |
| 115 | + target_link_libraries(${TARGET} PUBLIC ${BOARD_TARGET} ${TARGET}-tinyusb) |
| 116 | + |
| 117 | + # group target (not yet supported by clion) |
| 118 | + set_target_properties(${TARGET}-tinyusb ${TARGET}-tinyusb_config |
| 119 | + PROPERTIES FOLDER ${TARGET}_sub |
| 120 | + ) |
| 121 | + |
| 122 | + #---------- Flash ---------- |
| 123 | + family_flash_jlink(${TARGET}) |
| 124 | +endfunction() |
| 125 | + |
| 126 | + |
| 127 | +function(family_configure_device_example TARGET) |
| 128 | + family_configure_example(${TARGET}) |
| 129 | +endfunction() |
| 130 | + |
| 131 | +function(family_configure_host_example TARGET) |
| 132 | + family_configure_example(${TARGET}) |
| 133 | +endfunction() |
| 134 | + |
| 135 | +function(family_configure_dual_usb_example TARGET) |
| 136 | + family_configure_example(${TARGET}) |
| 137 | +endfunction() |
0 commit comments