| 
									
										
										
										
											2023-05-23 21:45:00 +07:00
										 |  |  | include_guard()
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | if (NOT BOARD)
 | 
					
						
							|  |  |  |   message(FATAL_ERROR "BOARD not specified")
 | 
					
						
							|  |  |  | endif ()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set(NRFX_DIR ${TOP}/hw/mcu/nordic/nrfx)
 | 
					
						
							|  |  |  | set(CMSIS_DIR ${TOP}/lib/CMSIS_5)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # include board specific
 | 
					
						
							|  |  |  | include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
 | 
					
						
							| 
									
										
										
										
											2023-05-15 16:51:06 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # toolchain set up
 | 
					
						
							|  |  |  | if (MCU_VARIANT STREQUAL "nrf5340_application")
 | 
					
						
							|  |  |  |   set(CMAKE_SYSTEM_PROCESSOR cortex-m33 CACHE INTERNAL "System Processor")
 | 
					
						
							|  |  |  |   set(JLINK_DEVICE nrf5340_xxaa_app)
 | 
					
						
							|  |  |  | else ()
 | 
					
						
							|  |  |  |   set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
 | 
					
						
							|  |  |  |   set(JLINK_DEVICE ${MCU_VARIANT}_xxaa)
 | 
					
						
							|  |  |  | endif ()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-19 14:46:39 +07:00
										 |  |  | set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
 | 
					
						
							| 
									
										
										
										
											2023-05-15 16:51:06 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | set(FAMILY_MCUS NRF5X CACHE INTERNAL "")
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:26:16 +07:00
										 |  |  | # enable LTO if supported
 | 
					
						
							|  |  |  | include(CheckIPOSupported)
 | 
					
						
							|  |  |  | check_ipo_supported(RESULT IPO_SUPPORTED)
 | 
					
						
							|  |  |  | if (IPO_SUPPORTED)
 | 
					
						
							|  |  |  |   set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
 | 
					
						
							|  |  |  | endif ()
 | 
					
						
							| 
									
										
										
										
											2023-05-19 14:46:39 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | #------------------------------------
 | 
					
						
							|  |  |  | # BOARD_TARGET
 | 
					
						
							|  |  |  | #------------------------------------
 | 
					
						
							|  |  |  | # only need to be built ONCE for all examples
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:26:16 +07:00
										 |  |  | function(add_board_target BOARD_TARGET)
 | 
					
						
							|  |  |  |   if (NOT TARGET ${BOARD_TARGET})
 | 
					
						
							|  |  |  |     add_library(${BOARD_TARGET} STATIC | 
					
						
							|  |  |  |       # driver
 | 
					
						
							|  |  |  |       ${NRFX_DIR}/drivers/src/nrfx_power.c
 | 
					
						
							|  |  |  |       ${NRFX_DIR}/drivers/src/nrfx_uarte.c
 | 
					
						
							|  |  |  |       # mcu
 | 
					
						
							|  |  |  |       ${NRFX_DIR}/mdk/system_${MCU_VARIANT}.c
 | 
					
						
							|  |  |  |       )
 | 
					
						
							|  |  |  |     target_compile_definitions(${BOARD_TARGET} PUBLIC | 
					
						
							|  |  |  |       CONFIG_GPIO_AS_PINRESET
 | 
					
						
							|  |  |  |       )
 | 
					
						
							|  |  |  |     target_include_directories(${BOARD_TARGET} PUBLIC | 
					
						
							|  |  |  |       ${CMAKE_CURRENT_FUNCTION_LIST_DIR}
 | 
					
						
							|  |  |  |       ${NRFX_DIR}
 | 
					
						
							|  |  |  |       ${NRFX_DIR}/mdk
 | 
					
						
							|  |  |  |       ${NRFX_DIR}/hal
 | 
					
						
							|  |  |  |       ${NRFX_DIR}/drivers/include
 | 
					
						
							|  |  |  |       ${NRFX_DIR}/drivers/src
 | 
					
						
							|  |  |  |       ${CMSIS_DIR}/CMSIS/Core/Include
 | 
					
						
							|  |  |  |       )
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:26:16 +07:00
										 |  |  |     update_board(${BOARD_TARGET})
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (NOT DEFINED LD_FILE_${CMAKE_C_COMPILER_ID})
 | 
					
						
							|  |  |  |       set(LD_FILE_GNU ${NRFX_DIR}/mdk/${MCU_VARIANT}_xxaa.ld)
 | 
					
						
							|  |  |  |     endif ()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (NOT DEFINED STARTUP_FILE_${CMAKE_C_COMPILER_ID})
 | 
					
						
							|  |  |  |       set(STARTUP_FILE_GNU ${NRFX_DIR}/mdk/gcc_startup_${MCU_VARIANT}.S)
 | 
					
						
							|  |  |  |     endif ()
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     target_sources(${BOARD_TARGET} PUBLIC | 
					
						
							| 
									
										
										
										
											2023-06-02 15:26:16 +07:00
										 |  |  |       ${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  |       )
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:26:16 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
 | 
					
						
							|  |  |  |       target_link_options(${BOARD_TARGET} PUBLIC | 
					
						
							|  |  |  |         # linker file
 | 
					
						
							|  |  |  |         "LINKER:--script=${LD_FILE_GNU}"
 | 
					
						
							|  |  |  |         -L${NRFX_DIR}/mdk
 | 
					
						
							|  |  |  |         # nanolib
 | 
					
						
							|  |  |  |         --specs=nosys.specs
 | 
					
						
							|  |  |  |         --specs=nano.specs
 | 
					
						
							|  |  |  |         )
 | 
					
						
							|  |  |  |     elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
 | 
					
						
							|  |  |  |       target_link_options(${BOARD_TARGET} PUBLIC | 
					
						
							|  |  |  |         "LINKER:--config=${LD_FILE_IAR}"
 | 
					
						
							|  |  |  |         )
 | 
					
						
							|  |  |  |     endif ()
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  |   endif ()
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:26:16 +07:00
										 |  |  | endfunction()
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 21:27:26 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | #------------------------------------
 | 
					
						
							|  |  |  | # Functions
 | 
					
						
							|  |  |  | #------------------------------------
 | 
					
						
							| 
									
										
										
										
											2023-05-25 17:27:05 +07:00
										 |  |  | function(family_configure_example TARGET)
 | 
					
						
							| 
									
										
										
										
											2023-06-01 12:36:08 +07:00
										 |  |  |   family_configure_common(${TARGET})
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:26:16 +07:00
										 |  |  |   # Board target
 | 
					
						
							|  |  |  |   add_board_target(board_${BOARD})
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  |   #---------- Port Specific ----------
 | 
					
						
							|  |  |  |   # These files are built for each example since it depends on example's tusb_config.h
 | 
					
						
							|  |  |  |   target_sources(${TARGET} PUBLIC | 
					
						
							|  |  |  |     # TinyUSB Port
 | 
					
						
							|  |  |  |     ${TOP}/src/portable/nordic/nrf5x/dcd_nrf5x.c
 | 
					
						
							|  |  |  |     # BSP
 | 
					
						
							|  |  |  |     ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
 | 
					
						
							|  |  |  |     ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
 | 
					
						
							|  |  |  |     )
 | 
					
						
							|  |  |  |   target_include_directories(${TARGET} PUBLIC | 
					
						
							|  |  |  |     # family, hw, board
 | 
					
						
							|  |  |  |     ${CMAKE_CURRENT_FUNCTION_LIST_DIR}
 | 
					
						
							|  |  |  |     ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
 | 
					
						
							|  |  |  |     ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
 | 
					
						
							|  |  |  |     )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 11:42:17 +07:00
										 |  |  |   # Add TinyUSB
 | 
					
						
							|  |  |  |   family_add_tinyusb(${TARGET} OPT_MCU_NRF5X)
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # Link dependencies
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:26:16 +07:00
										 |  |  |   target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 11:42:17 +07:00
										 |  |  |   # Flashing
 | 
					
						
							| 
									
										
										
										
											2023-05-19 16:27:07 +07:00
										 |  |  |   family_flash_jlink(${TARGET})
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | endfunction()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function(family_configure_device_example TARGET)
 | 
					
						
							| 
									
										
										
										
											2023-05-25 17:27:05 +07:00
										 |  |  |   family_configure_example(${TARGET})
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | endfunction()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function(family_configure_host_example TARGET)
 | 
					
						
							| 
									
										
										
										
											2023-05-25 17:27:05 +07:00
										 |  |  |   family_configure_example(${TARGET})
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | endfunction()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function(family_configure_dual_usb_example TARGET)
 | 
					
						
							| 
									
										
										
										
											2023-05-25 17:27:05 +07:00
										 |  |  |   family_configure_example(${TARGET})
 | 
					
						
							| 
									
										
										
										
											2023-05-15 14:25:42 +07:00
										 |  |  | endfunction()
 |