-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_console.c
58 lines (48 loc) · 1.31 KB
/
serial_console.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*****************************************************************************************
* Purpose:
* Providing sending / receiving the printf / scanf strings to/from a specified
* UART interface.
*
*
*****************************************************************************************
* Author: Usama
* Created on: July 28, 2022
*****************************************************************************************
* Changes:
*
* Date Changed by Description
* ---- ---------- -----------
*
*
*
*
*****************************************************************************************/
#include "stm32f7xx_hal.h"
//- IMPORTANT:
//- Set this handle to any initialized UART
UART_HandleTypeDef *console_io_uart_ptr = 0;
int __io_putchar(int _char)
{
if (console_io_uart_ptr)
{
HAL_UART_Transmit(console_io_uart_ptr, (unsigned char *) &_char, 1, HAL_MAX_DELAY);
return _char;
}
return 0;
}
int __io_getchar(void)
{
if (console_io_uart_ptr)
{
unsigned char _char;
HAL_UART_Receive(console_io_uart_ptr, &_char, 1, HAL_MAX_DELAY);
HAL_UART_Transmit(console_io_uart_ptr, &_char, 1, HAL_MAX_DELAY);
if (_char == '\r')
{
unsigned char repl = '\n';
HAL_UART_Transmit(console_io_uart_ptr, &repl, 1, HAL_MAX_DELAY);
}
return _char;
}
return 0;
}