Skip to content

Commit b1e345b

Browse files
committed
Add UART_DEV support
1 parent 6c7c9f2 commit b1e345b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

hw/bsp/xmc4000/family.c

Lines changed: 20 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,7 @@ void board_init(void)
6984
#endif
7085

7186
// USB Power Enable
87+
XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_USB0);
7288
XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_USB0);
7389
XMC_SCU_POWER_EnableUsb();
7490
}
@@ -93,7 +109,7 @@ int board_uart_read(uint8_t* buf, int len)
93109
{
94110
#ifdef UART_DEV
95111
for(int i=0;i<len;i++) {
96-
buf[i] = uart_getc(uart_inst);
112+
buf[i] = XMC_UART_CH_GetReceivedData(UART_DEV);
97113
}
98114
return len;
99115
#else
@@ -107,7 +123,7 @@ int board_uart_write(void const * buf, int len)
107123
#ifdef UART_DEV
108124
char const* bufch = (char const*) buf;
109125
for(int i=0;i<len;i++) {
110-
uart_putc(uart_inst, bufch[i]);
126+
XMC_UART_CH_Transmit(UART_DEV, bufch[i]);
111127
}
112128
return len;
113129
#else

0 commit comments

Comments
 (0)