From 3da76ae4495cc16a4eed5882122efad696e2270c Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 15:58:43 +0700 Subject: [PATCH 01/15] making new family lpc54 --- hw/bsp/lpc54/boards/lpcxpresso54114/board.mk | 11 ++++++ .../lpcxpresso54114.c => lpc54/family.c} | 36 +++++++++---------- .../board.mk => lpc54/family.mk} | 14 ++------ hw/bsp/lpc55/family.c | 26 +++++++------- 4 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 hw/bsp/lpc54/boards/lpcxpresso54114/board.mk rename hw/bsp/{lpcxpresso54114/lpcxpresso54114.c => lpc54/family.c} (88%) rename hw/bsp/{lpcxpresso54114/board.mk => lpc54/family.mk} (76%) diff --git a/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk b/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk new file mode 100644 index 00000000..33e1a6dc --- /dev/null +++ b/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk @@ -0,0 +1,11 @@ +MCU_VARIANT = LPC55S69 +MCU_CORE = LPC55S69_cm33_core0 + +CFLAGS += -DCPU_LPC54114J256BD64_cm4 +LD_FILE = $(MCU_DIR)/gcc/LPC54114J256_cm4_flash.ld + +JLINK_DEVICE = LPC54114J256_M4 +PYOCD_TARGET = LPC54114 + +# flash using pyocd +flash: flash-pyocd diff --git a/hw/bsp/lpcxpresso54114/lpcxpresso54114.c b/hw/bsp/lpc54/family.c similarity index 88% rename from hw/bsp/lpcxpresso54114/lpcxpresso54114.c rename to hw/bsp/lpc54/family.c index 3bccc4bd..ead69cef 100644 --- a/hw/bsp/lpcxpresso54114/lpcxpresso54114.c +++ b/hw/bsp/lpc54/family.c @@ -30,14 +30,6 @@ #include "fsl_power.h" #include "fsl_iocon.h" -//--------------------------------------------------------------------+ -// Forward USB interrupt events to TinyUSB IRQ Handler -//--------------------------------------------------------------------+ -void USB0_IRQHandler(void) -{ - tud_int_handler(0); -} - //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM //--------------------------------------------------------------------+ @@ -50,16 +42,24 @@ void USB0_IRQHandler(void) #define BUTTON_PIN 24 // IOCON pin mux -#define IOCON_PIO_DIGITAL_EN 0x80u /*!<@brief Enables digital function */ +#define IOCON_PIO_DIGITAL_EN 0x80u // Enables digital function #define IOCON_PIO_FUNC0 0x00u -#define IOCON_PIO_FUNC1 0x01u /*!<@brief Selects pin function 1 */ -#define IOCON_PIO_FUNC7 0x07u /*!<@brief Selects pin function 7 */ -#define IOCON_PIO_INPFILT_OFF 0x0100u /*!<@brief Input filter disabled */ -#define IOCON_PIO_INV_DI 0x00u /*!<@brief Input function is not inverted */ -#define IOCON_PIO_MODE_INACT 0x00u /*!<@brief No addition pin function */ +#define IOCON_PIO_FUNC1 0x01u // Selects pin function 1 +#define IOCON_PIO_FUNC7 0x07u // Selects pin function 7 +#define IOCON_PIO_INPFILT_OFF 0x0100u // Input filter disabled +#define IOCON_PIO_INV_DI 0x00u // Input function is not inverted +#define IOCON_PIO_MODE_INACT 0x00u // No addition pin function #define IOCON_PIO_MODE_PULLUP 0x10u -#define IOCON_PIO_OPENDRAIN_DI 0x00u /*!<@brief Open drain is disabled */ -#define IOCON_PIO_SLEW_STANDARD 0x00u /*!<@brief Standard mode, output slew rate control is enabled */ +#define IOCON_PIO_OPENDRAIN_DI 0x00u // Open drain is disabled +#define IOCON_PIO_SLEW_STANDARD 0x00u // Standard mode, output slew rate control is enabled + +//--------------------------------------------------------------------+ +// Forward USB interrupt events to TinyUSB IRQ Handler +//--------------------------------------------------------------------+ +void USB0_IRQHandler(void) +{ + tud_int_handler(0); +} /**************************************************************** name: BOARD_BootClockFROHF96M @@ -104,10 +104,10 @@ void board_init(void) // Init 96 MHz clock BootClockFROHF96M(); -#if CFG_TUSB_OS == OPT_OS_NONE // 1ms tick timer SysTick_Config(SystemCoreClock / 1000); -#elif CFG_TUSB_OS == OPT_OS_FREERTOS + +#if CFG_TUSB_OS == OPT_OS_FREERTOS // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher ) NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); #endif diff --git a/hw/bsp/lpcxpresso54114/board.mk b/hw/bsp/lpc54/family.mk similarity index 76% rename from hw/bsp/lpcxpresso54114/board.mk rename to hw/bsp/lpc54/family.mk index b6bc0761..969d1ae2 100644 --- a/hw/bsp/lpcxpresso54114/board.mk +++ b/hw/bsp/lpc54/family.mk @@ -1,5 +1,7 @@ DEPS_SUBMODULES += hw/mcu/nxp +include $(TOP)/$(BOARD_PATH)/board.mk + CFLAGS += \ -flto \ -mthumb \ @@ -7,7 +9,6 @@ CFLAGS += \ -mcpu=cortex-m4 \ -mfloat-abi=hard \ -mfpu=fpv4-sp-d16 \ - -DCPU_LPC54114J256BD64_cm4 \ -DCFG_TUSB_MCU=OPT_MCU_LPC54XXX \ -DCFG_TUSB_MEM_SECTION='__attribute__((section(".data")))' \ -DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))' @@ -17,9 +18,6 @@ CFLAGS += -Wno-error=unused-parameter MCU_DIR = hw/mcu/nxp/sdk/devices/LPC54114 -# All source paths should be relative to the top level. -LD_FILE = $(MCU_DIR)/gcc/LPC54114J256_cm4_flash.ld - SRC_C += \ src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c \ $(MCU_DIR)/system_LPC54114_cm4.c \ @@ -29,6 +27,7 @@ SRC_C += \ $(MCU_DIR)/drivers/fsl_reset.c INC += \ + $(TOP)/$(BOARD_PATH) \ $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ $(TOP)/$(MCU_DIR) \ $(TOP)/$(MCU_DIR)/drivers @@ -39,10 +38,3 @@ LIBS += $(TOP)/$(MCU_DIR)/gcc/libpower_cm4_hardabi.a # For freeRTOS port source FREERTOS_PORT = ARM_CM4F - -# For flash-jlink target -JLINK_DEVICE = LPC54114J256_M4 - -# flash using pyocd -flash: $(BUILD)/$(PROJECT).hex - pyocd flash -t LPC54114 $< diff --git a/hw/bsp/lpc55/family.c b/hw/bsp/lpc55/family.c index 890c2f5c..4fc1f622 100644 --- a/hw/bsp/lpc55/family.c +++ b/hw/bsp/lpc55/family.c @@ -39,20 +39,20 @@ //--------------------------------------------------------------------+ // IOCON pin mux -#define IOCON_PIO_DIGITAL_EN 0x0100u /*!<@brief Enables digital function */ -#define IOCON_PIO_FUNC0 0x00u /*!<@brief Selects pin function 0 */ -#define IOCON_PIO_FUNC1 0x01u /*!<@brief Selects pin function 1 */ -#define IOCON_PIO_FUNC4 0x04u /*!<@brief Selects pin function 4 */ -#define IOCON_PIO_FUNC7 0x07u /*!<@brief Selects pin function 7 */ -#define IOCON_PIO_INV_DI 0x00u /*!<@brief Input function is not inverted */ -#define IOCON_PIO_MODE_INACT 0x00u /*!<@brief No addition pin function */ -#define IOCON_PIO_OPENDRAIN_DI 0x00u /*!<@brief Open drain is disabled */ -#define IOCON_PIO_SLEW_STANDARD 0x00u /*!<@brief Standard mode, output slew rate control is enabled */ +#define IOCON_PIO_DIGITAL_EN 0x0100u // Enables digital function +#define IOCON_PIO_FUNC0 0x00u // Selects pin function 0 +#define IOCON_PIO_FUNC1 0x01u // Selects pin function 1 +#define IOCON_PIO_FUNC4 0x04u // Selects pin function 4 +#define IOCON_PIO_FUNC7 0x07u // Selects pin function 7 +#define IOCON_PIO_INV_DI 0x00u // Input function is not inverted +#define IOCON_PIO_MODE_INACT 0x00u // No addition pin function +#define IOCON_PIO_OPENDRAIN_DI 0x00u // Open drain is disabled +#define IOCON_PIO_SLEW_STANDARD 0x00u // Standard mode, output slew rate control is enabled -#define IOCON_PIO_DIG_FUNC0_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC0) /*!<@brief Digital pin function 0 enabled */ -#define IOCON_PIO_DIG_FUNC1_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC1) /*!<@brief Digital pin function 1 enabled */ -#define IOCON_PIO_DIG_FUNC4_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC4) /*!<@brief Digital pin function 2 enabled */ -#define IOCON_PIO_DIG_FUNC7_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC7) /*!<@brief Digital pin function 2 enabled */ +#define IOCON_PIO_DIG_FUNC0_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC0) // Digital pin function 0 enabled +#define IOCON_PIO_DIG_FUNC1_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC1) // Digital pin function 1 enabled +#define IOCON_PIO_DIG_FUNC4_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC4) // Digital pin function 2 enabled +#define IOCON_PIO_DIG_FUNC7_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_FUNC7) // Digital pin function 2 enabled //--------------------------------------------------------------------+ // Forward USB interrupt events to TinyUSB IRQ Handler From 62c5fa10567a6cb68ed53961022b4d3b054d9de6 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 18:07:26 +0700 Subject: [PATCH 02/15] remove submodule hw/mcu/nxp --- .gitmodules | 3 --- hw/mcu/nxp | 1 - 2 files changed, 4 deletions(-) delete mode 160000 hw/mcu/nxp diff --git a/.gitmodules b/.gitmodules index 6cceee43..e2140ee1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,9 +10,6 @@ [submodule "hw/mcu/ti"] path = hw/mcu/ti url = https://github.com/hathach/ti_driver.git -[submodule "hw/mcu/nxp"] - path = hw/mcu/nxp - url = https://github.com/hathach/nxp_driver.git [submodule "hw/mcu/microchip"] path = hw/mcu/microchip url = https://github.com/hathach/microchip_driver.git diff --git a/hw/mcu/nxp b/hw/mcu/nxp deleted file mode 160000 index 587c6576..00000000 --- a/hw/mcu/nxp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 587c65766538a5e1cfb6188ac611ded61f2eb859 From e115e087281bf1c52f4c67d1bec3f6a778acce15 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 18:11:49 +0700 Subject: [PATCH 03/15] add nxp_lpcopen as submodule --- .gitmodules | 3 +++ hw/bsp/ea4088qs/board.mk | 2 +- hw/bsp/ea4357/board.mk | 2 +- hw/bsp/lpc15/family.mk | 2 +- hw/bsp/lpc18/family.mk | 2 +- hw/bsp/lpcxpresso11u37/board.mk | 2 +- hw/bsp/lpcxpresso11u68/board.mk | 2 +- hw/bsp/lpcxpresso1347/board.mk | 2 +- hw/bsp/lpcxpresso1769/board.mk | 2 +- hw/bsp/mbed1768/board.mk | 2 +- hw/bsp/ngx4330/board.mk | 2 +- hw/mcu/nxp/lpcopen | 1 + 12 files changed, 14 insertions(+), 10 deletions(-) create mode 160000 hw/mcu/nxp/lpcopen diff --git a/.gitmodules b/.gitmodules index e2140ee1..087cf963 100644 --- a/.gitmodules +++ b/.gitmodules @@ -112,3 +112,6 @@ [submodule "hw/mcu/renesas/rx"] path = hw/mcu/renesas/rx url = https://github.com/kkitayam/rx_device.git +[submodule "hw/mcu/nxp/lpcopen"] + path = hw/mcu/nxp/lpcopen + url = https://github.com/hathach/nxp_lpcopen.git diff --git a/hw/bsp/ea4088qs/board.mk b/hw/bsp/ea4088qs/board.mk index 05e730d2..c624a5cf 100644 --- a/hw/bsp/ea4088qs/board.mk +++ b/hw/bsp/ea4088qs/board.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/lpcopen CFLAGS += \ -flto \ diff --git a/hw/bsp/ea4357/board.mk b/hw/bsp/ea4357/board.mk index 1ad97057..86391ab5 100644 --- a/hw/bsp/ea4357/board.mk +++ b/hw/bsp/ea4357/board.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/lpcopen CFLAGS += \ -flto \ diff --git a/hw/bsp/lpc15/family.mk b/hw/bsp/lpc15/family.mk index 90e8ca50..e80a3bc5 100644 --- a/hw/bsp/lpc15/family.mk +++ b/hw/bsp/lpc15/family.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/lpcopen include $(TOP)/$(BOARD_PATH)/board.mk diff --git a/hw/bsp/lpc18/family.mk b/hw/bsp/lpc18/family.mk index 0908e187..3fed0b45 100644 --- a/hw/bsp/lpc18/family.mk +++ b/hw/bsp/lpc18/family.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/lpcopen include $(TOP)/$(BOARD_PATH)/board.mk diff --git a/hw/bsp/lpcxpresso11u37/board.mk b/hw/bsp/lpcxpresso11u37/board.mk index 7fa42f9a..8fcda51e 100644 --- a/hw/bsp/lpcxpresso11u37/board.mk +++ b/hw/bsp/lpcxpresso11u37/board.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/lpcopen CFLAGS += \ -flto \ diff --git a/hw/bsp/lpcxpresso11u68/board.mk b/hw/bsp/lpcxpresso11u68/board.mk index b59506d4..922414f8 100644 --- a/hw/bsp/lpcxpresso11u68/board.mk +++ b/hw/bsp/lpcxpresso11u68/board.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/lpcopen CFLAGS += \ -flto \ diff --git a/hw/bsp/lpcxpresso1347/board.mk b/hw/bsp/lpcxpresso1347/board.mk index 0f63cefb..0d56a33a 100644 --- a/hw/bsp/lpcxpresso1347/board.mk +++ b/hw/bsp/lpcxpresso1347/board.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/lpcopen CFLAGS += \ -flto \ diff --git a/hw/bsp/lpcxpresso1769/board.mk b/hw/bsp/lpcxpresso1769/board.mk index 678c703d..b69be39b 100644 --- a/hw/bsp/lpcxpresso1769/board.mk +++ b/hw/bsp/lpcxpresso1769/board.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/lpcopen CFLAGS += \ -flto \ diff --git a/hw/bsp/mbed1768/board.mk b/hw/bsp/mbed1768/board.mk index bd48b29b..e99df9f0 100644 --- a/hw/bsp/mbed1768/board.mk +++ b/hw/bsp/mbed1768/board.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/lpcopen CFLAGS += \ -flto \ diff --git a/hw/bsp/ngx4330/board.mk b/hw/bsp/ngx4330/board.mk index 0a0cb3ba..04c37fee 100644 --- a/hw/bsp/ngx4330/board.mk +++ b/hw/bsp/ngx4330/board.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/lpcopen CFLAGS += \ -flto \ diff --git a/hw/mcu/nxp/lpcopen b/hw/mcu/nxp/lpcopen new file mode 160000 index 00000000..43c45c85 --- /dev/null +++ b/hw/mcu/nxp/lpcopen @@ -0,0 +1 @@ +Subproject commit 43c45c85405a5dd114fff0ea95cca62837740c13 From aaa8c9928c2b560f60f7e4f70bc8d8d2eb5eb0eb Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 18:26:04 +0700 Subject: [PATCH 04/15] add official nxp mcux-sdk submodule --- .gitmodules | 3 +++ hw/mcu/nxp/mcux-sdk | 1 + 2 files changed, 4 insertions(+) create mode 160000 hw/mcu/nxp/mcux-sdk diff --git a/.gitmodules b/.gitmodules index 087cf963..f9edcebd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -115,3 +115,6 @@ [submodule "hw/mcu/nxp/lpcopen"] path = hw/mcu/nxp/lpcopen url = https://github.com/hathach/nxp_lpcopen.git +[submodule "hw/mcu/nxp/mcux-sdk"] + path = hw/mcu/nxp/mcux-sdk + url = https://github.com/NXPmicro/mcux-sdk.git diff --git a/hw/mcu/nxp/mcux-sdk b/hw/mcu/nxp/mcux-sdk new file mode 160000 index 00000000..cb21c660 --- /dev/null +++ b/hw/mcu/nxp/mcux-sdk @@ -0,0 +1 @@ +Subproject commit cb21c660991c92e90ece99ccb63a4bc611899c3a From af0db342df37932511521a1a4b45c7bc31de03f2 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 18:30:19 +0700 Subject: [PATCH 05/15] update lpc mcu sdk path --- hw/bsp/frdm_kl25z/board.mk | 4 ++-- hw/bsp/imxrt/family.mk | 4 ++-- hw/bsp/lpc54/family.mk | 4 ++-- hw/bsp/lpc55/family.mk | 4 ++-- hw/bsp/lpcxpresso51u68/board.mk | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hw/bsp/frdm_kl25z/board.mk b/hw/bsp/frdm_kl25z/board.mk index 1a4d718c..2e973b98 100644 --- a/hw/bsp/frdm_kl25z/board.mk +++ b/hw/bsp/frdm_kl25z/board.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/mcux-sdk CFLAGS += \ -mthumb \ @@ -10,7 +10,7 @@ CFLAGS += \ # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -MCU_DIR = hw/mcu/nxp/sdk/devices/MKL25Z4 +MCU_DIR = hw/mcu/nxp/mcux-sdk/devices/MKL25Z4 # All source paths should be relative to the top level. LD_FILE = $(MCU_DIR)/gcc/MKL25Z128xxx4_flash.ld diff --git a/hw/bsp/imxrt/family.mk b/hw/bsp/imxrt/family.mk index 1b6d7e8d..6ebc0e26 100644 --- a/hw/bsp/imxrt/family.mk +++ b/hw/bsp/imxrt/family.mk @@ -1,5 +1,5 @@ UF2_FAMILY_ID = 0x4fb2d5bd -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/mcux-sdk include $(TOP)/$(BOARD_PATH)/board.mk @@ -17,7 +17,7 @@ CFLAGS += \ # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -Wno-error=implicit-fallthrough= -MCU_DIR = hw/mcu/nxp/sdk/devices/$(MCU_VARIANT) +MCU_DIR = hw/mcu/nxp/mcux-sdk/devices/$(MCU_VARIANT) # All source paths should be relative to the top level. LD_FILE = $(MCU_DIR)/gcc/$(MCU_VARIANT)xxxxx_flexspi_nor.ld diff --git a/hw/bsp/lpc54/family.mk b/hw/bsp/lpc54/family.mk index 969d1ae2..862a5a7c 100644 --- a/hw/bsp/lpc54/family.mk +++ b/hw/bsp/lpc54/family.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/mcux-sdk include $(TOP)/$(BOARD_PATH)/board.mk @@ -16,7 +16,7 @@ CFLAGS += \ # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -MCU_DIR = hw/mcu/nxp/sdk/devices/LPC54114 +MCU_DIR = hw/mcu/nxp/mcux-sdk/devices/LPC54114 SRC_C += \ src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c \ diff --git a/hw/bsp/lpc55/family.mk b/hw/bsp/lpc55/family.mk index 46923cc4..6bced7ed 100644 --- a/hw/bsp/lpc55/family.mk +++ b/hw/bsp/lpc55/family.mk @@ -1,5 +1,5 @@ UF2_FAMILY_ID = 0x2abc77ec -DEPS_SUBMODULES += lib/sct_neopixel hw/mcu/nxp +DEPS_SUBMODULES += lib/sct_neopixel hw/mcu/nxp/mcux-sdk include $(TOP)/$(BOARD_PATH)/board.mk @@ -30,7 +30,7 @@ endif # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -Wno-error=float-equal -MCU_DIR = hw/mcu/nxp/sdk/devices/$(MCU_VARIANT) +MCU_DIR = hw/mcu/nxp/mcux-sdk/devices/$(MCU_VARIANT) # All source paths should be relative to the top level. LD_FILE ?= $(MCU_DIR)/gcc/$(MCU_CORE)_flash.ld diff --git a/hw/bsp/lpcxpresso51u68/board.mk b/hw/bsp/lpcxpresso51u68/board.mk index 2582e98f..21b6c55f 100644 --- a/hw/bsp/lpcxpresso51u68/board.mk +++ b/hw/bsp/lpcxpresso51u68/board.mk @@ -1,4 +1,4 @@ -DEPS_SUBMODULES += hw/mcu/nxp +DEPS_SUBMODULES += hw/mcu/nxp/mcux-sdk CFLAGS += \ -flto \ @@ -13,7 +13,7 @@ CFLAGS += \ # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -MCU_DIR = hw/mcu/nxp/sdk/devices/LPC51U68 +MCU_DIR = hw/mcu/nxp/mcux-sdk/devices/LPC51U68 # All source paths should be relative to the top level. LD_FILE = $(MCU_DIR)/gcc/LPC51U68_flash.ld From 810057bdb2b0b2d62a7f4ae9f394f46f58862be2 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 19:30:23 +0700 Subject: [PATCH 06/15] fix build with imxrt --- hw/bsp/imxrt/family.c | 13 ++++++++++++- hw/bsp/imxrt/family.mk | 16 ++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/hw/bsp/imxrt/family.c b/hw/bsp/imxrt/family.c index c6b1a315..77a224a5 100644 --- a/hw/bsp/imxrt/family.c +++ b/hw/bsp/imxrt/family.c @@ -79,7 +79,18 @@ void board_init(void) uart_config.baudRate_Bps = CFG_BOARD_UART_BAUDRATE; uart_config.enableTx = true; uart_config.enableRx = true; - LPUART_Init(UART_PORT, &uart_config, (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U)); + + uint32_t freq; + if (CLOCK_GetMux(kCLOCK_UartMux) == 0) /* PLL3 div6 80M */ + { + freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); + } + else + { + freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U); + } + + LPUART_Init(UART_PORT, &uart_config, freq); //------------- USB0 -------------// diff --git a/hw/bsp/imxrt/family.mk b/hw/bsp/imxrt/family.mk index 6ebc0e26..a919d369 100644 --- a/hw/bsp/imxrt/family.mk +++ b/hw/bsp/imxrt/family.mk @@ -1,5 +1,6 @@ UF2_FAMILY_ID = 0x4fb2d5bd -DEPS_SUBMODULES += hw/mcu/nxp/mcux-sdk +SDK_DIR = hw/mcu/nxp/mcux-sdk +DEPS_SUBMODULES += $(SDK_DIR) include $(TOP)/$(BOARD_PATH)/board.mk @@ -17,7 +18,7 @@ CFLAGS += \ # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -Wno-error=implicit-fallthrough= -MCU_DIR = hw/mcu/nxp/mcux-sdk/devices/$(MCU_VARIANT) +MCU_DIR = $(SDK_DIR)/devices/$(MCU_VARIANT) # All source paths should be relative to the top level. LD_FILE = $(MCU_DIR)/gcc/$(MCU_VARIANT)xxxxx_flexspi_nor.ld @@ -32,16 +33,19 @@ SRC_C += \ $(MCU_DIR)/xip/fsl_flexspi_nor_boot.c \ $(MCU_DIR)/project_template/clock_config.c \ $(MCU_DIR)/drivers/fsl_clock.c \ - $(MCU_DIR)/drivers/fsl_gpio.c \ - $(MCU_DIR)/drivers/fsl_common.c \ - $(MCU_DIR)/drivers/fsl_lpuart.c + $(SDK_DIR)/drivers/common/fsl_common.c \ + $(SDK_DIR)/drivers/igpio/fsl_gpio.c \ + $(SDK_DIR)/drivers/lpuart/fsl_lpuart.c INC += \ $(TOP)/$(BOARD_PATH) \ $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ $(TOP)/$(MCU_DIR) \ - $(TOP)/$(MCU_DIR)/drivers \ $(TOP)/$(MCU_DIR)/project_template \ + $(TOP)/$(MCU_DIR)/drivers \ + $(TOP)/$(SDK_DIR)/drivers/common \ + $(TOP)/$(SDK_DIR)/drivers/igpio \ + $(TOP)/$(SDK_DIR)/drivers/lpuart SRC_S += $(MCU_DIR)/gcc/startup_$(MCU_VARIANT).S From fcedb2eecb7719b1669eb9f9addcb1a08e55f18f Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 19:53:31 +0700 Subject: [PATCH 07/15] fix lpc55 build --- .../lpc55/boards/double_m33_express/board.h | 2 +- .../lpc55/boards/double_m33_express/board.mk | 1 + hw/bsp/lpc55/boards/lpcxpresso55s28/board.h | 2 +- hw/bsp/lpc55/boards/lpcxpresso55s69/board.h | 2 +- hw/bsp/lpc55/family.mk | 22 ++++++++++++------- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/hw/bsp/lpc55/boards/double_m33_express/board.h b/hw/bsp/lpc55/boards/double_m33_express/board.h index 6e43b8fc..975e74e9 100644 --- a/hw/bsp/lpc55/boards/double_m33_express/board.h +++ b/hw/bsp/lpc55/boards/double_m33_express/board.h @@ -54,7 +54,7 @@ #define UART_TX_PINMUX 0U, 30U, IOCON_PIO_DIG_FUNC1_EN // XTAL -//#define XTAL0_CLK_HZ 16000000U +#define XTAL0_CLK_HZ (16 * 1000 * 1000U) #ifdef __cplusplus } diff --git a/hw/bsp/lpc55/boards/double_m33_express/board.mk b/hw/bsp/lpc55/boards/double_m33_express/board.mk index 9bbfcc33..d28700ca 100644 --- a/hw/bsp/lpc55/boards/double_m33_express/board.mk +++ b/hw/bsp/lpc55/boards/double_m33_express/board.mk @@ -1,5 +1,6 @@ MCU_VARIANT = LPC55S69 MCU_CORE = LPC55S69_cm33_core0 +PORT ?= 1 CFLAGS += -DCPU_LPC55S69JBD100_cm33_core0 LD_FILE = $(BOARD_PATH)/LPC55S69_cm33_core0_uf2.ld diff --git a/hw/bsp/lpc55/boards/lpcxpresso55s28/board.h b/hw/bsp/lpc55/boards/lpcxpresso55s28/board.h index 10f74ec3..f85701b0 100644 --- a/hw/bsp/lpc55/boards/lpcxpresso55s28/board.h +++ b/hw/bsp/lpc55/boards/lpcxpresso55s28/board.h @@ -47,7 +47,7 @@ #define UART_TX_PINMUX 0, 30, IOCON_PIO_DIG_FUNC1_EN // XTAL -#define XTAL0_CLK_HZ 16000000U +#define XTAL0_CLK_HZ (16 * 1000 * 1000U) #ifdef __cplusplus } diff --git a/hw/bsp/lpc55/boards/lpcxpresso55s69/board.h b/hw/bsp/lpc55/boards/lpcxpresso55s69/board.h index 10f74ec3..f85701b0 100644 --- a/hw/bsp/lpc55/boards/lpcxpresso55s69/board.h +++ b/hw/bsp/lpc55/boards/lpcxpresso55s69/board.h @@ -47,7 +47,7 @@ #define UART_TX_PINMUX 0, 30, IOCON_PIO_DIG_FUNC1_EN // XTAL -#define XTAL0_CLK_HZ 16000000U +#define XTAL0_CLK_HZ (16 * 1000 * 1000U) #ifdef __cplusplus } diff --git a/hw/bsp/lpc55/family.mk b/hw/bsp/lpc55/family.mk index 6bced7ed..4e8d65ce 100644 --- a/hw/bsp/lpc55/family.mk +++ b/hw/bsp/lpc55/family.mk @@ -1,10 +1,11 @@ UF2_FAMILY_ID = 0x2abc77ec -DEPS_SUBMODULES += lib/sct_neopixel hw/mcu/nxp/mcux-sdk +SDK_DIR = hw/mcu/nxp/mcux-sdk +DEPS_SUBMODULES += lib/sct_neopixel $(SDK_DIR) include $(TOP)/$(BOARD_PATH)/board.mk -# TODO change Default to Highspeed PORT1 -PORT ?= 0 +# Default to Highspeed PORT1 +PORT ?= 1 CFLAGS += \ -flto \ @@ -30,7 +31,7 @@ endif # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -Wno-error=float-equal -MCU_DIR = hw/mcu/nxp/mcux-sdk/devices/$(MCU_VARIANT) +MCU_DIR = $(SDK_DIR)/devices/$(MCU_VARIANT) # All source paths should be relative to the top level. LD_FILE ?= $(MCU_DIR)/gcc/$(MCU_CORE)_flash.ld @@ -39,11 +40,11 @@ SRC_C += \ src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c \ $(MCU_DIR)/system_$(MCU_CORE).c \ $(MCU_DIR)/drivers/fsl_clock.c \ - $(MCU_DIR)/drivers/fsl_gpio.c \ $(MCU_DIR)/drivers/fsl_power.c \ $(MCU_DIR)/drivers/fsl_reset.c \ - $(MCU_DIR)/drivers/fsl_usart.c \ - $(MCU_DIR)/drivers/fsl_flexcomm.c \ + $(SDK_DIR)/drivers/lpc_gpio/fsl_gpio.c \ + $(SDK_DIR)/drivers/flexcomm/fsl_flexcomm.c \ + $(SDK_DIR)/drivers/flexcomm/fsl_usart.c \ lib/sct_neopixel/sct_neopixel.c INC += \ @@ -51,7 +52,12 @@ INC += \ $(TOP)/lib/sct_neopixel \ $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ $(TOP)/$(MCU_DIR) \ - $(TOP)/$(MCU_DIR)/drivers + $(TOP)/$(MCU_DIR)/drivers \ + $(TOP)/$(SDK_DIR)/drivers/common \ + $(TOP)/$(SDK_DIR)/drivers/flexcomm \ + $(TOP)/$(SDK_DIR)/drivers/lpc_iocon \ + $(TOP)/$(SDK_DIR)/drivers/lpc_gpio \ + $(TOP)/$(SDK_DIR)/drivers/sctimer SRC_S += $(MCU_DIR)/gcc/startup_$(MCU_CORE).S From 9a6552c4b33889090786a125c789eb44397f0e68 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 20:02:17 +0700 Subject: [PATCH 08/15] fix build with lpc54 --- hw/bsp/lpc54/family.mk | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hw/bsp/lpc54/family.mk b/hw/bsp/lpc54/family.mk index 862a5a7c..c6f69007 100644 --- a/hw/bsp/lpc54/family.mk +++ b/hw/bsp/lpc54/family.mk @@ -1,4 +1,5 @@ -DEPS_SUBMODULES += hw/mcu/nxp/mcux-sdk +SDK_DIR = hw/mcu/nxp/mcux-sdk +DEPS_SUBMODULES += $(SDK_DIR) include $(TOP)/$(BOARD_PATH)/board.mk @@ -16,21 +17,27 @@ CFLAGS += \ # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -MCU_DIR = hw/mcu/nxp/mcux-sdk/devices/LPC54114 +MCU_DIR = $(SDK_DIR)/devices/LPC54114 SRC_C += \ src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c \ $(MCU_DIR)/system_LPC54114_cm4.c \ $(MCU_DIR)/drivers/fsl_clock.c \ - $(MCU_DIR)/drivers/fsl_gpio.c \ $(MCU_DIR)/drivers/fsl_power.c \ - $(MCU_DIR)/drivers/fsl_reset.c + $(MCU_DIR)/drivers/fsl_reset.c \ + $(SDK_DIR)/drivers/lpc_gpio/fsl_gpio.c \ + $(SDK_DIR)/drivers/flexcomm/fsl_flexcomm.c \ + $(SDK_DIR)/drivers/flexcomm/fsl_usart.c INC += \ $(TOP)/$(BOARD_PATH) \ $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ $(TOP)/$(MCU_DIR) \ - $(TOP)/$(MCU_DIR)/drivers + $(TOP)/$(MCU_DIR)/drivers \ + $(TOP)/$(SDK_DIR)/drivers/common \ + $(TOP)/$(SDK_DIR)/drivers/flexcomm \ + $(TOP)/$(SDK_DIR)/drivers/lpc_iocon \ + $(TOP)/$(SDK_DIR)/drivers/lpc_gpio SRC_S += $(MCU_DIR)/gcc/startup_LPC54114_cm4.S From 71a1f57ccd24b61e4a35b6dcaf5df8efc76c586f Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 21:34:26 +0700 Subject: [PATCH 09/15] generalize lpc54 family --- hw/bsp/lpc54/boards/lpcxpresso54114/board.h | 59 ++++++++++++++++++++ hw/bsp/lpc54/boards/lpcxpresso54114/board.mk | 4 +- hw/bsp/lpc54/family.c | 52 ++++++++++------- hw/bsp/lpc54/family.mk | 6 +- 4 files changed, 95 insertions(+), 26 deletions(-) create mode 100644 hw/bsp/lpc54/boards/lpcxpresso54114/board.h diff --git a/hw/bsp/lpc54/boards/lpcxpresso54114/board.h b/hw/bsp/lpc54/boards/lpcxpresso54114/board.h new file mode 100644 index 00000000..b1ad4258 --- /dev/null +++ b/hw/bsp/lpc54/boards/lpcxpresso54114/board.h @@ -0,0 +1,59 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021, Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#ifndef BOARD_H_ +#define BOARD_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +// LED +#define LED_PORT 0 +#define LED_PIN 29 +#define LED_STATE_ON 0 + +// WAKE button +#define BUTTON_PORT 0 +#define BUTTON_PIN 24 +#define BUTTON_STATE_ACTIVE 0 + +// UART +#define UART_DEV USART0 +#define UART_RX_PINMUX 0, 0, IOCON_PIO_DIG_FUNC1_EN +#define UART_TX_PINMUX 0, 1, IOCON_PIO_DIG_FUNC1_EN + +// USB0 VBUS +#define USB0_VBUS_PINMUX 1, 6, IOCON_PIO_DIG_FUNC7_EN + +// XTAL +//#define XTAL0_CLK_HZ (16 * 1000 * 1000U) + +#ifdef __cplusplus + } +#endif + +#endif diff --git a/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk b/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk index 33e1a6dc..93e41471 100644 --- a/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk +++ b/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk @@ -1,5 +1,5 @@ -MCU_VARIANT = LPC55S69 -MCU_CORE = LPC55S69_cm33_core0 +MCU_VARIANT = LPC54114 +MCU_CORE = LPC54114_cm4 CFLAGS += -DCPU_LPC54114J256BD64_cm4 LD_FILE = $(MCU_DIR)/gcc/LPC54114J256_cm4_flash.ld diff --git a/hw/bsp/lpc54/family.c b/hw/bsp/lpc54/family.c index ead69cef..af352b9e 100644 --- a/hw/bsp/lpc54/family.c +++ b/hw/bsp/lpc54/family.c @@ -24,22 +24,18 @@ * This file is part of the TinyUSB stack. */ -#include "../board.h" #include "fsl_device_registers.h" #include "fsl_gpio.h" #include "fsl_power.h" #include "fsl_iocon.h" +#include "fsl_usart.h" + +#include "bsp/board.h" +#include "board.h" //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM //--------------------------------------------------------------------+ -#define LED_PORT 0 -#define LED_PIN 29 -#define LED_STATE_ON 0 - -// WAKE button -#define BUTTON_PORT 0 -#define BUTTON_PIN 24 // IOCON pin mux #define IOCON_PIO_DIGITAL_EN 0x80u // Enables digital function @@ -53,6 +49,12 @@ #define IOCON_PIO_OPENDRAIN_DI 0x00u // Open drain is disabled #define IOCON_PIO_SLEW_STANDARD 0x00u // Standard mode, output slew rate control is enabled +// Digital pin function n enabled +#define IOCON_PIO_DIG_FUNC0_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_INPFILT_OFF | IOCON_PIO_FUNC0) +#define IOCON_PIO_DIG_FUNC1_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_INPFILT_OFF | IOCON_PIO_FUNC1) +#define IOCON_PIO_DIG_FUNC4_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_INPFILT_OFF | IOCON_PIO_FUNC4) +#define IOCON_PIO_DIG_FUNC7_EN (IOCON_PIO_DIGITAL_EN | IOCON_PIO_INPFILT_OFF | IOCON_PIO_FUNC7) + //--------------------------------------------------------------------+ // Forward USB interrupt events to TinyUSB IRQ Handler //--------------------------------------------------------------------+ @@ -112,8 +114,9 @@ void board_init(void) NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); #endif - GPIO_PortInit(GPIO, LED_PORT); - GPIO_PortInit(GPIO, BUTTON_PORT); + // Init all GPIO ports + GPIO_PortInit(GPIO, 0); + GPIO_PortInit(GPIO, 1); // LED gpio_pin_config_t const led_config = { kGPIO_DigitalOutput, 0}; @@ -124,16 +127,23 @@ void board_init(void) gpio_pin_config_t const button_config = { kGPIO_DigitalInput, 0}; GPIO_PinInit(GPIO, BUTTON_PORT, BUTTON_PIN, &button_config); +#ifdef UART_DEV + // UART + IOCON_PinMuxSet(IOCON, UART_RX_PINMUX); + IOCON_PinMuxSet(IOCON, UART_TX_PINMUX); + + // Enable UART when debug log is on + CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0); + usart_config_t uart_config; + USART_GetDefaultConfig(&uart_config); + uart_config.baudRate_Bps = CFG_BOARD_UART_BAUDRATE; + uart_config.enableTx = true; + uart_config.enableRx = true; + USART_Init(UART_DEV, &uart_config, 12000000); +#endif + // USB - const uint32_t port1_pin6_config = ( - IOCON_PIO_FUNC7 | /* Pin is configured as USB0_VBUS */ - IOCON_PIO_MODE_INACT | /* No addition pin function */ - IOCON_PIO_INV_DI | /* Input function is not inverted */ - IOCON_PIO_DIGITAL_EN | /* Enables digital function */ - IOCON_PIO_INPFILT_OFF | /* Input filter disabled */ - IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */ - ); - IOCON_PinMuxSet(IOCON, 1, 6, port1_pin6_config); /* PORT1 PIN6 (coords: 26) is configured as USB0_VBUS */ + IOCON_PinMuxSet(IOCON, USB0_VBUS_PINMUX); POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*Turn on USB Phy */ CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcFro, CLOCK_GetFreq(kCLOCK_FroHf)); /* enable USB IP clock */ @@ -151,7 +161,7 @@ void board_led_write(bool state) uint32_t board_button_read(void) { // active low - return 1-GPIO_PinRead(GPIO, BUTTON_PORT, BUTTON_PIN); + return BUTTON_STATE_ACTIVE == GPIO_PinRead(GPIO, BUTTON_PORT, BUTTON_PIN); } int board_uart_read(uint8_t* buf, int len) @@ -162,7 +172,7 @@ int board_uart_read(uint8_t* buf, int len) int board_uart_write(void const * buf, int len) { - (void) buf; (void) len; + USART_WriteBlocking(UART_DEV, (uint8_t *)buf, len); return 0; } diff --git a/hw/bsp/lpc54/family.mk b/hw/bsp/lpc54/family.mk index c6f69007..8e501f59 100644 --- a/hw/bsp/lpc54/family.mk +++ b/hw/bsp/lpc54/family.mk @@ -17,11 +17,11 @@ CFLAGS += \ # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -MCU_DIR = $(SDK_DIR)/devices/LPC54114 +MCU_DIR = $(SDK_DIR)/devices/$(MCU_VARIANT) SRC_C += \ src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c \ - $(MCU_DIR)/system_LPC54114_cm4.c \ + $(MCU_DIR)/system_$(MCU_CORE).c \ $(MCU_DIR)/drivers/fsl_clock.c \ $(MCU_DIR)/drivers/fsl_power.c \ $(MCU_DIR)/drivers/fsl_reset.c \ @@ -39,7 +39,7 @@ INC += \ $(TOP)/$(SDK_DIR)/drivers/lpc_iocon \ $(TOP)/$(SDK_DIR)/drivers/lpc_gpio -SRC_S += $(MCU_DIR)/gcc/startup_LPC54114_cm4.S +SRC_S += $(MCU_DIR)/gcc/startup_$(MCU_CORE).S LIBS += $(TOP)/$(MCU_DIR)/gcc/libpower_cm4_hardabi.a From 8a9f41278831ec2d97953df95f5685a7145ec1dc Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 22:34:56 +0700 Subject: [PATCH 10/15] fix lpc54 button --- hw/bsp/lpc54/boards/lpcxpresso54114/board.mk | 2 ++ hw/bsp/lpc54/family.c | 8 ++++---- hw/bsp/lpc54/family.mk | 3 --- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk b/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk index 93e41471..6e33d8cb 100644 --- a/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk +++ b/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk @@ -4,6 +4,8 @@ MCU_CORE = LPC54114_cm4 CFLAGS += -DCPU_LPC54114J256BD64_cm4 LD_FILE = $(MCU_DIR)/gcc/LPC54114J256_cm4_flash.ld +LIBS += $(TOP)/$(MCU_DIR)/gcc/libpower_cm4_hardabi.a + JLINK_DEVICE = LPC54114J256_M4 PYOCD_TARGET = LPC54114 diff --git a/hw/bsp/lpc54/family.c b/hw/bsp/lpc54/family.c index af352b9e..b1e2ca35 100644 --- a/hw/bsp/lpc54/family.c +++ b/hw/bsp/lpc54/family.c @@ -100,9 +100,6 @@ void board_init(void) // Enable IOCON clock CLOCK_EnableClock(kCLOCK_Iocon); - // Enable GPIO0 clock - CLOCK_EnableClock(kCLOCK_Gpio0); - // Init 96 MHz clock BootClockFROHF96M(); @@ -114,16 +111,19 @@ void board_init(void) NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); #endif - // Init all GPIO ports + // Init all GPIO ports 54114 only has 2 ports. GPIO_PortInit(GPIO, 0); GPIO_PortInit(GPIO, 1); + //GPIO_PortInit(GPIO, 2); // LED + IOCON_PinMuxSet(IOCON, LED_PORT, LED_PIN, IOCON_PIO_DIG_FUNC0_EN); gpio_pin_config_t const led_config = { kGPIO_DigitalOutput, 0}; GPIO_PinInit(GPIO, LED_PORT, LED_PIN, &led_config); board_led_write(true); // Button + IOCON_PinMuxSet(IOCON, BUTTON_PORT, BUTTON_PIN, IOCON_PIO_DIG_FUNC0_EN | IOCON_PIO_MODE_PULLUP); gpio_pin_config_t const button_config = { kGPIO_DigitalInput, 0}; GPIO_PinInit(GPIO, BUTTON_PORT, BUTTON_PIN, &button_config); diff --git a/hw/bsp/lpc54/family.mk b/hw/bsp/lpc54/family.mk index 8e501f59..26fbfc54 100644 --- a/hw/bsp/lpc54/family.mk +++ b/hw/bsp/lpc54/family.mk @@ -11,7 +11,6 @@ CFLAGS += \ -mfloat-abi=hard \ -mfpu=fpv4-sp-d16 \ -DCFG_TUSB_MCU=OPT_MCU_LPC54XXX \ - -DCFG_TUSB_MEM_SECTION='__attribute__((section(".data")))' \ -DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))' # mcu driver cause following warnings @@ -41,7 +40,5 @@ INC += \ SRC_S += $(MCU_DIR)/gcc/startup_$(MCU_CORE).S -LIBS += $(TOP)/$(MCU_DIR)/gcc/libpower_cm4_hardabi.a - # For freeRTOS port source FREERTOS_PORT = ARM_CM4F From fdda9f75db72a2c0ea0cd120a7196105d458a215 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 23:24:37 +0700 Subject: [PATCH 11/15] add lpc54628 but usb clock;phy doesn't seem to be right --- hw/bsp/lpc54/boards/lpcxpresso54628/board.h | 59 ++++++++++++++++++++ hw/bsp/lpc54/boards/lpcxpresso54628/board.mk | 18 ++++++ hw/bsp/lpc54/family.c | 48 ++++++++++++++-- hw/bsp/lpc54/family.mk | 10 ++++ 4 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 hw/bsp/lpc54/boards/lpcxpresso54628/board.h create mode 100644 hw/bsp/lpc54/boards/lpcxpresso54628/board.mk diff --git a/hw/bsp/lpc54/boards/lpcxpresso54628/board.h b/hw/bsp/lpc54/boards/lpcxpresso54628/board.h new file mode 100644 index 00000000..67027751 --- /dev/null +++ b/hw/bsp/lpc54/boards/lpcxpresso54628/board.h @@ -0,0 +1,59 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021, Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#ifndef BOARD_H_ +#define BOARD_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +// LED +#define LED_PORT 2 +#define LED_PIN 2 +#define LED_STATE_ON 0 + +// WAKE button +#define BUTTON_PORT 1 +#define BUTTON_PIN 1 +#define BUTTON_STATE_ACTIVE 0 + +// UART +#define UART_DEV USART0 +#define UART_RX_PINMUX 0, 29, IOCON_PIO_DIG_FUNC1_EN +#define UART_TX_PINMUX 0, 30, IOCON_PIO_DIG_FUNC1_EN + +// USB0 VBUS +#define USB0_VBUS_PINMUX 0, 22, IOCON_PIO_DIG_FUNC7_EN + +// XTAL +//#define XTAL0_CLK_HZ (16 * 1000 * 1000U) + +#ifdef __cplusplus + } +#endif + +#endif diff --git a/hw/bsp/lpc54/boards/lpcxpresso54628/board.mk b/hw/bsp/lpc54/boards/lpcxpresso54628/board.mk new file mode 100644 index 00000000..925374cc --- /dev/null +++ b/hw/bsp/lpc54/boards/lpcxpresso54628/board.mk @@ -0,0 +1,18 @@ +MCU_VARIANT = LPC54628 +MCU_CORE = LPC54628 + +PORT ?= 0 + +CFLAGS += -DCPU_LPC54628J512ET180 +CFLAGS += -Wno-error=double-promotion + +LD_FILE = $(MCU_DIR)/gcc/LPC54628J512_flash.ld + +LIBS += $(TOP)/$(MCU_DIR)/gcc/libpower_hardabi.a + +JLINK_DEVICE = LPC54628J512 +PYOCD_TARGET = LPC54628 + +#flash: flash-pyocd + +flash: flash-jlink \ No newline at end of file diff --git a/hw/bsp/lpc54/family.c b/hw/bsp/lpc54/family.c index b1e2ca35..4789425a 100644 --- a/hw/bsp/lpc54/family.c +++ b/hw/bsp/lpc54/family.c @@ -63,6 +63,11 @@ void USB0_IRQHandler(void) tud_int_handler(0); } +void USB1_IRQHandler(void) +{ + tud_int_handler(1); +} + /**************************************************************** name: BOARD_BootClockFROHF96M outputs: @@ -112,15 +117,15 @@ void board_init(void) #endif // Init all GPIO ports 54114 only has 2 ports. - GPIO_PortInit(GPIO, 0); - GPIO_PortInit(GPIO, 1); - //GPIO_PortInit(GPIO, 2); + GPIO_PortInit(GPIO, LED_PORT); + GPIO_PortInit(GPIO, BUTTON_PORT); // LED IOCON_PinMuxSet(IOCON, LED_PORT, LED_PIN, IOCON_PIO_DIG_FUNC0_EN); gpio_pin_config_t const led_config = { kGPIO_DigitalOutput, 0}; GPIO_PinInit(GPIO, LED_PORT, LED_PIN, &led_config); - board_led_write(true); + + board_led_write(0); // Button IOCON_PinMuxSet(IOCON, BUTTON_PORT, BUTTON_PIN, IOCON_PIO_DIG_FUNC0_EN | IOCON_PIO_MODE_PULLUP); @@ -145,8 +150,41 @@ void board_init(void) // USB IOCON_PinMuxSet(IOCON, USB0_VBUS_PINMUX); - POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*Turn on USB Phy */ +#if defined(FSL_FEATURE_SOC_USBHSD_COUNT) && FSL_FEATURE_SOC_USBHSD_COUNT + // LPC546xx and LPC540xx has OTG 1 FS + 1 HS rhports + + #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE + // Port0 is Full Speed + POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*< Turn on USB Phy */ + CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1, false); + CLOCK_AttachClk(kFRO_HF_to_USB0_CLK); + + /*According to reference mannual, device mode setting has to be set by access usb host register */ + CLOCK_EnableClock(kCLOCK_Usbhsl0); /* enable usb0 host clock */ + USBFSH->PORTMODE |= USBFSH_PORTMODE_DEV_ENABLE_MASK; + CLOCK_DisableClock(kCLOCK_Usbhsl0); /* disable usb0 host clock */ + + CLOCK_EnableUsbfs0DeviceClock(kCLOCK_UsbSrcFro, CLOCK_GetFroHfFreq()); + #endif + + #if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE + // Port1 is High Speed + POWER_DisablePD(kPDRUNCFG_PD_USB1_PHY); + + /*According to reference mannual, device mode setting has to be set by access usb host register */ + CLOCK_EnableClock(kCLOCK_Usbh1); /* enable usb1 host clock */ + USBHSH->PORTMODE |= USBHSH_PORTMODE_DEV_ENABLE_MASK; + CLOCK_DisableClock(kCLOCK_Usbh1); /* enable usb1 host clock */ + + CLOCK_EnableUsbhs0DeviceClock(kCLOCK_UsbSrcUsbPll, 0U); + #endif + +#else + // LPC5411x series only has full speed device + + POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); // Turn on USB Phy CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcFro, CLOCK_GetFreq(kCLOCK_FroHf)); /* enable USB IP clock */ +#endif } //--------------------------------------------------------------------+ diff --git a/hw/bsp/lpc54/family.mk b/hw/bsp/lpc54/family.mk index 26fbfc54..600df6fd 100644 --- a/hw/bsp/lpc54/family.mk +++ b/hw/bsp/lpc54/family.mk @@ -13,6 +13,16 @@ CFLAGS += \ -DCFG_TUSB_MCU=OPT_MCU_LPC54XXX \ -DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))' +ifeq ($(PORT), 1) + $(info "PORT1 High Speed") + CFLAGS += -DBOARD_DEVICE_RHPORT_SPEED=OPT_MODE_HIGH_SPEED + + # LPC55 Highspeed Port1 can only write to USB_SRAM region + CFLAGS += -DCFG_TUSB_MEM_SECTION='__attribute__((section("m_usb_global")))' +else + $(info "PORT0 Full Speed") +endif + # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter From f7779c70d67bb60a35d5d399aa97d93bfa93494e Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 23:27:12 +0700 Subject: [PATCH 12/15] add lpc54 to ci --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c88722b2..187b7d4a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,7 @@ jobs: - 'imxrt' - 'lpc15' - 'lpc18' + - 'lpc54' - 'lpc55' - 'nrf' - 'rp2040' From d70af332c02a7093fdd0636f6ceb14abd1f74004 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 23:44:04 +0700 Subject: [PATCH 13/15] fixed build with lpc51 --- hw/bsp/lpcxpresso51u68/board.mk | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hw/bsp/lpcxpresso51u68/board.mk b/hw/bsp/lpcxpresso51u68/board.mk index 21b6c55f..98bef675 100644 --- a/hw/bsp/lpcxpresso51u68/board.mk +++ b/hw/bsp/lpcxpresso51u68/board.mk @@ -1,4 +1,5 @@ -DEPS_SUBMODULES += hw/mcu/nxp/mcux-sdk +SDK_DIR = hw/mcu/nxp/mcux-sdk +DEPS_SUBMODULES += $(SDK_DIR) CFLAGS += \ -flto \ @@ -13,7 +14,7 @@ CFLAGS += \ # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -MCU_DIR = hw/mcu/nxp/mcux-sdk/devices/LPC51U68 +MCU_DIR = $(SDK_DIR)/devices/LPC51U68 # All source paths should be relative to the top level. LD_FILE = $(MCU_DIR)/gcc/LPC51U68_flash.ld @@ -22,14 +23,20 @@ SRC_C += \ src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c \ $(MCU_DIR)/system_LPC51U68.c \ $(MCU_DIR)/drivers/fsl_clock.c \ - $(MCU_DIR)/drivers/fsl_gpio.c \ $(MCU_DIR)/drivers/fsl_power.c \ - $(MCU_DIR)/drivers/fsl_reset.c + $(MCU_DIR)/drivers/fsl_reset.c \ + $(SDK_DIR)/drivers/lpc_gpio/fsl_gpio.c \ + $(SDK_DIR)/drivers/flexcomm/fsl_flexcomm.c \ + $(SDK_DIR)/drivers/flexcomm/fsl_usart.c INC += \ $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ $(TOP)/$(MCU_DIR) \ - $(TOP)/$(MCU_DIR)/drivers + $(TOP)/$(MCU_DIR)/drivers \ + $(TOP)/$(SDK_DIR)/drivers/common \ + $(TOP)/$(SDK_DIR)/drivers/flexcomm \ + $(TOP)/$(SDK_DIR)/drivers/lpc_iocon \ + $(TOP)/$(SDK_DIR)/drivers/lpc_gpio SRC_S += $(MCU_DIR)/gcc/startup_LPC51U68.S @@ -38,9 +45,8 @@ LIBS += $(TOP)/$(MCU_DIR)/gcc/libpower.a # For freeRTOS port source FREERTOS_PORT = ARM_CM0 -# For flash-jlink target JLINK_DEVICE = LPC51U68 +PYOCD_TARGET = LPC51U68 # flash using pyocd (51u68 is not supported yet) -flash: $(BUILD)/$(PROJECT).hex - pyocd flash -t LPC51U68 $< +flash: flash-pyocd From cf64b2214b9ac3cd6815af6ddc48b1cd0f075590 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 29 Apr 2021 00:22:28 +0700 Subject: [PATCH 14/15] fix build with mkl25z --- .gitmodules | 3 +++ hw/bsp/frdm_kl25z/board.mk | 7 ++++--- hw/mcu/nxp/nxp_sdk | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) create mode 160000 hw/mcu/nxp/nxp_sdk diff --git a/.gitmodules b/.gitmodules index f9edcebd..79ef8e0a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -118,3 +118,6 @@ [submodule "hw/mcu/nxp/mcux-sdk"] path = hw/mcu/nxp/mcux-sdk url = https://github.com/NXPmicro/mcux-sdk.git +[submodule "hw/mcu/nxp/nxp_sdk"] + path = hw/mcu/nxp/nxp_sdk + url = https://github.com/hathach/nxp_sdk.git diff --git a/hw/bsp/frdm_kl25z/board.mk b/hw/bsp/frdm_kl25z/board.mk index 2e973b98..cec722f8 100644 --- a/hw/bsp/frdm_kl25z/board.mk +++ b/hw/bsp/frdm_kl25z/board.mk @@ -1,4 +1,5 @@ -DEPS_SUBMODULES += hw/mcu/nxp/mcux-sdk +SDK_DIR = hw/mcu/nxp/nxp_sdk +DEPS_SUBMODULES += $(SDK_DIR) CFLAGS += \ -mthumb \ @@ -10,7 +11,7 @@ CFLAGS += \ # mcu driver cause following warnings CFLAGS += -Wno-error=unused-parameter -MCU_DIR = hw/mcu/nxp/mcux-sdk/devices/MKL25Z4 +MCU_DIR = $(SDK_DIR)/devices/MKL25Z4 # All source paths should be relative to the top level. LD_FILE = $(MCU_DIR)/gcc/MKL25Z128xxx4_flash.ld @@ -25,7 +26,7 @@ SRC_C += \ INC += \ $(TOP)/hw/bsp/$(BOARD) \ - $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ + $(TOP)/hw/mcu/nxp/mcux-sdk/CMSIS/Include \ $(TOP)/$(MCU_DIR) \ $(TOP)/$(MCU_DIR)/drivers \ $(TOP)/$(MCU_DIR)/project_template \ diff --git a/hw/mcu/nxp/nxp_sdk b/hw/mcu/nxp/nxp_sdk new file mode 160000 index 00000000..b4e85c43 --- /dev/null +++ b/hw/mcu/nxp/nxp_sdk @@ -0,0 +1 @@ +Subproject commit b4e85c4353af401dbf5a0a17be673530248fca23 From e70fb7fd418cfceef693dfa7df43ebc460b46ec8 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 29 Apr 2021 00:33:03 +0700 Subject: [PATCH 15/15] fix mkl25z ci --- hw/bsp/frdm_kl25z/board.mk | 2 +- hw/mcu/nxp/nxp_sdk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/bsp/frdm_kl25z/board.mk b/hw/bsp/frdm_kl25z/board.mk index cec722f8..451bc37c 100644 --- a/hw/bsp/frdm_kl25z/board.mk +++ b/hw/bsp/frdm_kl25z/board.mk @@ -26,7 +26,7 @@ SRC_C += \ INC += \ $(TOP)/hw/bsp/$(BOARD) \ - $(TOP)/hw/mcu/nxp/mcux-sdk/CMSIS/Include \ + $(TOP)/$(SDK_DIR)/CMSIS/Include \ $(TOP)/$(MCU_DIR) \ $(TOP)/$(MCU_DIR)/drivers \ $(TOP)/$(MCU_DIR)/project_template \ diff --git a/hw/mcu/nxp/nxp_sdk b/hw/mcu/nxp/nxp_sdk index b4e85c43..845c8fc4 160000 --- a/hw/mcu/nxp/nxp_sdk +++ b/hw/mcu/nxp/nxp_sdk @@ -1 +1 @@ -Subproject commit b4e85c4353af401dbf5a0a17be673530248fca23 +Subproject commit 845c8fc49b6fb660f06a5c45225494eacb06f00c