From 71a1f57ccd24b61e4a35b6dcaf5df8efc76c586f Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Apr 2021 21:34:26 +0700 Subject: [PATCH] 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