|
| 1 | +include_guard() |
| 2 | + |
| 3 | +if (NOT BOARD) |
| 4 | + message(FATAL_ERROR "BOARD not specified") |
| 5 | +endif () |
| 6 | + |
| 7 | +set(SDK_DIR ${TOP}/hw/mcu/nxp/mcux-sdk) |
| 8 | +set(CMSIS_DIR ${TOP}/lib/CMSIS_5) |
| 9 | + |
| 10 | +# include board specific |
| 11 | +include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) |
| 12 | + |
| 13 | +# toolchain set up |
| 14 | +set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor") |
| 15 | +set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake) |
| 16 | + |
| 17 | +set(FAMILY_MCUS LPC54 CACHE INTERNAL "") |
| 18 | + |
| 19 | +if (NOT DEFINED PORT) |
| 20 | + set(PORT 0) |
| 21 | +endif() |
| 22 | + |
| 23 | +# Host port will be the other port if available |
| 24 | +set(HOST_PORT $<NOT:${PORT}>) |
| 25 | + |
| 26 | +#------------------------------------ |
| 27 | +# BOARD_TARGET |
| 28 | +#------------------------------------ |
| 29 | +# only need to be built ONCE for all examples |
| 30 | +function(add_board_target BOARD_TARGET) |
| 31 | + if (NOT TARGET ${BOARD_TARGET}) |
| 32 | + add_library(${BOARD_TARGET} STATIC |
| 33 | + # driver |
| 34 | + ${SDK_DIR}/drivers/lpc_gpio/fsl_gpio.c |
| 35 | + ${SDK_DIR}/drivers/common/fsl_common_arm.c |
| 36 | + ${SDK_DIR}/drivers/flexcomm/fsl_flexcomm.c |
| 37 | + ${SDK_DIR}/drivers/flexcomm/fsl_usart.c |
| 38 | + # mcu |
| 39 | + ${SDK_DIR}/devices/${MCU_VARIANT}/system_${MCU_CORE}.c |
| 40 | + ${SDK_DIR}/devices/${MCU_VARIANT}/drivers/fsl_clock.c |
| 41 | + ${SDK_DIR}/devices/${MCU_VARIANT}/drivers/fsl_power.c |
| 42 | + ${SDK_DIR}/devices/${MCU_VARIANT}/drivers/fsl_reset.c |
| 43 | + ) |
| 44 | + |
| 45 | + target_compile_definitions(${BOARD_TARGET} PUBLIC |
| 46 | + CFG_TUSB_MEM_ALIGN=TU_ATTR_ALIGNED\(64\) |
| 47 | + BOARD_TUD_RHPORT=${PORT} |
| 48 | + BOARD_TUH_RHPORT=${HOST_PORT} |
| 49 | + ) |
| 50 | + # Port 0 is Fullspeed, Port 1 is Highspeed. Port1 controller can only access USB_SRAM |
| 51 | + if (PORT EQUAL 1) |
| 52 | + target_compile_definitions(${BOARD_TARGET} PUBLIC |
| 53 | + BOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED |
| 54 | + BOARD_TUH_MAX_SPEED=OPT_MODE_FULL_SPEED |
| 55 | + CFG_TUD_MEM_SECTION=__attribute__\(\(section\(\"m_usb_global\"\)\)\) |
| 56 | + ) |
| 57 | + else () |
| 58 | + target_compile_definitions(${BOARD_TARGET} PUBLIC |
| 59 | + BOARD_TUD_MAX_SPEED=OPT_MODE_FULL_SPEED |
| 60 | + BOARD_TUH_MAX_SPEED=OPT_MODE_HIGH_SPEED |
| 61 | + CFG_TUH_MEM_SECTION=__attribute__\(\(section\(\"m_usb_global\"\)\)\) |
| 62 | + ) |
| 63 | + endif () |
| 64 | + |
| 65 | + target_include_directories(${BOARD_TARGET} PUBLIC |
| 66 | + ${TOP}/lib/sct_neopixel |
| 67 | + # driver |
| 68 | + ${SDK_DIR}/drivers/common |
| 69 | + ${SDK_DIR}/drivers/flexcomm |
| 70 | + ${SDK_DIR}/drivers/lpc_iocon |
| 71 | + ${SDK_DIR}/drivers/lpc_gpio |
| 72 | + ${SDK_DIR}/drivers/lpuart |
| 73 | + ${SDK_DIR}/drivers/sctimer |
| 74 | + # mcu |
| 75 | + ${CMSIS_DIR}/CMSIS/Core/Include |
| 76 | + ${SDK_DIR}/devices/${MCU_VARIANT} |
| 77 | + ${SDK_DIR}/devices/${MCU_VARIANT}/drivers |
| 78 | + ) |
| 79 | + |
| 80 | + update_board(${BOARD_TARGET}) |
| 81 | + |
| 82 | + if (NOT DEFINED LD_FILE_${CMAKE_C_COMPILER_ID}) |
| 83 | + set(LD_FILE_GNU ${SDK_DIR}/devices/${MCU_VARIANT}/gcc/${MCU_CORE}_flash.ld) |
| 84 | + endif () |
| 85 | + |
| 86 | + if (NOT DEFINED STARTUP_FILE_${CMAKE_C_COMPILER_ID}) |
| 87 | + set(STARTUP_FILE_GNU ${SDK_DIR}/devices/${MCU_VARIANT}/gcc/startup_${MCU_CORE}.S) |
| 88 | + endif () |
| 89 | + |
| 90 | + target_sources(${BOARD_TARGET} PUBLIC |
| 91 | + ${STARTUP_FILE_${CMAKE_C_COMPILER_ID}} |
| 92 | + ) |
| 93 | + |
| 94 | + if (CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 95 | + target_link_options(${BOARD_TARGET} PUBLIC |
| 96 | + # linker file |
| 97 | + "LINKER:--script=${LD_FILE_GNU}" |
| 98 | + # nanolib |
| 99 | + --specs=nosys.specs |
| 100 | + --specs=nano.specs |
| 101 | + ) |
| 102 | + elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR") |
| 103 | + target_link_options(${BOARD_TARGET} PUBLIC |
| 104 | + "LINKER:--config=${LD_FILE_IAR}" |
| 105 | + ) |
| 106 | + endif () |
| 107 | + endif () |
| 108 | +endfunction() |
| 109 | + |
| 110 | + |
| 111 | +#------------------------------------ |
| 112 | +# Functions |
| 113 | +#------------------------------------ |
| 114 | +function(family_configure_example TARGET RTOS) |
| 115 | + family_configure_common(${TARGET} ${RTOS}) |
| 116 | + |
| 117 | + # Board target |
| 118 | + add_board_target(board_${BOARD}) |
| 119 | + |
| 120 | + #---------- Port Specific ---------- |
| 121 | + # These files are built for each example since it depends on example's tusb_config.h |
| 122 | + target_sources(${TARGET} PUBLIC |
| 123 | + # BSP |
| 124 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c |
| 125 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c |
| 126 | + # external driver |
| 127 | + ${TOP}/lib/sct_neopixel/sct_neopixel.c |
| 128 | + ) |
| 129 | + |
| 130 | + # https://github.com/gsteiert/sct_neopixel/pull/1 |
| 131 | + if (CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 132 | + set_source_files_properties(${TOP}/lib/sct_neopixel/sct_neopixel.c PROPERTIES |
| 133 | + COMPILE_FLAGS "-Wno-unused-parameter") |
| 134 | + endif () |
| 135 | + |
| 136 | + target_include_directories(${TARGET} PUBLIC |
| 137 | + # family, hw, board |
| 138 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR} |
| 139 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../ |
| 140 | + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD} |
| 141 | + ) |
| 142 | + |
| 143 | + # Add TinyUSB target and port source |
| 144 | + family_add_tinyusb(${TARGET} OPT_MCU_LPC54 ${RTOS}) |
| 145 | + target_sources(${TARGET}-tinyusb PUBLIC |
| 146 | + ${TOP}/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c |
| 147 | + ) |
| 148 | + target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD}) |
| 149 | + |
| 150 | + # Link dependencies |
| 151 | + target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb) |
| 152 | + |
| 153 | + # Flashing |
| 154 | + family_flash_jlink(${TARGET}) |
| 155 | + #family_flash_nxplink(${TARGET}) |
| 156 | + #family_flash_pyocd(${TARGET}) |
| 157 | +endfunction() |
0 commit comments