1 /*
2  * Copyright (c) 2012 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #include <stdarg.h>
9 #include <lk/reg.h>
10 #include <lk/debug.h>
11 #include <stdio.h>
12 #include <kernel/thread.h>
13 #include <platform/debug.h>
14 #include <arch/ops.h>
15 #include <dev/uart.h>
16 #include <target/debugconfig.h>
17 #include <arch/arm/cm.h>
18 #include <platform/stm32.h>
19 
stm32_debug_early_init(void)20 void stm32_debug_early_init(void) {
21     uart_init_early();
22 }
23 
24 /* later in the init process */
stm32_debug_init(void)25 void stm32_debug_init(void) {
26     uart_init();
27 }
28 
platform_dputc(char c)29 void platform_dputc(char c) {
30     if (c == '\n')
31         uart_putc(DEBUG_UART, '\r');
32     uart_putc(DEBUG_UART, c);
33 }
34 
platform_dgetc(char * c,bool wait)35 int platform_dgetc(char *c, bool wait) {
36     int ret = uart_getc(DEBUG_UART, wait);
37     if (ret < 0)
38         return -1;
39     *c = ret;
40     return 0;
41 }
42 
platform_pputc(char c)43 void platform_pputc(char c) {
44     if (c == '\n')
45         uart_pputc(DEBUG_UART, '\r');
46     uart_pputc(DEBUG_UART, c);
47 }
48 
platform_pgetc(char * c,bool wait)49 int platform_pgetc(char *c, bool wait) {
50     int ret = uart_pgetc(DEBUG_UART);
51     if (ret < 0)
52         return -1;
53     *c = ret;
54     return 0;
55 }
56