1 /* 2 * Copyright (c) 2020 Intel Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <kernel.h> 8 #include <drivers/uart.h> 9 #include <sys/__assert.h> 10 11 static const struct device *uart_dev; 12 z_gdb_backend_init(void)13int z_gdb_backend_init(void) 14 { 15 int ret = 0; 16 static const struct uart_config uart_cfg = { 17 .baudrate = 115200, 18 .parity = UART_CFG_PARITY_NONE, 19 .stop_bits = UART_CFG_STOP_BITS_1, 20 .data_bits = UART_CFG_DATA_BITS_8, 21 .flow_ctrl = UART_CFG_FLOW_CTRL_NONE 22 }; 23 24 if (uart_dev == NULL) { 25 uart_dev = device_get_binding( 26 CONFIG_GDBSTUB_SERIAL_BACKEND_NAME); 27 28 __ASSERT(uart_dev != NULL, "Could not get uart device"); 29 30 ret = uart_configure(uart_dev, &uart_cfg); 31 __ASSERT(ret == 0, "Could not configure uart device"); 32 } 33 34 return ret; 35 } 36 z_gdb_putchar(unsigned char ch)37void z_gdb_putchar(unsigned char ch) 38 { 39 uart_poll_out(uart_dev, ch); 40 } 41 z_gdb_getchar(void)42unsigned char z_gdb_getchar(void) 43 { 44 unsigned char ch; 45 46 while (uart_poll_in(uart_dev, &ch) < 0) { 47 } 48 49 return ch; 50 } 51