Merge pull request #2155 from jferreir/xmc4700_relax

Board support for XMC4700_RELAX
This commit is contained in:
Ha Thach 2023-07-21 19:08:51 +07:00 committed by GitHub
commit 8fa0b74d80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 120 additions and 6 deletions

View File

@ -3,7 +3,7 @@ CFLAGS += \
-DXMC4500_F100x1024 \
# mcu driver cause following warnings
CFLAGS += -Wno-error=stringop-overread
CFLAGS += -Wno-stringop-overread
LD_FILE = $(MCU_DIR)/CMSIS/Infineon/COMPONENT_$(MCU_VARIANT)/Source/TOOLCHAIN_GCC_ARM/XMC4500x1024.ld

View File

@ -0,0 +1,81 @@
/*
* 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
#define LED_PIN P5_9
#define LED_STATE_ON 1
#define BUTTON_PIN P15_13
#define BUTTON_STATE_ACTIVE 0
#define UART_DEV XMC_UART0_CH0
#define UART_TX_PIN P1_5
#define UART_TX_PIN_AF P1_5_AF_U0C0_DOUT0
#define UART_RX_PIN P1_4
#define UART_RX_INPUT USIC0_C0_DX0_P1_4
static inline void board_clock_init(void)
{
/* Clock configuration */
/* fPLL = 144MHz */
/* fSYS = 144MHz */
/* fUSB = 48MHz */
const XMC_SCU_CLOCK_CONFIG_t clock_config =
{
.syspll_config.p_div = 2,
.syspll_config.n_div = 48,
.syspll_config.k_div = 1,
.syspll_config.mode = XMC_SCU_CLOCK_SYSPLL_MODE_NORMAL,
.syspll_config.clksrc = XMC_SCU_CLOCK_SYSPLLCLKSRC_OSCHP,
.enable_oschp = true,
.calibration_mode = XMC_SCU_CLOCK_FOFI_CALIBRATION_MODE_FACTORY,
.fsys_clksrc = XMC_SCU_CLOCK_SYSCLKSRC_PLL,
.fsys_clkdiv = 2,
.fcpu_clkdiv = 1,
.fccu_clkdiv = 1,
.fperipheral_clkdiv = 1
};
/* Setup settings for USB clock */
XMC_SCU_CLOCK_Init(&clock_config);
XMC_SCU_CLOCK_SetUsbClockDivider(6);
XMC_SCU_CLOCK_SetUsbClockSource(XMC_SCU_CLOCK_USBCLKSRC_SYSPLL);
XMC_SCU_CLOCK_EnableClock(XMC_SCU_CLOCK_USB);
}
#ifdef __cplusplus
}
#endif
#endif /* BOARD_H_ */

View File

@ -0,0 +1,12 @@
MCU_VARIANT = XMC4700
CFLAGS += \
-DXMC4700_F144x2048 \
# mcu driver cause following warnings
CFLAGS += -Wno-stringop-overread
LD_FILE = $(MCU_DIR)/CMSIS/Infineon/COMPONENT_$(MCU_VARIANT)/Source/TOOLCHAIN_GCC_ARM/XMC4700x2048.ld
JLINK_DEVICE = XMC4700-2048
flash: flash-jlink

View File

@ -26,6 +26,7 @@
#include "xmc_gpio.h"
#include "xmc_scu.h"
#include "xmc_uart.h"
#include "bsp/board.h"
#include "board.h"
@ -45,17 +46,31 @@ void board_init(void)
SystemCoreClockUpdate();
// LED
XMC_GPIO_CONFIG_t led_cfg;
XMC_GPIO_CONFIG_t led_cfg = {0};
led_cfg.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
led_cfg.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
led_cfg.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM;
XMC_GPIO_Init(LED_PIN, &led_cfg);
// Button
XMC_GPIO_CONFIG_t button_cfg;
XMC_GPIO_CONFIG_t button_cfg = {0};
button_cfg.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
XMC_GPIO_Init(BUTTON_PIN, &button_cfg);
#ifdef UART_DEV
XMC_UART_CH_CONFIG_t uart_cfg = {0};
uart_cfg.baudrate = CFG_BOARD_UART_BAUDRATE;
uart_cfg.data_bits = 8;
uart_cfg.stop_bits = 1;
XMC_UART_CH_Init(UART_DEV, &uart_cfg);
XMC_GPIO_SetMode(UART_RX_PIN, XMC_GPIO_MODE_INPUT_PULL_UP);
XMC_UART_CH_SetInputSource(UART_DEV, XMC_UART_CH_INPUT_RXD, UART_RX_INPUT);
XMC_UART_CH_Start(UART_DEV);
XMC_GPIO_SetMode(UART_TX_PIN, (XMC_GPIO_MODE_t)(XMC_GPIO_MODE_OUTPUT_PUSH_PULL | UART_TX_PIN_AF));
#endif
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
@ -69,6 +84,9 @@ void board_init(void)
#endif
// USB Power Enable
#if(UC_SERIES != XMC45)
XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_USB0);
#endif
XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_USB0);
XMC_SCU_POWER_EnableUsb();
}
@ -93,7 +111,7 @@ int board_uart_read(uint8_t* buf, int len)
{
#ifdef UART_DEV
for(int i=0;i<len;i++) {
buf[i] = uart_getc(uart_inst);
buf[i] = XMC_UART_CH_GetReceivedData(UART_DEV);
}
return len;
#else
@ -107,7 +125,7 @@ int board_uart_write(void const * buf, int len)
#ifdef UART_DEV
char const* bufch = (char const*) buf;
for(int i=0;i<len;i++) {
uart_putc(uart_inst, bufch[i]);
XMC_UART_CH_Transmit(UART_DEV, bufch[i]);
}
return len;
#else

View File

@ -20,8 +20,11 @@ SRC_C += \
src/portable/synopsys/dwc2/dcd_dwc2.c \
$(MCU_DIR)/Newlib/syscalls.c \
$(MCU_DIR)/CMSIS/Infineon/COMPONENT_$(MCU_VARIANT)/Source/system_$(MCU_VARIANT).c \
$(MCU_DIR)/XMCLib/src/xmc_gpio.c \
$(MCU_DIR)/XMCLib/src/xmc4_gpio.c \
$(MCU_DIR)/XMCLib/src/xmc4_scu.c
$(MCU_DIR)/XMCLib/src/xmc4_scu.c \
$(MCU_DIR)/XMCLib/src/xmc_usic.c \
$(MCU_DIR)/XMCLib/src/xmc_uart.c
SRC_S += $(MCU_DIR)/CMSIS/Infineon/COMPONENT_$(MCU_VARIANT)/Source/TOOLCHAIN_GCC_ARM/startup_$(MCU_VARIANT).S