From 3da76ae4495cc16a4eed5882122efad696e2270c Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 15:58:43 +0700 Subject: making new family lpc54 --- hw/bsp/lpc54/boards/lpcxpresso54114/board.mk | 11 ++ hw/bsp/lpc54/family.c | 180 +++++++++++++++++++++++++++ hw/bsp/lpc54/family.mk | 40 ++++++ hw/bsp/lpc55/family.c | 28 ++--- hw/bsp/lpcxpresso54114/board.mk | 48 ------- hw/bsp/lpcxpresso54114/lpcxpresso54114.c | 180 --------------------------- 6 files changed, 245 insertions(+), 242 deletions(-) create mode 100644 hw/bsp/lpc54/boards/lpcxpresso54114/board.mk create mode 100644 hw/bsp/lpc54/family.c create mode 100644 hw/bsp/lpc54/family.mk delete mode 100644 hw/bsp/lpcxpresso54114/board.mk delete mode 100644 hw/bsp/lpcxpresso54114/lpcxpresso54114.c diff --git a/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk b/hw/bsp/lpc54/boards/lpcxpresso54114/board.mk new file mode 100644 index 000000000..33e1a6dc0 --- /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/lpc54/family.c b/hw/bsp/lpc54/family.c new file mode 100644 index 000000000..ead69cef2 --- /dev/null +++ b/hw/bsp/lpc54/family.c @@ -0,0 +1,180 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018, hathach (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. + */ + +#include "../board.h" +#include "fsl_device_registers.h" +#include "fsl_gpio.h" +#include "fsl_power.h" +#include "fsl_iocon.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 +#define IOCON_PIO_FUNC0 0x00u +#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 // 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 +outputs: +- {id: SYSTICK_clock.outFreq, value: 96 MHz} +- {id: System_clock.outFreq, value: 96 MHz} +settings: +- {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf} +sources: +- {id: SYSCON.fro_hf.outFreq, value: 96 MHz} +******************************************************************/ +void BootClockFROHF96M(void) +{ + /*!< Set up the clock sources */ + /*!< Set up FRO */ + POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */ + CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without + accidentally being below the voltage for current speed */ + POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */ + CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */ + + CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */ + + /*!< Set up dividers */ + CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */ + + /*!< Set up clock selectors - Attach clocks to the peripheries */ + CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */ + + /*!< Set SystemCoreClock variable. */ + SystemCoreClock = 96000000U; +} + +void board_init(void) +{ + // Enable IOCON clock + CLOCK_EnableClock(kCLOCK_Iocon); + + // Enable GPIO0 clock + CLOCK_EnableClock(kCLOCK_Gpio0); + + // Init 96 MHz clock + BootClockFROHF96M(); + + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000); + +#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 + + GPIO_PortInit(GPIO, LED_PORT); + GPIO_PortInit(GPIO, BUTTON_PORT); + + // LED + gpio_pin_config_t const led_config = { kGPIO_DigitalOutput, 0}; + GPIO_PinInit(GPIO, LED_PORT, LED_PIN, &led_config); + board_led_write(true); + + // Button + gpio_pin_config_t const button_config = { kGPIO_DigitalInput, 0}; + GPIO_PinInit(GPIO, BUTTON_PORT, BUTTON_PIN, &button_config); + + // 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 */ + + POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*Turn on USB Phy */ + CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcFro, CLOCK_GetFreq(kCLOCK_FroHf)); /* enable USB IP clock */ +} + +//--------------------------------------------------------------------+ +// Board porting API +//--------------------------------------------------------------------+ + +void board_led_write(bool state) +{ + GPIO_PinWrite(GPIO, LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON)); +} + +uint32_t board_button_read(void) +{ + // active low + return 1-GPIO_PinRead(GPIO, BUTTON_PORT, BUTTON_PIN); +} + +int board_uart_read(uint8_t* buf, int len) +{ + (void) buf; (void) len; + return 0; +} + +int board_uart_write(void const * buf, int len) +{ + (void) buf; (void) len; + return 0; +} + +#if CFG_TUSB_OS == OPT_OS_NONE +volatile uint32_t system_ticks = 0; +void SysTick_Handler(void) +{ + system_ticks++; +} + +uint32_t board_millis(void) +{ + return system_ticks; +} +#endif diff --git a/hw/bsp/lpc54/family.mk b/hw/bsp/lpc54/family.mk new file mode 100644 index 000000000..969d1ae2a --- /dev/null +++ b/hw/bsp/lpc54/family.mk @@ -0,0 +1,40 @@ +DEPS_SUBMODULES += hw/mcu/nxp + +include $(TOP)/$(BOARD_PATH)/board.mk + +CFLAGS += \ + -flto \ + -mthumb \ + -mabi=aapcs \ + -mcpu=cortex-m4 \ + -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 +CFLAGS += -Wno-error=unused-parameter + +MCU_DIR = hw/mcu/nxp/sdk/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 + +INC += \ + $(TOP)/$(BOARD_PATH) \ + $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ + $(TOP)/$(MCU_DIR) \ + $(TOP)/$(MCU_DIR)/drivers + +SRC_S += $(MCU_DIR)/gcc/startup_LPC54114_cm4.S + +LIBS += $(TOP)/$(MCU_DIR)/gcc/libpower_cm4_hardabi.a + +# For freeRTOS port source +FREERTOS_PORT = ARM_CM4F diff --git a/hw/bsp/lpc55/family.c b/hw/bsp/lpc55/family.c index 890c2f5c5..4fc1f6222 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_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_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) // 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 diff --git a/hw/bsp/lpcxpresso54114/board.mk b/hw/bsp/lpcxpresso54114/board.mk deleted file mode 100644 index b6bc07615..000000000 --- a/hw/bsp/lpcxpresso54114/board.mk +++ /dev/null @@ -1,48 +0,0 @@ -DEPS_SUBMODULES += hw/mcu/nxp - -CFLAGS += \ - -flto \ - -mthumb \ - -mabi=aapcs \ - -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)))' - -# mcu driver cause following warnings -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 \ - $(MCU_DIR)/drivers/fsl_clock.c \ - $(MCU_DIR)/drivers/fsl_gpio.c \ - $(MCU_DIR)/drivers/fsl_power.c \ - $(MCU_DIR)/drivers/fsl_reset.c - -INC += \ - $(TOP)/$(MCU_DIR)/../../CMSIS/Include \ - $(TOP)/$(MCU_DIR) \ - $(TOP)/$(MCU_DIR)/drivers - -SRC_S += $(MCU_DIR)/gcc/startup_LPC54114_cm4.S - -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/lpcxpresso54114/lpcxpresso54114.c b/hw/bsp/lpcxpresso54114/lpcxpresso54114.c deleted file mode 100644 index 3bccc4bd7..000000000 --- a/hw/bsp/lpcxpresso54114/lpcxpresso54114.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018, hathach (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. - */ - -#include "../board.h" -#include "fsl_device_registers.h" -#include "fsl_gpio.h" -#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 -//--------------------------------------------------------------------+ -#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 /*!<@brief 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_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 */ - -/**************************************************************** -name: BOARD_BootClockFROHF96M -outputs: -- {id: SYSTICK_clock.outFreq, value: 96 MHz} -- {id: System_clock.outFreq, value: 96 MHz} -settings: -- {id: SYSCON.MAINCLKSELA.sel, value: SYSCON.fro_hf} -sources: -- {id: SYSCON.fro_hf.outFreq, value: 96 MHz} -******************************************************************/ -void BootClockFROHF96M(void) -{ - /*!< Set up the clock sources */ - /*!< Set up FRO */ - POWER_DisablePD(kPDRUNCFG_PD_FRO_EN); /*!< Ensure FRO is on */ - CLOCK_AttachClk(kFRO12M_to_MAIN_CLK); /*!< Switch to FRO 12MHz first to ensure we can change voltage without - accidentally being below the voltage for current speed */ - POWER_SetVoltageForFreq(96000000U); /*!< Set voltage for the one of the fastest clock outputs: System clock output */ - CLOCK_SetFLASHAccessCyclesForFreq(96000000U); /*!< Set FLASH wait states for core */ - - CLOCK_SetupFROClocking(96000000U); /*!< Set up high frequency FRO output to selected frequency */ - - /*!< Set up dividers */ - CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false); /*!< Set AHBCLKDIV divider to value 1 */ - - /*!< Set up clock selectors - Attach clocks to the peripheries */ - CLOCK_AttachClk(kFRO_HF_to_MAIN_CLK); /*!< Switch MAIN_CLK to FRO_HF */ - - /*!< Set SystemCoreClock variable. */ - SystemCoreClock = 96000000U; -} - -void board_init(void) -{ - // Enable IOCON clock - CLOCK_EnableClock(kCLOCK_Iocon); - - // Enable GPIO0 clock - CLOCK_EnableClock(kCLOCK_Gpio0); - - // 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 freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher ) - NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); -#endif - - GPIO_PortInit(GPIO, LED_PORT); - GPIO_PortInit(GPIO, BUTTON_PORT); - - // LED - gpio_pin_config_t const led_config = { kGPIO_DigitalOutput, 0}; - GPIO_PinInit(GPIO, LED_PORT, LED_PIN, &led_config); - board_led_write(true); - - // Button - gpio_pin_config_t const button_config = { kGPIO_DigitalInput, 0}; - GPIO_PinInit(GPIO, BUTTON_PORT, BUTTON_PIN, &button_config); - - // 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 */ - - POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*Turn on USB Phy */ - CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcFro, CLOCK_GetFreq(kCLOCK_FroHf)); /* enable USB IP clock */ -} - -//--------------------------------------------------------------------+ -// Board porting API -//--------------------------------------------------------------------+ - -void board_led_write(bool state) -{ - GPIO_PinWrite(GPIO, LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON)); -} - -uint32_t board_button_read(void) -{ - // active low - return 1-GPIO_PinRead(GPIO, BUTTON_PORT, BUTTON_PIN); -} - -int board_uart_read(uint8_t* buf, int len) -{ - (void) buf; (void) len; - return 0; -} - -int board_uart_write(void const * buf, int len) -{ - (void) buf; (void) len; - return 0; -} - -#if CFG_TUSB_OS == OPT_OS_NONE -volatile uint32_t system_ticks = 0; -void SysTick_Handler(void) -{ - system_ticks++; -} - -uint32_t board_millis(void) -{ - return system_ticks; -} -#endif -- cgit v1.3.1 From 62c5fa10567a6cb68ed53961022b4d3b054d9de6 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 18:07:26 +0700 Subject: 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 6cceee43f..e2140ee16 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 587c65766..000000000 --- a/hw/mcu/nxp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 587c65766538a5e1cfb6188ac611ded61f2eb859 -- cgit v1.3.1 From e115e087281bf1c52f4c67d1bec3f6a778acce15 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 18:11:49 +0700 Subject: 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 e2140ee16..087cf963b 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 05e730d29..c624a5cf2 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 1ad970579..86391ab5d 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 90e8ca504..e80a3bc51 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 0908e1877..3fed0b45a 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 7fa42f9a5..8fcda51ee 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 b59506d4a..922414f82 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 0f63cefb4..0d56a33a6 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 678c703dc..b69be39bd 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 bd48b29ba..e99df9f08 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 0a0cb3ba6..04c37feeb 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 000000000..43c45c854 --- /dev/null +++ b/hw/mcu/nxp/lpcopen @@ -0,0 +1 @@ +Subproject commit 43c45c85405a5dd114fff0ea95cca62837740c13 -- cgit v1.3.1 From aaa8c9928c2b560f60f7e4f70bc8d8d2eb5eb0eb Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 18:26:04 +0700 Subject: 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 087cf963b..f9edcebd8 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 000000000..cb21c6609 --- /dev/null +++ b/hw/mcu/nxp/mcux-sdk @@ -0,0 +1 @@ +Subproject commit cb21c660991c92e90ece99ccb63a4bc611899c3a -- cgit v1.3.1 From af0db342df37932511521a1a4b45c7bc31de03f2 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 18:30:19 +0700 Subject: 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 1a4d718cf..2e973b98d 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 1b6d7e8d6..6ebc0e260 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 969d1ae2a..862a5a7c9 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 46923cc4f..6bced7ed7 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 2582e98f2..21b6c55fc 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 -- cgit v1.3.1 From 810057bdb2b0b2d62a7f4ae9f394f46f58862be2 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 19:30:23 +0700 Subject: 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 c6b1a3159..77a224a5e 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 6ebc0e260..a919d3698 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 -- cgit v1.3.1 From fcedb2eecb7719b1669eb9f9addcb1a08e55f18f Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 19:53:31 +0700 Subject: fix lpc55 build --- hw/bsp/lpc55/boards/double_m33_express/board.h | 2 +- hw/bsp/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 6e43b8fc5..975e74e92 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 9bbfcc330..d28700ca7 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 10f74ec3f..f85701b08 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 10f74ec3f..f85701b08 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 6bced7ed7..4e8d65ce9 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 -- cgit v1.3.1 From 9a6552c4b33889090786a125c789eb44397f0e68 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 20:02:17 +0700 Subject: 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 862a5a7c9..c6f690076 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 -- cgit v1.3.1 From 71a1f57ccd24b61e4a35b6dcaf5df8efc76c586f Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 21:34:26 +0700 Subject: 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 000000000..b1ad4258c --- /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 33e1a6dc0..93e414713 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 ead69cef2..af352b9eb 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 c6f690076..8e501f59a 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 -- cgit v1.3.1 From 8a9f41278831ec2d97953df95f5685a7145ec1dc Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 22:34:56 +0700 Subject: 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 93e414713..6e33d8cbe 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 af352b9eb..b1e2ca356 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 8e501f59a..26fbfc54c 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 -- cgit v1.3.1 From fdda9f75db72a2c0ea0cd120a7196105d458a215 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 23:24:37 +0700 Subject: 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 000000000..670277512 --- /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 000000000..925374cc8 --- /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 b1e2ca356..4789425a3 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 26fbfc54c..600df6fd0 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 -- cgit v1.3.1 From f7779c70d67bb60a35d5d399aa97d93bfa93494e Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 23:27:12 +0700 Subject: 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 c88722b2a..187b7d4a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,7 @@ jobs: - 'imxrt' - 'lpc15' - 'lpc18' + - 'lpc54' - 'lpc55' - 'nrf' - 'rp2040' -- cgit v1.3.1 From d70af332c02a7093fdd0636f6ceb14abd1f74004 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 23:44:04 +0700 Subject: 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 21b6c55fc..98bef6758 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 -- cgit v1.3.1 From cf64b2214b9ac3cd6815af6ddc48b1cd0f075590 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 29 Apr 2021 00:22:28 +0700 Subject: 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 f9edcebd8..79ef8e0ad 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 2e973b98d..cec722f85 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 000000000..b4e85c435 --- /dev/null +++ b/hw/mcu/nxp/nxp_sdk @@ -0,0 +1 @@ +Subproject commit b4e85c4353af401dbf5a0a17be673530248fca23 -- cgit v1.3.1 From e70fb7fd418cfceef693dfa7df43ebc460b46ec8 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 29 Apr 2021 00:33:03 +0700 Subject: 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 cec722f85..451bc37c2 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 b4e85c435..845c8fc49 160000 --- a/hw/mcu/nxp/nxp_sdk +++ b/hw/mcu/nxp/nxp_sdk @@ -1 +1 @@ -Subproject commit b4e85c4353af401dbf5a0a17be673530248fca23 +Subproject commit 845c8fc49b6fb660f06a5c45225494eacb06f00c -- cgit v1.3.1