Skip to content

Commit 9fd0fee

Browse files
committed
adding nrf
1 parent a57ba87 commit 9fd0fee

File tree

6 files changed

+203
-5
lines changed

6 files changed

+203
-5
lines changed

.idea/cmake.xml

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cmake/cpu/cortex-m4.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
if (TOOLCHAIN STREQUAL "gcc")
2+
list(APPEND TOOLCHAIN_COMMON_FLAGS
3+
-mthumb
4+
-mcpu=cortex-m4
5+
-mfloat-abi=hard
6+
-mfpu=fpv4-sp-d16
7+
)
8+
9+
set(FREERTOS_PORT GCC_ARM_CM4F CACHE INTERNAL "")
10+
else ()
11+
# TODO support IAR
12+
endif ()

examples/rules.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ LDFLAGS += -Wl,-T,$(TOP)/$(GCC_LD_FILE)
8686
endif
8787

8888
ifneq ($(SKIP_NANOLIB), 1)
89-
LDFLAGS += -specs=nosys.specs -specs=nano.specs
89+
LDFLAGS += --specs=nosys.specs --specs=nano.specs
9090
endif
9191

9292
ASFLAGS += $(CFLAGS)

hw/bsp/lpc55/family.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
if (TARGET _${FAMILY}_family_inclusion_marker)
1+
if (TARGET _lpc55_family_inclusion_marker)
22
return()
33
endif ()
44

5-
add_library(_${FAMILY}_family_inclusion_marker INTERFACE)
5+
add_library(_lpc55_family_inclusion_marker INTERFACE)
66

77
if (NOT BOARD)
88
message(FATAL_ERROR "BOARD not specified")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(MCU_VARIANT nrf52840)
2+
set(LD_FILE_gcc ${NRFX_DIR}/mdk/nrf52840_xxaa.ld)
3+
4+
function(update_board TARGET)
5+
target_compile_definitions(${TARGET} PUBLIC
6+
NRF52840_XXAA
7+
)
8+
endfunction()

hw/bsp/nrf/family.cmake

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
if (TARGET _nrf_family_inclusion_marker)
2+
return()
3+
endif ()
4+
5+
add_library(_nrf_family_inclusion_marker INTERFACE)
6+
7+
if (NOT BOARD)
8+
message(FATAL_ERROR "BOARD not specified")
9+
endif ()
10+
11+
# toolchain set up
12+
set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
13+
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/../../../examples/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
14+
15+
set(FAMILY_MCUS NRF5X CACHE INTERNAL "")
16+
17+
# TOP is path to root directory
18+
set(TOP "${CMAKE_CURRENT_LIST_DIR}/../../..")
19+
set(NRFX_DIR ${TOP}/hw/mcu/nordic/nrfx)
20+
set(CMSIS_DIR ${TOP}/lib/CMSIS_5)
21+
22+
# include board specific
23+
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
24+
set(JLINK_DEVICE $(MCU_VARIANT)_xxaa)
25+
26+
#------------------------------------
27+
# BOARD_TARGET
28+
#------------------------------------
29+
# only need to be built ONCE for all examples
30+
set(BOARD_TARGET board_${BOARD})
31+
if (NOT TARGET ${BOARD_TARGET})
32+
add_library(${BOARD_TARGET} STATIC
33+
# driver
34+
${NRFX_DIR}/drivers/src/nrfx_power.c
35+
${NRFX_DIR}/drivers/src/nrfx_uarte.c
36+
# mcu
37+
${NRFX_DIR}/mdk/system_${MCU_VARIANT}.c
38+
)
39+
target_compile_definitions(${BOARD_TARGET} PUBLIC
40+
CONFIG_GPIO_AS_PINRESET
41+
)
42+
target_include_directories(${BOARD_TARGET} PUBLIC
43+
${NRFX_DIR}/../ # hw/mcu/nordic: remove later
44+
# driver
45+
${NRFX_DIR}
46+
${NRFX_DIR}/mdk
47+
${NRFX_DIR}/hal
48+
${NRFX_DIR}/drivers/include
49+
${NRFX_DIR}/drivers/src
50+
${CMSIS_DIR}/CMSIS/Core/Include
51+
)
52+
update_board(${BOARD_TARGET})
53+
54+
if (NOT DEFINED LD_FILE_${TOOLCHAIN})
55+
set(LD_FILE_gcc ${NRFX_DIR}/mdk/${MCU_VARIANT}_xxaa.ld)
56+
endif ()
57+
58+
if (TOOLCHAIN STREQUAL "gcc")
59+
target_sources(${BOARD_TARGET} PUBLIC
60+
${NRFX_DIR}/mdk/gcc_startup_${MCU_VARIANT}.S
61+
)
62+
target_link_options(${BOARD_TARGET} PUBLIC
63+
# linker file
64+
"LINKER:--script=${LD_FILE_gcc}"
65+
-L${NRFX_DIR}/mdk
66+
# link map
67+
"LINKER:-Map=$<IF:$<BOOL:$<TARGET_PROPERTY:OUTPUT_NAME>>,$<TARGET_PROPERTY:OUTPUT_NAME>,$<TARGET_PROPERTY:NAME>>${CMAKE_EXECUTABLE_SUFFIX}.map"
68+
# nanolib
69+
--specs=nosys.specs
70+
--specs=nano.specs
71+
)
72+
else ()
73+
# TODO support IAR
74+
endif ()
75+
endif () # BOARD_TARGET
76+
77+
#------------------------------------
78+
# Functions
79+
#------------------------------------
80+
function(family_configure_target TARGET)
81+
# set output name to .elf
82+
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${TARGET}.elf)
83+
84+
# TOP is path to root directory
85+
set(TOP "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../..")
86+
87+
#---------- Port Specific ----------
88+
# These files are built for each example since it depends on example's tusb_config.h
89+
target_sources(${TARGET} PUBLIC
90+
# TinyUSB Port
91+
${TOP}/src/portable/nordic/nrf5x/dcd_nrf5x.c
92+
# BSP
93+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
94+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
95+
)
96+
target_include_directories(${TARGET} PUBLIC
97+
# family, hw, board
98+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
99+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
100+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
101+
)
102+
103+
#---------- TinyUSB ----------
104+
# tinyusb target is built for each example since it depends on example's tusb_config.h
105+
set(TINYUSB_TARGET_PREFIX ${TARGET}-)
106+
add_library(${TARGET}-tinyusb_config INTERFACE)
107+
108+
target_include_directories(${TARGET}-tinyusb_config INTERFACE
109+
${CMAKE_CURRENT_SOURCE_DIR}/src
110+
)
111+
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
112+
CFG_TUSB_MCU=OPT_MCU_NRF5X
113+
)
114+
115+
# tinyusb's CMakeList.txt
116+
add_subdirectory(${TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb)
117+
118+
# Link dependencies
119+
target_link_libraries(${TARGET} PUBLIC ${BOARD_TARGET} ${TARGET}-tinyusb)
120+
121+
# group target (not yet supported by clion)
122+
set_target_properties(${TARGET}-tinyusb ${TARGET}-tinyusb_config
123+
PROPERTIES FOLDER ${TARGET}_sub
124+
)
125+
126+
#---------- Flash ----------
127+
# Flash using pyocd
128+
add_custom_target(${TARGET}-pyocd
129+
COMMAND pyocd flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
130+
)
131+
132+
# Flash using NXP LinkServer (redlink)
133+
# https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER
134+
# LinkServer has a bug that can only execute with full path otherwise it throws:
135+
# realpath error: No such file or directory
136+
execute_process(COMMAND which LinkServer OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
137+
add_custom_target(${TARGET}-nxplink
138+
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
139+
)
140+
141+
endfunction()
142+
143+
144+
function(family_add_freertos TARGET)
145+
# freertos_config
146+
add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/FreeRTOSConfig ${CMAKE_CURRENT_BINARY_DIR}/freertos_config)
147+
148+
## freertos
149+
if (NOT TARGET freertos_kernel)
150+
add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../../lib/FreeRTOS-Kernel ${CMAKE_CURRENT_BINARY_DIR}/freertos_kernel)
151+
endif ()
152+
153+
# Add FreeRTOS option to tinyusb_config
154+
target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
155+
CFG_TUSB_OS=OPT_OS_FREERTOS
156+
)
157+
# link tinyusb with freeRTOS kernel
158+
target_link_libraries(${TARGET}-tinyusb PUBLIC
159+
freertos_kernel
160+
)
161+
target_link_libraries(${TARGET} PUBLIC
162+
freertos_kernel
163+
)
164+
endfunction()
165+
166+
function(family_configure_device_example TARGET)
167+
family_configure_target(${TARGET})
168+
endfunction()
169+
170+
function(family_configure_host_example TARGET)
171+
family_configure_target(${TARGET})
172+
endfunction()
173+
174+
function(family_configure_dual_usb_example TARGET)
175+
family_configure_target(${TARGET})
176+
endfunction()

0 commit comments

Comments
 (0)