Skip to content

Commit e2d3c0b

Browse files
authored
Merge pull request hathach#2065 from hathach/cmake-lpc55
add support for nrf5340 application core with pca10059
2 parents f1bef8d + 116a258 commit e2d3c0b

File tree

34 files changed

+630
-194
lines changed

34 files changed

+630
-194
lines changed

.idea/cmake.xml

Lines changed: 5 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-m33.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-m33
5+
-mfloat-abi=hard
6+
-mfpu=fpv5-d16
7+
)
8+
9+
set(FREERTOS_PORT GCC_ARM_CM33_NONSECURE CACHE INTERNAL "")
10+
else ()
11+
# TODO support IAR
12+
endif ()

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: 2 additions & 2 deletions
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)
@@ -230,7 +230,7 @@ JLINK_IF ?= swd
230230
# Flash using jlink
231231
flash-jlink: $(BUILD)/$(PROJECT).hex
232232
@echo halt > $(BUILD)/$(BOARD).jlink
233-
@echo r > $(BUILD)/$(BOARD).jlink
233+
@echo r >> $(BUILD)/$(BOARD).jlink
234234
@echo loadfile $^ >> $(BUILD)/$(BOARD).jlink
235235
@echo r >> $(BUILD)/$(BOARD).jlink
236236
@echo go >> $(BUILD)/$(BOARD).jlink

hw/bsp/imxrt/family.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ function(family_configure_target TARGET)
9898
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
9999
)
100100
target_include_directories(${TARGET} PUBLIC
101+
# family, hw, board
101102
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
102103
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
103104
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
@@ -129,6 +130,7 @@ function(family_configure_target TARGET)
129130
#---------- Flash ----------
130131
# Flash using pyocd
131132
add_custom_target(${TARGET}-pyocd
133+
DEPENDS ${TARGET}
132134
COMMAND pyocd flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
133135
)
134136

@@ -138,6 +140,7 @@ function(family_configure_target TARGET)
138140
# realpath error: No such file or directory
139141
execute_process(COMMAND which LinkServer OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
140142
add_custom_target(${TARGET}-nxplink
143+
DEPENDS ${TARGET}
141144
COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
142145
)
143146

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set(MCU_VARIANT LPC55S28)
2+
set(MCU_CORE LPC55S28)
3+
4+
set(JLINK_DEVICE LPC55S28)
5+
set(PYOCD_TARGET LPC55S28)
6+
set(NXPLINK_DEVICE LPC55S28:LPCXpresso55S28)
7+
8+
function(update_board TARGET)
9+
target_compile_definitions(${TARGET} PUBLIC
10+
CPU_LPC55S28JBD100
11+
)
12+
endfunction()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set(MCU_VARIANT LPC55S69)
2+
set(MCU_CORE LPC55S69_cm33_core0)
3+
4+
set(JLINK_DEVICE LPC55S69)
5+
set(PYOCD_TARGET LPC55S69)
6+
set(NXPLINK_DEVICE LPC55S69:LPCXpresso55S69)
7+
8+
function(update_board TARGET)
9+
target_compile_definitions(${TARGET} PUBLIC
10+
CPU_LPC55S69JBD100_cm33_core0
11+
# port 1 is highspeed
12+
# BOARD_TUD_RHPORT=1
13+
)
14+
endfunction()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set(MCU_VARIANT LPC55S69)
2+
set(MCU_CORE LPC55S69_cm33_core0)
3+
4+
set(JLINK_DEVICE LPC55S69)
5+
set(PYOCD_TARGET LPC55S69)
6+
set(NXPLINK_DEVICE LPC55S69:LPCXpresso55S69)
7+
8+
function(update_board TARGET)
9+
target_compile_definitions(${TARGET} PUBLIC
10+
CPU_LPC55S69JBD100_cm33_core0
11+
# port 1 is highspeed
12+
# BOARD_TUD_RHPORT=1
13+
)
14+
endfunction()

hw/bsp/lpc55/family.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
#include "fsl_power.h"
3232
#include "fsl_iocon.h"
3333
#include "fsl_usart.h"
34+
35+
#ifdef NEOPIXEL_PIN
3436
#include "fsl_sctimer.h"
3537
#include "sct_neopixel.h"
38+
#endif
3639

3740
#ifdef BOARD_TUD_RHPORT
3841
#define PORT_SUPPORT_DEVICE(_n) (BOARD_TUD_RHPORT == _n)

hw/bsp/lpc55/family.cmake

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

0 commit comments

Comments
 (0)