summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Paddock <[email protected]>2023-01-16 15:05:31 -0500
committerhathach <[email protected]>2023-03-18 16:50:50 +0700
commitf9b8a0667a2cc42a6c6521c51bba695ca8e9e28f (patch)
tree606528814e5fb64a9eb20db3656ad86da0cab9f4
parentf1a859d90701564dc6e152197454fae1f49ee846 (diff)
Add support for NXP FRDM_K32L2A4S eval board.
-rw-r--r--hw/bsp/board_mcu.h2
-rw-r--r--hw/bsp/frdm_k32l2a4s/README.rst51
-rw-r--r--hw/bsp/frdm_k32l2a4s/board.h58
-rw-r--r--hw/bsp/frdm_k32l2a4s/board.mk80
-rw-r--r--hw/bsp/frdm_k32l2a4s/frdm_k32l2a4s.c171
-rw-r--r--src/common/tusb_mcu.h2
-rw-r--r--src/portable/nxp/khci/dcd_khci.c9
-rw-r--r--src/portable/nxp/khci/hcd_khci.c9
-rw-r--r--src/tusb_option.h1
9 files changed, 375 insertions, 8 deletions
diff --git a/hw/bsp/board_mcu.h b/hw/bsp/board_mcu.h
index b34197e6c..920e7d0d9 100644
--- a/hw/bsp/board_mcu.h
+++ b/hw/bsp/board_mcu.h
@@ -47,7 +47,7 @@
#elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX || CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \
CFG_TUSB_MCU == OPT_MCU_LPC55XX || CFG_TUSB_MCU == OPT_MCU_MKL25ZXX || \
- CFG_TUSB_MCU == OPT_MCU_K32L2BXX
+ CFG_TUSB_MCU == OPT_MCU_K32L2AXX || OPT_MCU_K32L2BXX
#include "fsl_device_registers.h"
#elif CFG_TUSB_MCU == OPT_MCU_NRF5X
diff --git a/hw/bsp/frdm_k32l2a4s/README.rst b/hw/bsp/frdm_k32l2a4s/README.rst
new file mode 100644
index 000000000..68ab409c3
--- /dev/null
+++ b/hw/bsp/frdm_k32l2a4s/README.rst
@@ -0,0 +1,51 @@
+Jan/13/2023 13:04
+
+The FRDM-K32L2B3 Freedom development board provides a platform for
+evaluation and development of the K32 L2B MCU Family. -
+https://www.nxp.com/part/FRDM-K32L2B3#/
+
+TinyUSB does not include the board specific drivers. Those drivers
+need to be extracted from the MCUXpresso IDE and SDK.
+
+Install MCUXPresso version 11.6 or later and SDK 2.12 or later. Then
+build the example project "frdmk32l2b_hellow_worldvirual_com".
+
+From the frdmk32l2b_hellow_worldvirual_com project copy these files to
+this directory structure, in this directory:
+
+hw/mcu/nxp/mcux-sdk/devices/K32L2B31A
+
+CMSIS/
+config/
+drivers/
+gcc/
+fsl_device_registers.h
+K32L2B31A_features.h
+K32L2B31A.h
+
+./CMSIS:
+cmsis_armcc.h cmsis_armclang_ltm.h cmsis_gcc.h cmsis_version.h mpu_armv7.h
+cmsis_armclang.h cmsis_compiler.h cmsis_iccarm.h core_cm0plus.h
+
+./config:
+clock_config.c clock_config.h system_K32L2B31A.c system_K32L2B31A.h
+
+./drivers:
+fsl_clock.c fsl_common_arm.h fsl_gpio.c fsl_lpuart.h fsl_smc.h
+fsl_clock.h fsl_common.c fsl_gpio.h fsl_port.h fsl_uart.c
+fsl_common_arm.c fsl_common.h fsl_lpuart.c fsl_smc.c fsl_uart.h
+
+./gcc:
+frdmk32l2b.ld startup_k32l2b31a.c
+frdmk32l2b_library.ld frdmk32l2b_memory.ld
+
+The linker files have been renamed and the #include directive edited
+to match.
+
+Then to build a test project change to the directory
+examples/devices/cdc_msc and do:
+
+make BOARD=frdm_k32l2b
+
+The resulting .hex file will be found in the _build directory, copy
+that will to the FRDM board to run the demo.
diff --git a/hw/bsp/frdm_k32l2a4s/board.h b/hw/bsp/frdm_k32l2a4s/board.h
new file mode 100644
index 000000000..14eefda17
--- /dev/null
+++ b/hw/bsp/frdm_k32l2a4s/board.h
@@ -0,0 +1,58 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019, 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_
+
+#include "fsl_device_registers.h"
+
+// LED
+// The Red LED is on PTE29.
+// The Green LED is on PTC4.
+// The Blue LED is on PTE31.
+#define LED_PIN_CLOCK kCLOCK_PortC
+#define LED_GPIO GPIOC
+#define LED_PORT PORTC
+#define LED_PIN 4
+#define LED_STATE_ON 0
+
+// SW3 button1
+#define BUTTON_PIN_CLOCK kCLOCK_PortE
+#define BUTTON_GPIO GPIOE
+#define BUTTON_PORT PORTE
+#define BUTTON_PIN 4
+#define BUTTON_STATE_ACTIVE 0
+
+// UART
+#define UART_PORT LPUART0
+#define UART_PIN_CLOCK kCLOCK_PortB
+#define UART_PIN_GPIO GPIOB
+#define UART_PIN_PORT PORTB
+#define UART_PIN_RX 16u
+#define UART_PIN_TX 17u
+
+#endif /* BOARD_H_ */
diff --git a/hw/bsp/frdm_k32l2a4s/board.mk b/hw/bsp/frdm_k32l2a4s/board.mk
new file mode 100644
index 000000000..e9e606fe6
--- /dev/null
+++ b/hw/bsp/frdm_k32l2a4s/board.mk
@@ -0,0 +1,80 @@
+
+# Default to a less-verbose build. If you want all the gory compiler output,
+# "VERBOSE=1" to the make command line.
+ifndef VERBOSE
+.SILENT:
+$(info Non-Verbose Output)
+else
+$(info Verbose Output)
+endif
+
+SDK_DIR = hw/mcu/nxp/mcux-sdk
+MCU_DIR = $(SDK_DIR)/devices/K32L2A4S
+
+ifdef VERBOSE
+$(info TOP='$(TOP)')
+$(info )
+
+$(info BSP='$(TOP)/hw/bsp/$(BOARD)')
+$(info )
+
+$(info TOP/SDK_DIR='$(TOP)/$(SDK_DIR)')
+$(info )
+
+$(info MCU_DIR='$(MCU_DIR)')
+$(info )
+endif
+
+DEPS_SUBMODULES += $(SDK_DIR)
+
+CFLAGS += \
+ -mthumb \
+ -mabi=aapcs \
+ -mcpu=cortex-m0plus \
+ -DCPU_K32L2A41VLH1A \
+ -DCFG_TUSB_MCU=OPT_MCU_K32L2AXX
+
+# mcu driver cause following warnings
+CFLAGS += -Wno-error=unused-parameter -Wno-error=redundant-decls -Wno-error=cast-qual
+
+# All source paths should be relative to the top level.
+
+LD_FILE = $(MCU_DIR)/gcc/frdmk32l2a4s.ld
+LDFLAGS += -L$(TOP)/$(MCU_DIR)/gcc
+
+# Define Recursive Depth wildcard:
+rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
+
+SRC_C += \
+ src/portable/nxp/khci/dcd_khci.c \
+ $(MCU_DIR)/gcc/startup_k32l2a41a.c
+
+SRC_C += $(call rwildcard,$(TOP)/$(MCU_DIR)/config,*.c)
+SRC_C += $(call rwildcard,$(TOP)/$(MCU_DIR)/drivers,*.c)
+
+INC += \
+ $(TOP)/hw/bsp/$(BOARD) \
+ $(TOP)/$(MCU_DIR)/CMSIS/ \
+ $(TOP)/$(MCU_DIR) \
+ $(TOP)/$(MCU_DIR)/config \
+ $(TOP)/$(MCU_DIR)/drivers
+
+ifdef VERBOSE
+$(info INC = '$(strip $(INC))')
+$(info )
+
+$(info SRC_C = '$(sort $(strip $(SRC_C)))')
+$(info )
+endif
+
+# For freeRTOS port source
+FREERTOS_PORT = ARM_CM0
+
+# For flash-jlink target
+#JLINK_DEVICE = ?
+
+# For flash-pyocd target
+PYOCD_TARGET = K32L2A
+
+# flash using pyocd
+flash: flash-pyocd
diff --git a/hw/bsp/frdm_k32l2a4s/frdm_k32l2a4s.c b/hw/bsp/frdm_k32l2a4s/frdm_k32l2a4s.c
new file mode 100644
index 000000000..47dd0c8ec
--- /dev/null
+++ b/hw/bsp/frdm_k32l2a4s/frdm_k32l2a4s.c
@@ -0,0 +1,171 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018, hathach (tinyusb.org)
+ * Copyright (c) 2020, Koji Kitayama
+ *
+ * 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 "board.h"
+#include "fsl_gpio.h"
+#include "fsl_port.h"
+#include "fsl_clock.h"
+#include "fsl_lpuart.h"
+
+#include "clock_config.h"
+
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void USB0_IRQHandler(void)
+{
+ tud_int_handler(0);
+}
+
+void board_init(void)
+{
+ /* Enable port clocks for UART/LED/Button pins */
+ CLOCK_EnableClock(UART_PIN_CLOCK);
+ CLOCK_EnableClock(LED_PIN_CLOCK);
+ CLOCK_EnableClock(BUTTON_PIN_CLOCK);
+
+ gpio_pin_config_t led_config = { kGPIO_DigitalOutput, 0 };
+ GPIO_PinInit(LED_GPIO, LED_PIN, &led_config);
+ PORT_SetPinMux(LED_PORT, LED_PIN, kPORT_MuxAsGpio);
+
+ gpio_pin_config_t button_config = { kGPIO_DigitalInput, 0 };
+ GPIO_PinInit(BUTTON_GPIO, BUTTON_PIN, &button_config);
+ const port_pin_config_t BUTTON_CFG = {
+ kPORT_PullUp,
+ kPORT_FastSlewRate,
+ kPORT_PassiveFilterDisable,
+ kPORT_OpenDrainDisable,
+ kPORT_LowDriveStrength,
+ kPORT_MuxAsGpio,
+ kPORT_UnlockRegister
+ };
+ PORT_SetPinConfig(BUTTON_PORT, BUTTON_PIN, &BUTTON_CFG);
+
+ /*
+ Enable LPUART0 clock and configure port pins.
+ FIR clock is being used so the USB examples work.
+ */
+ PCC_LPUART0 = 0U; /* Clock must be off to set PCS */
+ PCC_LPUART0 = PCC_CLKCFG_PCS( 3U ); /* Select the clock. 1:OSCCLK/Bus Clock, 2:Slow IRC, 3: Fast IRC, 6: System PLL */
+ PCC_LPUART0 |= PCC_CLKCFG_CGC( 1U ); /* Enable LPUART */
+
+ /* PORTB16 (pin 62) is configured as LPUART0_RX */
+ gpio_pin_config_t const lpuart_config_rx = { kGPIO_DigitalInput, 0 };
+ GPIO_PinInit(UART_PIN_GPIO, UART_PIN_RX, &lpuart_config_rx);
+ const port_pin_config_t UART_CFG = {
+ kPORT_PullUp,
+ kPORT_FastSlewRate,
+ kPORT_PassiveFilterDisable,
+ kPORT_OpenDrainDisable,
+ kPORT_LowDriveStrength,
+ kPORT_MuxAsGpio,
+ kPORT_UnlockRegister
+ };
+ PORT_SetPinConfig(UART_PIN_PORT, UART_PIN_RX, &UART_CFG);
+ PORT_SetPinMux( UART_PIN_PORT, UART_PIN_RX, kPORT_MuxAlt3);
+
+ /* PORTB17 (pin 63) is configured as LPUART0_TX */
+ gpio_pin_config_t const lpuart_config_tx = { kGPIO_DigitalOutput, 0 };
+ GPIO_PinInit( UART_PIN_GPIO, UART_PIN_TX, &lpuart_config_tx);
+ PORT_SetPinMux( UART_PIN_PORT, UART_PIN_TX, kPORT_MuxAlt3);
+
+ BOARD_BootClockRUN();
+ SystemCoreClockUpdate();
+
+#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
+
+ lpuart_config_t uart_config;
+ LPUART_GetDefaultConfig(&uart_config);
+ uart_config.baudRate_Bps = CFG_BOARD_UART_BAUDRATE;
+ uart_config.enableTx = true;
+ uart_config.enableRx = true;
+ LPUART_Init(UART_PORT, &uart_config, CLOCK_GetFreq(kCLOCK_ScgFircClk));
+
+ // USB
+ CLOCK_EnableUsbfs0Clock(kCLOCK_IpSrcFircAsync, 48000000U);
+}
+
+//--------------------------------------------------------------------+
+// Board porting API
+//--------------------------------------------------------------------+
+
+void board_led_write(bool state)
+{
+ GPIO_PinWrite(LED_GPIO, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
+}
+
+uint32_t board_button_read(void)
+{
+ return BUTTON_STATE_ACTIVE == GPIO_PinRead(BUTTON_GPIO, BUTTON_PIN);
+}
+
+int board_uart_read(uint8_t* buf, int len)
+{
+#if 0 /*
+ Use this version if want the LED to blink during BOARD=board_test,
+ without having to hit a key.
+ */
+ if( 0U != (kLPUART_RxDataRegFullFlag & LPUART_GetStatusFlags( UART_PORT )) )
+ {
+ LPUART_ReadBlocking(UART_PORT, buf, len);
+ return len;
+ }
+
+ return( 0 );
+#else /* Wait for 'len' characters to come in */
+
+ LPUART_ReadBlocking(UART_PORT, buf, len);
+ return len;
+
+#endif
+}
+
+int board_uart_write(void const * buf, int len)
+{
+ LPUART_WriteBlocking(UART_PORT, (uint8_t const*) buf, len);
+ return len;
+}
+
+#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/src/common/tusb_mcu.h b/src/common/tusb_mcu.h
index 1d27f47af..18e40e1b1 100644
--- a/src/common/tusb_mcu.h
+++ b/src/common/tusb_mcu.h
@@ -85,7 +85,7 @@
#define TUP_DCD_ENDPOINT_MAX 8
#define TUP_RHPORT_HIGHSPEED 1 // Port0 HS, Port1 HS
-#elif TU_CHECK_MCU(OPT_MCU_MKL25ZXX, OPT_MCU_K32L2BXX)
+#elif TU_CHECK_MCU(OPT_MCU_MKL25ZXX, OPT_MCU_K32L2AXX, OPT_MCU_K32L2BXX)
#define TUP_DCD_ENDPOINT_MAX 16
#elif TU_CHECK_MCU(OPT_MCU_MM32F327X)
diff --git a/src/portable/nxp/khci/dcd_khci.c b/src/portable/nxp/khci/dcd_khci.c
index b6daec3de..2678cdca1 100644
--- a/src/portable/nxp/khci/dcd_khci.c
+++ b/src/portable/nxp/khci/dcd_khci.c
@@ -26,9 +26,12 @@
#include "tusb_option.h"
-#if CFG_TUD_ENABLED && ( \
- ( CFG_TUSB_MCU == OPT_MCU_MKL25ZXX ) || ( CFG_TUSB_MCU == OPT_MCU_K32L2BXX ) \
- )
+#if CFG_TUD_ENABLED && \
+ ( \
+ ( CFG_TUSB_MCU == OPT_MCU_MKL25ZXX ) || \
+ ( CFG_TUSB_MCU == OPT_MCU_K32L2AXX ) || \
+ ( CFG_TUSB_MCU == OPT_MCU_K32L2BXX ) \
+ )
#include "fsl_device_registers.h"
#define KHCI USB0
diff --git a/src/portable/nxp/khci/hcd_khci.c b/src/portable/nxp/khci/hcd_khci.c
index 35763f121..8ff1feff7 100644
--- a/src/portable/nxp/khci/hcd_khci.c
+++ b/src/portable/nxp/khci/hcd_khci.c
@@ -26,9 +26,12 @@
#include "tusb_option.h"
-#if CFG_TUH_ENABLED && ( \
- ( CFG_TUSB_MCU == OPT_MCU_MKL25ZXX ) || ( CFG_TUSB_MCU == OPT_MCU_K32L2BXX ) \
- )
+#if CFG_TUD_ENABLED && \
+ ( \
+ ( CFG_TUSB_MCU == OPT_MCU_MKL25ZXX ) || \
+ ( CFG_TUSB_MCU == OPT_MCU_K32L2AXX ) || \
+ ( CFG_TUSB_MCU == OPT_MCU_K32L2BXX ) \
+ )
#include "fsl_device_registers.h"
#define KHCI USB0
diff --git a/src/tusb_option.h b/src/tusb_option.h
index c019b0ba4..5a234e357 100644
--- a/src/tusb_option.h
+++ b/src/tusb_option.h
@@ -119,6 +119,7 @@
// NXP Kinetis
#define OPT_MCU_MKL25ZXX 1200 ///< NXP MKL25Zxx
#define OPT_MCU_K32L2BXX 1201 ///< NXP K32L2Bxx
+#define OPT_MCU_K32L2AXX 1202 ///< NXP K32L2Axx
// Silabs
#define OPT_MCU_EFM32GG 1300 ///< Silabs EFM32GG