gdbstub_backend_serial.c 938 B

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