1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17:
18:
19: #include <tk/typedef.h>
20: #include <sys/sysdef.h>
21:
22: #if USE_TMONITOR
23: #include "../../libtm.h"
24:
25: #ifdef IOTE_STM32L4
26: #if TM_COM_SERIAL_DEV
27:
28:
29: #define UART_BASE (0x40004400UL)
30:
31: #define UART_CR1 (*(_UW*)(UART_BASE+0x0000))
32: #define UART_CR2 (*(_UW*)(UART_BASE+0x0004))
33: #define UART_CR3 (*(_UW*)(UART_BASE+0x0008))
34: #define UART_BRR (*(_UW*)(UART_BASE+0x000C))
35: #define UART_GTPR (*(_UW*)(UART_BASE+0x0010))
36: #define UART_RTOR (*(_UW*)(UART_BASE+0x0014))
37: #define UART_RQR (*(_UW*)(UART_BASE+0x0018))
38: #define UART_ISR (*(_UW*)(UART_BASE+0x001C))
39: #define UART_ICR (*(_UW*)(UART_BASE+0x0020))
40: #define UART_RDR (*(_UW*)(UART_BASE+0x0024))
41: #define UART_TDR (*(_UW*)(UART_BASE+0x0028))
42:
43: #define CR1_UE (0x00000001)
44: #define CR1_RE (0x00000004)
45: #define CR1_TE (0x00000008)
46:
47: #define ISR_TXE (0x00000080)
48: #define ISR_TC (0x00000040)
49: #define ISR_RXNE (0x00000020)
50:
51:
52: #define UART_BAUD (115200)
53:
54: EXPORT void tm_snd_dat( const UB* buf, INT size )
55: {
56: UB *b;
57:
58: for( b = (UB *)buf; size > 0; size--, b++ ){
59: while ((UART_ISR & ISR_TXE) == 0 );
60: UART_TDR = *b;
61: while ((UART_ISR & ISR_TC) == 0 );
62: }
63: }
64:
65:
66: EXPORT void tm_rcv_dat( UB* buf, INT size )
67: {
68: for( ; size > 0; size--, buf++ ){
69: while ( (UART_ISR & ISR_RXNE) == 0 );
70: *buf = UART_RDR & 0xff;
71: }
72: }
73:
74:
75: EXPORT void tm_com_init(void)
76: {
77:
78: UART_CR1 = 0;
79: UART_CR2 = 0;
80: UART_CR3 = 0;
81:
82:
83: UART_BRR = ((TMCLK*1000*1000) + UART_BAUD/2)/UART_BAUD;
84:
85: UART_CR1 = CR1_UE | CR1_RE |CR1_TE;
86: }
87:
88: #endif
89: #endif
90: #endif