Skip to content

Commit a268e0b

Browse files
committed
add lpc40 to cmake
1 parent 8fa0b74 commit a268e0b

File tree

10 files changed

+179
-20
lines changed

10 files changed

+179
-20
lines changed

.github/workflows/cmake_arm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
# Alphabetical order
3636
- 'imxrt'
3737
- 'kinetis_kl'
38-
- 'lpc18'
38+
- 'lpc18 lpc40'
3939
- 'lpc55'
4040
- 'mcx'
4141
- 'ra'

.idea/cmake.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/lpc4088.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(JLINK_DEVICE LPC4088)
2+
set(PYOCD_TARGET LPC4088)
3+
set(NXPLINK_DEVICE LPC4088:LPC4088)
4+
5+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/lpc4088.ld)
6+
7+
function(update_board TARGET)
8+
# nothing to do
9+
endfunction()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2023 Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
#ifndef EA4088QS__BOARD_H
28+
#define EA4088QS__BOARD_H
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
35+
#ifdef __cplusplus
36+
}
37+
#endif
38+
39+
#endif
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
LD_FILE = $(BOARD_PATH)/lpc4088.ld
3+
4+
# For flash-jlink target
5+
JLINK_DEVICE = LPC4088
6+
7+
# flash using jlink
8+
flash: flash-jlink

hw/bsp/ea4088qs/ea4088qs.c renamed to hw/bsp/lpc40/family.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
*/
2626

2727
#include "chip.h"
28-
#include "../board.h"
28+
#include "bsp/board.h"
29+
#include "board.h"
2930

3031
//--------------------------------------------------------------------+
3132
// USB Interrupt Handler
@@ -49,6 +50,8 @@ void USB_IRQHandler(void)
4950

5051
#define BUTTON_PORT 2
5152
#define BUTTON_PIN 10
53+
#define BUTTON_ACTIV_STATE 0
54+
5255

5356
/* System oscillator rate and RTC oscillator rate */
5457
const uint32_t OscRateIn = 12000000;
@@ -159,7 +162,7 @@ void board_led_write(bool state)
159162
uint32_t board_button_read(void)
160163
{
161164
// active low
162-
return Chip_GPIO_GetPinState(LPC_GPIO, BUTTON_PORT, BUTTON_PIN) ? 0 : 1;
165+
return BUTTON_ACTIV_STATE == Chip_GPIO_GetPinState(LPC_GPIO, BUTTON_PORT, BUTTON_PIN);
163166
}
164167

165168
int board_uart_read(uint8_t* buf, int len)

hw/bsp/lpc40/family.cmake

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
include_guard()
2+
3+
set(SDK_DIR ${TOP}/hw/mcu/nxp/lpcopen/lpc40xx/lpc_chip_40xx)
4+
5+
# include board specific
6+
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
7+
8+
# toolchain set up
9+
set(CMAKE_SYSTEM_PROCESSOR cortex-m4 CACHE INTERNAL "System Processor")
10+
set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
11+
12+
set(FAMILY_MCUS LPC18XX CACHE INTERNAL "")
13+
14+
15+
#------------------------------------
16+
# BOARD_TARGET
17+
#------------------------------------
18+
# only need to be built ONCE for all examples
19+
function(add_board_target BOARD_TARGET)
20+
if (TARGET ${BOARD_TARGET})
21+
return()
22+
endif ()
23+
24+
add_library(${BOARD_TARGET} STATIC
25+
${SDK_DIR}/../gcc/cr_startup_lpc40xx.c
26+
${SDK_DIR}/src/chip_17xx_40xx.c
27+
${SDK_DIR}/src/clock_17xx_40xx.c
28+
${SDK_DIR}/src/fpu_init.c
29+
${SDK_DIR}/src/gpio_17xx_40xx.c
30+
${SDK_DIR}/src/iocon_17xx_40xx.c
31+
${SDK_DIR}/src/sysctl_17xx_40xx.c
32+
${SDK_DIR}/src/sysinit_17xx_40xx.c
33+
${SDK_DIR}/src/uart_17xx_40xx.c
34+
)
35+
target_compile_options(${BOARD_TARGET} PUBLIC
36+
-nostdlib
37+
)
38+
target_compile_definitions(${BOARD_TARGET} PUBLIC
39+
__USE_LPCOPEN
40+
CORE_M4
41+
)
42+
target_include_directories(${BOARD_TARGET} PUBLIC
43+
${SDK_DIR}/inc
44+
)
45+
46+
update_board(${BOARD_TARGET})
47+
48+
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
49+
target_link_options(${BOARD_TARGET} PUBLIC
50+
"LINKER:--script=${LD_FILE_GNU}"
51+
# nanolib
52+
--specs=nosys.specs
53+
--specs=nano.specs
54+
)
55+
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
56+
target_link_options(${BOARD_TARGET} PUBLIC
57+
"LINKER:--config=${LD_FILE_IAR}"
58+
)
59+
endif ()
60+
endfunction()
61+
62+
63+
#------------------------------------
64+
# Functions
65+
#------------------------------------
66+
function(family_configure_example TARGET RTOS)
67+
family_configure_common(${TARGET} ${RTOS})
68+
69+
# Board target
70+
add_board_target(board_${BOARD})
71+
72+
#---------- Port Specific ----------
73+
# These files are built for each example since it depends on example's tusb_config.h
74+
target_sources(${TARGET} PUBLIC
75+
# BSP
76+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
77+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
78+
)
79+
target_include_directories(${TARGET} PUBLIC
80+
# family, hw, board
81+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
82+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
83+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
84+
)
85+
86+
# Add TinyUSB target and port source
87+
family_add_tinyusb(${TARGET} OPT_MCU_LPC40XX ${RTOS})
88+
target_sources(${TARGET}-tinyusb PUBLIC
89+
${TOP}/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
90+
)
91+
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
92+
93+
# Link dependencies
94+
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
95+
96+
# Flashing
97+
family_flash_jlink(${TARGET})
98+
#family_flash_nxplink(${TARGET})
99+
endfunction()
Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
DEPS_SUBMODULES += hw/mcu/nxp/lpcopen
22

3+
MCU_DIR = hw/mcu/nxp/lpcopen/lpc40xx/lpc_chip_40xx
4+
include $(TOP)/$(BOARD_PATH)/board.mk
5+
CPU_CORE ?= cortex-m4
6+
37
CFLAGS += \
48
-flto \
5-
-mthumb \
6-
-mabi=aapcs \
7-
-mcpu=cortex-m4 \
8-
-mfloat-abi=hard \
9-
-mfpu=fpv4-sp-d16 \
109
-nostdlib \
1110
-DCORE_M4 \
1211
-D__USE_LPCOPEN \
@@ -17,31 +16,22 @@ CFLAGS += \
1716
# mcu driver cause following warnings
1817
CFLAGS += -Wno-error=strict-prototypes -Wno-error=unused-parameter -Wno-error=cast-qual
1918

20-
MCU_DIR = hw/mcu/nxp/lpcopen/lpc40xx/lpc_chip_40xx
21-
2219
# All source paths should be relative to the top level.
23-
LD_FILE = hw/bsp/$(BOARD)/lpc4088.ld
24-
2520
SRC_C += \
2621
src/portable/nxp/lpc17_40/dcd_lpc17_40.c \
2722
$(MCU_DIR)/../gcc/cr_startup_lpc40xx.c \
2823
$(MCU_DIR)/src/chip_17xx_40xx.c \
2924
$(MCU_DIR)/src/clock_17xx_40xx.c \
25+
$(MCU_DIR)/src/fpu_init.c \
3026
$(MCU_DIR)/src/gpio_17xx_40xx.c \
3127
$(MCU_DIR)/src/iocon_17xx_40xx.c \
3228
$(MCU_DIR)/src/sysctl_17xx_40xx.c \
3329
$(MCU_DIR)/src/sysinit_17xx_40xx.c \
3430
$(MCU_DIR)/src/uart_17xx_40xx.c \
35-
$(MCU_DIR)/src/fpu_init.c
3631

3732
INC += \
38-
$(TOP)/$(MCU_DIR)/inc
33+
$(TOP)/$(MCU_DIR)/inc \
34+
$(TOP)/$(BOARD_PATH)
3935

4036
# For freeRTOS port source
4137
FREERTOS_PORTABLE_SRC = $(FREERTOS_PORTABLE_PATH)/ARM_CM4F
42-
43-
# For flash-jlink target
44-
JLINK_DEVICE = LPC4088
45-
46-
# flash using jlink
47-
flash: flash-jlink

0 commit comments

Comments
 (0)