Skip to content

Commit f9b8a06

Browse files
Bob Paddockhathach
authored andcommitted
Add support for NXP FRDM_K32L2A4S eval board.
1 parent f1a859d commit f9b8a06

File tree

9 files changed

+375
-8
lines changed

9 files changed

+375
-8
lines changed

hw/bsp/board_mcu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
#elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX || CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \
4949
CFG_TUSB_MCU == OPT_MCU_LPC55XX || CFG_TUSB_MCU == OPT_MCU_MKL25ZXX || \
50-
CFG_TUSB_MCU == OPT_MCU_K32L2BXX
50+
CFG_TUSB_MCU == OPT_MCU_K32L2AXX || OPT_MCU_K32L2BXX
5151
#include "fsl_device_registers.h"
5252

5353
#elif CFG_TUSB_MCU == OPT_MCU_NRF5X

hw/bsp/frdm_k32l2a4s/README.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Jan/13/2023 13:04
2+
3+
The FRDM-K32L2B3 Freedom development board provides a platform for
4+
evaluation and development of the K32 L2B MCU Family. -
5+
https://www.nxp.com/part/FRDM-K32L2B3#/
6+
7+
TinyUSB does not include the board specific drivers. Those drivers
8+
need to be extracted from the MCUXpresso IDE and SDK.
9+
10+
Install MCUXPresso version 11.6 or later and SDK 2.12 or later. Then
11+
build the example project "frdmk32l2b_hellow_worldvirual_com".
12+
13+
From the frdmk32l2b_hellow_worldvirual_com project copy these files to
14+
this directory structure, in this directory:
15+
16+
hw/mcu/nxp/mcux-sdk/devices/K32L2B31A
17+
18+
CMSIS/
19+
config/
20+
drivers/
21+
gcc/
22+
fsl_device_registers.h
23+
K32L2B31A_features.h
24+
K32L2B31A.h
25+
26+
./CMSIS:
27+
cmsis_armcc.h cmsis_armclang_ltm.h cmsis_gcc.h cmsis_version.h mpu_armv7.h
28+
cmsis_armclang.h cmsis_compiler.h cmsis_iccarm.h core_cm0plus.h
29+
30+
./config:
31+
clock_config.c clock_config.h system_K32L2B31A.c system_K32L2B31A.h
32+
33+
./drivers:
34+
fsl_clock.c fsl_common_arm.h fsl_gpio.c fsl_lpuart.h fsl_smc.h
35+
fsl_clock.h fsl_common.c fsl_gpio.h fsl_port.h fsl_uart.c
36+
fsl_common_arm.c fsl_common.h fsl_lpuart.c fsl_smc.c fsl_uart.h
37+
38+
./gcc:
39+
frdmk32l2b.ld startup_k32l2b31a.c
40+
frdmk32l2b_library.ld frdmk32l2b_memory.ld
41+
42+
The linker files have been renamed and the #include directive edited
43+
to match.
44+
45+
Then to build a test project change to the directory
46+
examples/devices/cdc_msc and do:
47+
48+
make BOARD=frdm_k32l2b
49+
50+
The resulting .hex file will be found in the _build directory, copy
51+
that will to the FRDM board to run the demo.

hw/bsp/frdm_k32l2a4s/board.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019, Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
28+
#ifndef BOARD_H_
29+
#define BOARD_H_
30+
31+
#include "fsl_device_registers.h"
32+
33+
// LED
34+
// The Red LED is on PTE29.
35+
// The Green LED is on PTC4.
36+
// The Blue LED is on PTE31.
37+
#define LED_PIN_CLOCK kCLOCK_PortC
38+
#define LED_GPIO GPIOC
39+
#define LED_PORT PORTC
40+
#define LED_PIN 4
41+
#define LED_STATE_ON 0
42+
43+
// SW3 button1
44+
#define BUTTON_PIN_CLOCK kCLOCK_PortE
45+
#define BUTTON_GPIO GPIOE
46+
#define BUTTON_PORT PORTE
47+
#define BUTTON_PIN 4
48+
#define BUTTON_STATE_ACTIVE 0
49+
50+
// UART
51+
#define UART_PORT LPUART0
52+
#define UART_PIN_CLOCK kCLOCK_PortB
53+
#define UART_PIN_GPIO GPIOB
54+
#define UART_PIN_PORT PORTB
55+
#define UART_PIN_RX 16u
56+
#define UART_PIN_TX 17u
57+
58+
#endif /* BOARD_H_ */

hw/bsp/frdm_k32l2a4s/board.mk

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
# Default to a less-verbose build. If you want all the gory compiler output,
3+
# "VERBOSE=1" to the make command line.
4+
ifndef VERBOSE
5+
.SILENT:
6+
$(info Non-Verbose Output)
7+
else
8+
$(info Verbose Output)
9+
endif
10+
11+
SDK_DIR = hw/mcu/nxp/mcux-sdk
12+
MCU_DIR = $(SDK_DIR)/devices/K32L2A4S
13+
14+
ifdef VERBOSE
15+
$(info TOP='$(TOP)')
16+
$(info )
17+
18+
$(info BSP='$(TOP)/hw/bsp/$(BOARD)')
19+
$(info )
20+
21+
$(info TOP/SDK_DIR='$(TOP)/$(SDK_DIR)')
22+
$(info )
23+
24+
$(info MCU_DIR='$(MCU_DIR)')
25+
$(info )
26+
endif
27+
28+
DEPS_SUBMODULES += $(SDK_DIR)
29+
30+
CFLAGS += \
31+
-mthumb \
32+
-mabi=aapcs \
33+
-mcpu=cortex-m0plus \
34+
-DCPU_K32L2A41VLH1A \
35+
-DCFG_TUSB_MCU=OPT_MCU_K32L2AXX
36+
37+
# mcu driver cause following warnings
38+
CFLAGS += -Wno-error=unused-parameter -Wno-error=redundant-decls -Wno-error=cast-qual
39+
40+
# All source paths should be relative to the top level.
41+
42+
LD_FILE = $(MCU_DIR)/gcc/frdmk32l2a4s.ld
43+
LDFLAGS += -L$(TOP)/$(MCU_DIR)/gcc
44+
45+
# Define Recursive Depth wildcard:
46+
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
47+
48+
SRC_C += \
49+
src/portable/nxp/khci/dcd_khci.c \
50+
$(MCU_DIR)/gcc/startup_k32l2a41a.c
51+
52+
SRC_C += $(call rwildcard,$(TOP)/$(MCU_DIR)/config,*.c)
53+
SRC_C += $(call rwildcard,$(TOP)/$(MCU_DIR)/drivers,*.c)
54+
55+
INC += \
56+
$(TOP)/hw/bsp/$(BOARD) \
57+
$(TOP)/$(MCU_DIR)/CMSIS/ \
58+
$(TOP)/$(MCU_DIR) \
59+
$(TOP)/$(MCU_DIR)/config \
60+
$(TOP)/$(MCU_DIR)/drivers
61+
62+
ifdef VERBOSE
63+
$(info INC = '$(strip $(INC))')
64+
$(info )
65+
66+
$(info SRC_C = '$(sort $(strip $(SRC_C)))')
67+
$(info )
68+
endif
69+
70+
# For freeRTOS port source
71+
FREERTOS_PORT = ARM_CM0
72+
73+
# For flash-jlink target
74+
#JLINK_DEVICE = ?
75+
76+
# For flash-pyocd target
77+
PYOCD_TARGET = K32L2A
78+
79+
# flash using pyocd
80+
flash: flash-pyocd

hw/bsp/frdm_k32l2a4s/frdm_k32l2a4s.c

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018, hathach (tinyusb.org)
5+
* Copyright (c) 2020, Koji Kitayama
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
* This file is part of the TinyUSB stack.
26+
*/
27+
28+
#include "../board.h"
29+
#include "board.h"
30+
#include "fsl_gpio.h"
31+
#include "fsl_port.h"
32+
#include "fsl_clock.h"
33+
#include "fsl_lpuart.h"
34+
35+
#include "clock_config.h"
36+
37+
//--------------------------------------------------------------------+
38+
// Forward USB interrupt events to TinyUSB IRQ Handler
39+
//--------------------------------------------------------------------+
40+
void USB0_IRQHandler(void)
41+
{
42+
tud_int_handler(0);
43+
}
44+
45+
void board_init(void)
46+
{
47+
/* Enable port clocks for UART/LED/Button pins */
48+
CLOCK_EnableClock(UART_PIN_CLOCK);
49+
CLOCK_EnableClock(LED_PIN_CLOCK);
50+
CLOCK_EnableClock(BUTTON_PIN_CLOCK);
51+
52+
gpio_pin_config_t led_config = { kGPIO_DigitalOutput, 0 };
53+
GPIO_PinInit(LED_GPIO, LED_PIN, &led_config);
54+
PORT_SetPinMux(LED_PORT, LED_PIN, kPORT_MuxAsGpio);
55+
56+
gpio_pin_config_t button_config = { kGPIO_DigitalInput, 0 };
57+
GPIO_PinInit(BUTTON_GPIO, BUTTON_PIN, &button_config);
58+
const port_pin_config_t BUTTON_CFG = {
59+
kPORT_PullUp,
60+
kPORT_FastSlewRate,
61+
kPORT_PassiveFilterDisable,
62+
kPORT_OpenDrainDisable,
63+
kPORT_LowDriveStrength,
64+
kPORT_MuxAsGpio,
65+
kPORT_UnlockRegister
66+
};
67+
PORT_SetPinConfig(BUTTON_PORT, BUTTON_PIN, &BUTTON_CFG);
68+
69+
/*
70+
Enable LPUART0 clock and configure port pins.
71+
FIR clock is being used so the USB examples work.
72+
*/
73+
PCC_LPUART0 = 0U; /* Clock must be off to set PCS */
74+
PCC_LPUART0 = PCC_CLKCFG_PCS( 3U ); /* Select the clock. 1:OSCCLK/Bus Clock, 2:Slow IRC, 3: Fast IRC, 6: System PLL */
75+
PCC_LPUART0 |= PCC_CLKCFG_CGC( 1U ); /* Enable LPUART */
76+
77+
/* PORTB16 (pin 62) is configured as LPUART0_RX */
78+
gpio_pin_config_t const lpuart_config_rx = { kGPIO_DigitalInput, 0 };
79+
GPIO_PinInit(UART_PIN_GPIO, UART_PIN_RX, &lpuart_config_rx);
80+
const port_pin_config_t UART_CFG = {
81+
kPORT_PullUp,
82+
kPORT_FastSlewRate,
83+
kPORT_PassiveFilterDisable,
84+
kPORT_OpenDrainDisable,
85+
kPORT_LowDriveStrength,
86+
kPORT_MuxAsGpio,
87+
kPORT_UnlockRegister
88+
};
89+
PORT_SetPinConfig(UART_PIN_PORT, UART_PIN_RX, &UART_CFG);
90+
PORT_SetPinMux( UART_PIN_PORT, UART_PIN_RX, kPORT_MuxAlt3);
91+
92+
/* PORTB17 (pin 63) is configured as LPUART0_TX */
93+
gpio_pin_config_t const lpuart_config_tx = { kGPIO_DigitalOutput, 0 };
94+
GPIO_PinInit( UART_PIN_GPIO, UART_PIN_TX, &lpuart_config_tx);
95+
PORT_SetPinMux( UART_PIN_PORT, UART_PIN_TX, kPORT_MuxAlt3);
96+
97+
BOARD_BootClockRUN();
98+
SystemCoreClockUpdate();
99+
100+
#if CFG_TUSB_OS == OPT_OS_NONE
101+
// 1ms tick timer
102+
SysTick_Config(SystemCoreClock / 1000);
103+
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
104+
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
105+
NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
106+
#endif
107+
108+
lpuart_config_t uart_config;
109+
LPUART_GetDefaultConfig(&uart_config);
110+
uart_config.baudRate_Bps = CFG_BOARD_UART_BAUDRATE;
111+
uart_config.enableTx = true;
112+
uart_config.enableRx = true;
113+
LPUART_Init(UART_PORT, &uart_config, CLOCK_GetFreq(kCLOCK_ScgFircClk));
114+
115+
// USB
116+
CLOCK_EnableUsbfs0Clock(kCLOCK_IpSrcFircAsync, 48000000U);
117+
}
118+
119+
//--------------------------------------------------------------------+
120+
// Board porting API
121+
//--------------------------------------------------------------------+
122+
123+
void board_led_write(bool state)
124+
{
125+
GPIO_PinWrite(LED_GPIO, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
126+
}
127+
128+
uint32_t board_button_read(void)
129+
{
130+
return BUTTON_STATE_ACTIVE == GPIO_PinRead(BUTTON_GPIO, BUTTON_PIN);
131+
}
132+
133+
int board_uart_read(uint8_t* buf, int len)
134+
{
135+
#if 0 /*
136+
Use this version if want the LED to blink during BOARD=board_test,
137+
without having to hit a key.
138+
*/
139+
if( 0U != (kLPUART_RxDataRegFullFlag & LPUART_GetStatusFlags( UART_PORT )) )
140+
{
141+
LPUART_ReadBlocking(UART_PORT, buf, len);
142+
return len;
143+
}
144+
145+
return( 0 );
146+
#else /* Wait for 'len' characters to come in */
147+
148+
LPUART_ReadBlocking(UART_PORT, buf, len);
149+
return len;
150+
151+
#endif
152+
}
153+
154+
int board_uart_write(void const * buf, int len)
155+
{
156+
LPUART_WriteBlocking(UART_PORT, (uint8_t const*) buf, len);
157+
return len;
158+
}
159+
160+
#if CFG_TUSB_OS == OPT_OS_NONE
161+
volatile uint32_t system_ticks = 0;
162+
void SysTick_Handler(void)
163+
{
164+
system_ticks++;
165+
}
166+
167+
uint32_t board_millis(void)
168+
{
169+
return system_ticks;
170+
}
171+
#endif

src/common/tusb_mcu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
#define TUP_DCD_ENDPOINT_MAX 8
8686
#define TUP_RHPORT_HIGHSPEED 1 // Port0 HS, Port1 HS
8787

88-
#elif TU_CHECK_MCU(OPT_MCU_MKL25ZXX, OPT_MCU_K32L2BXX)
88+
#elif TU_CHECK_MCU(OPT_MCU_MKL25ZXX, OPT_MCU_K32L2AXX, OPT_MCU_K32L2BXX)
8989
#define TUP_DCD_ENDPOINT_MAX 16
9090

9191
#elif TU_CHECK_MCU(OPT_MCU_MM32F327X)

src/portable/nxp/khci/dcd_khci.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626

2727
#include "tusb_option.h"
2828

29-
#if CFG_TUD_ENABLED && ( \
30-
( CFG_TUSB_MCU == OPT_MCU_MKL25ZXX ) || ( CFG_TUSB_MCU == OPT_MCU_K32L2BXX ) \
31-
)
29+
#if CFG_TUD_ENABLED && \
30+
( \
31+
( CFG_TUSB_MCU == OPT_MCU_MKL25ZXX ) || \
32+
( CFG_TUSB_MCU == OPT_MCU_K32L2AXX ) || \
33+
( CFG_TUSB_MCU == OPT_MCU_K32L2BXX ) \
34+
)
3235

3336
#include "fsl_device_registers.h"
3437
#define KHCI USB0

0 commit comments

Comments
 (0)