Skip to content

Commit 8fa0b74

Browse files
authored
Merge pull request hathach#2155 from jferreir/xmc4700_relax
Board support for XMC4700_RELAX
2 parents 17576a6 + 34ff7af commit 8fa0b74

File tree

5 files changed

+120
-6
lines changed

5 files changed

+120
-6
lines changed

hw/bsp/xmc4000/boards/xmc4500_relax/board.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CFLAGS += \
33
-DXMC4500_F100x1024 \
44

55
# mcu driver cause following warnings
6-
CFLAGS += -Wno-error=stringop-overread
6+
CFLAGS += -Wno-stringop-overread
77

88
LD_FILE = $(MCU_DIR)/CMSIS/Infineon/COMPONENT_$(MCU_VARIANT)/Source/TOOLCHAIN_GCC_ARM/XMC4500x1024.ld
99

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2021, 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+
#ifndef BOARD_H_
28+
#define BOARD_H_
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
#define LED_PIN P5_9
35+
#define LED_STATE_ON 1
36+
37+
#define BUTTON_PIN P15_13
38+
#define BUTTON_STATE_ACTIVE 0
39+
40+
#define UART_DEV XMC_UART0_CH0
41+
#define UART_TX_PIN P1_5
42+
#define UART_TX_PIN_AF P1_5_AF_U0C0_DOUT0
43+
#define UART_RX_PIN P1_4
44+
#define UART_RX_INPUT USIC0_C0_DX0_P1_4
45+
46+
static inline void board_clock_init(void)
47+
{
48+
/* Clock configuration */
49+
/* fPLL = 144MHz */
50+
/* fSYS = 144MHz */
51+
/* fUSB = 48MHz */
52+
const XMC_SCU_CLOCK_CONFIG_t clock_config =
53+
{
54+
.syspll_config.p_div = 2,
55+
.syspll_config.n_div = 48,
56+
.syspll_config.k_div = 1,
57+
.syspll_config.mode = XMC_SCU_CLOCK_SYSPLL_MODE_NORMAL,
58+
.syspll_config.clksrc = XMC_SCU_CLOCK_SYSPLLCLKSRC_OSCHP,
59+
.enable_oschp = true,
60+
.calibration_mode = XMC_SCU_CLOCK_FOFI_CALIBRATION_MODE_FACTORY,
61+
.fsys_clksrc = XMC_SCU_CLOCK_SYSCLKSRC_PLL,
62+
.fsys_clkdiv = 2,
63+
.fcpu_clkdiv = 1,
64+
.fccu_clkdiv = 1,
65+
.fperipheral_clkdiv = 1
66+
};
67+
68+
/* Setup settings for USB clock */
69+
XMC_SCU_CLOCK_Init(&clock_config);
70+
71+
XMC_SCU_CLOCK_SetUsbClockDivider(6);
72+
XMC_SCU_CLOCK_SetUsbClockSource(XMC_SCU_CLOCK_USBCLKSRC_SYSPLL);
73+
XMC_SCU_CLOCK_EnableClock(XMC_SCU_CLOCK_USB);
74+
}
75+
76+
77+
#ifdef __cplusplus
78+
}
79+
#endif
80+
81+
#endif /* BOARD_H_ */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
MCU_VARIANT = XMC4700
2+
CFLAGS += \
3+
-DXMC4700_F144x2048 \
4+
5+
# mcu driver cause following warnings
6+
CFLAGS += -Wno-stringop-overread
7+
8+
LD_FILE = $(MCU_DIR)/CMSIS/Infineon/COMPONENT_$(MCU_VARIANT)/Source/TOOLCHAIN_GCC_ARM/XMC4700x2048.ld
9+
10+
JLINK_DEVICE = XMC4700-2048
11+
12+
flash: flash-jlink

hw/bsp/xmc4000/family.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "xmc_gpio.h"
2828
#include "xmc_scu.h"
29+
#include "xmc_uart.h"
2930

3031
#include "bsp/board.h"
3132
#include "board.h"
@@ -45,17 +46,31 @@ void board_init(void)
4546
SystemCoreClockUpdate();
4647

4748
// LED
48-
XMC_GPIO_CONFIG_t led_cfg;
49+
XMC_GPIO_CONFIG_t led_cfg = {0};
4950
led_cfg.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
5051
led_cfg.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
5152
led_cfg.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM;
5253
XMC_GPIO_Init(LED_PIN, &led_cfg);
5354

5455
// Button
55-
XMC_GPIO_CONFIG_t button_cfg;
56+
XMC_GPIO_CONFIG_t button_cfg = {0};
5657
button_cfg.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
5758
XMC_GPIO_Init(BUTTON_PIN, &button_cfg);
5859

60+
#ifdef UART_DEV
61+
XMC_UART_CH_CONFIG_t uart_cfg = {0};
62+
uart_cfg.baudrate = CFG_BOARD_UART_BAUDRATE;
63+
uart_cfg.data_bits = 8;
64+
uart_cfg.stop_bits = 1;
65+
XMC_UART_CH_Init(UART_DEV, &uart_cfg);
66+
67+
XMC_GPIO_SetMode(UART_RX_PIN, XMC_GPIO_MODE_INPUT_PULL_UP);
68+
XMC_UART_CH_SetInputSource(UART_DEV, XMC_UART_CH_INPUT_RXD, UART_RX_INPUT);
69+
70+
XMC_UART_CH_Start(UART_DEV);
71+
XMC_GPIO_SetMode(UART_TX_PIN, (XMC_GPIO_MODE_t)(XMC_GPIO_MODE_OUTPUT_PUSH_PULL | UART_TX_PIN_AF));
72+
#endif
73+
5974
#if CFG_TUSB_OS == OPT_OS_NONE
6075
// 1ms tick timer
6176
SysTick_Config(SystemCoreClock / 1000);
@@ -69,6 +84,9 @@ void board_init(void)
6984
#endif
7085

7186
// USB Power Enable
87+
#if(UC_SERIES != XMC45)
88+
XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_USB0);
89+
#endif
7290
XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_USB0);
7391
XMC_SCU_POWER_EnableUsb();
7492
}
@@ -93,7 +111,7 @@ int board_uart_read(uint8_t* buf, int len)
93111
{
94112
#ifdef UART_DEV
95113
for(int i=0;i<len;i++) {
96-
buf[i] = uart_getc(uart_inst);
114+
buf[i] = XMC_UART_CH_GetReceivedData(UART_DEV);
97115
}
98116
return len;
99117
#else
@@ -107,7 +125,7 @@ int board_uart_write(void const * buf, int len)
107125
#ifdef UART_DEV
108126
char const* bufch = (char const*) buf;
109127
for(int i=0;i<len;i++) {
110-
uart_putc(uart_inst, bufch[i]);
128+
XMC_UART_CH_Transmit(UART_DEV, bufch[i]);
111129
}
112130
return len;
113131
#else

hw/bsp/xmc4000/family.mk

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ SRC_C += \
2020
src/portable/synopsys/dwc2/dcd_dwc2.c \
2121
$(MCU_DIR)/Newlib/syscalls.c \
2222
$(MCU_DIR)/CMSIS/Infineon/COMPONENT_$(MCU_VARIANT)/Source/system_$(MCU_VARIANT).c \
23+
$(MCU_DIR)/XMCLib/src/xmc_gpio.c \
2324
$(MCU_DIR)/XMCLib/src/xmc4_gpio.c \
24-
$(MCU_DIR)/XMCLib/src/xmc4_scu.c
25+
$(MCU_DIR)/XMCLib/src/xmc4_scu.c \
26+
$(MCU_DIR)/XMCLib/src/xmc_usic.c \
27+
$(MCU_DIR)/XMCLib/src/xmc_uart.c
2528

2629
SRC_S += $(MCU_DIR)/CMSIS/Infineon/COMPONENT_$(MCU_VARIANT)/Source/TOOLCHAIN_GCC_ARM/startup_$(MCU_VARIANT).S
2730

0 commit comments

Comments
 (0)