-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugConsole.cpp
More file actions
90 lines (71 loc) · 2.19 KB
/
Copy pathDebugConsole.cpp
File metadata and controls
90 lines (71 loc) · 2.19 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "DebugConsole.h"
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_gpio.h>
#include <stm32f4xx_usart.h>
#include <misc.h>
DebugConsole *Console;
DebugConsole::DebugConsole()
{
m_debugBufferHead = 0;
m_debugBufferTail = 0;
}
void DebugConsole::Init()
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
USART_ITConfig(UART4, USART_IT_TXE, DISABLE);
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
NVIC_InitTypeDef nvicInit;
nvicInit.NVIC_IRQChannel = UART4_IRQn;
nvicInit.NVIC_IRQChannelPreemptionPriority = 0;
nvicInit.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicInit);
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(UART4, &USART_InitStructure);
USART_Cmd(UART4, ENABLE);
}
void DebugConsole::HandleCh(char ch)
{
}
void DebugConsole::Write(const char *msg){
while (*msg)
{
m_debugBuffer[m_debugBufferTail++] = *msg;
if (m_debugBufferTail == DEBUG_BUFFER_SIZE)
m_debugBufferTail = 0;
msg++;
}
if (m_debugBufferHead != m_debugBufferTail)
USART_ITConfig(UART4, USART_IT_TXE, ENABLE);
}
void DebugConsole::SendNextCh()
{
if (m_debugBufferHead == m_debugBufferTail){
USART_ITConfig(UART4, USART_IT_TXE, DISABLE);
return;
}
UART4->DR = m_debugBuffer[m_debugBufferHead++];
if (m_debugBufferHead == DEBUG_BUFFER_SIZE)
m_debugBufferHead = 0;
}
void DebugConsole::HandleOverrun()
{
}
DebugConsole::~DebugConsole()
{
}