Skip to content

Commit 5ae7b77

Browse files
committed
feat:add debug uart use usart6
reference:#4
1 parent a6cc2cc commit 5ae7b77

File tree

7 files changed

+115
-17
lines changed

7 files changed

+115
-17
lines changed

doc/bug/串口接收-RX缓存满1.jpg

215 KB
Loading

doc/bug/串口接收-RX缓存满2.jpg

78.8 KB
Loading

doc/bug/风扇图标空白.jpg

129 KB
Loading

lcd/bsp_lcd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,11 @@ void LCD_DisplayChar(uint16_t Line, uint16_t Column, uint8_t Ascii)
581581
{
582582
Ascii -= 32;
583583

584-
PANEL_DEBUG("ASCII CODE = %d",Ascii);
584+
PANEL_DEBUG("ASCII CODE = %c",Ascii);
585585

586-
PANEL_DEBUG("table index = %d",Ascii * LCD_Currentfonts->Height);
586+
// PANEL_DEBUG("table index = %d",Ascii * LCD_Currentfonts->Height);
587587

588-
PANEL_DEBUG("fonts table in index = %#X",LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height+1]);
588+
// PANEL_DEBUG("fonts table in index = %#X",LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height+1]);
589589

590590
#ifdef PANEL
591591
Panel_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height * 6]); /* 字模高度 x 行成员数 */
@@ -609,7 +609,7 @@ void LCD_DisplayStringLine(uint16_t Line, uint8_t *ptr)
609609
/* Send the string character by character on lCD */
610610
while ((refcolumn < LCD_PIXEL_WIDTH) && ((*ptr != 0) & (((refcolumn + LCD_Currentfonts->Width) & 0xFFFF) >= LCD_Currentfonts->Width)))
611611
{
612-
PANEL_DEBUG("Line = %d, refcolumn = %d", Line, refcolumn);
612+
//PANEL_DEBUG("Line = %d, refcolumn = %d", Line, refcolumn);
613613

614614
/* Display one character on LCD */
615615
LCD_DisplayChar(Line, refcolumn, *ptr);

panel_usart.c

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ UartMsg CtrlMsg; /*!< 从ST接收到的云端下发的用电器控制信息 */
5858

5959
void PANEL_USART_Config(void)
6060
{
61-
AP_USART_Config();
61+
DEBUG_USART_Config(); /* 调试串口配置 */
62+
AP_USART_Config();
6263
ST_USART_Config();
6364
NVIC_Configuration();
6465
}
@@ -73,7 +74,7 @@ void PANEL_USART_Config(void)
7374
*/
7475

7576
/**
76-
* @defgroup Config
77+
* @defgroup AP_Config
7778
* @{
7879
*/
7980

@@ -139,7 +140,7 @@ void AP_USART_Config(void)
139140
*/
140141

141142
/**
142-
* @defgroup Config
143+
* @defgroup ST_Config
143144
* @{
144145
*/
145146

@@ -197,6 +198,66 @@ void ST_USART_Config(void)
197198
* @}
198199
*/
199200

201+
/**
202+
* @addtogroup DEBUG_UART
203+
* @{
204+
*/
205+
206+
/**
207+
* @defgroup DEBUG_Config
208+
* @{
209+
*/
210+
211+
/**
212+
* @brief DEBUG_USART GPIO 配置,工作模式配置。115200 8-N-1
213+
* @note 调试串口,无需使能中断
214+
* @param 无
215+
* @retval 无
216+
*/
217+
void DEBUG_USART_Config(void)
218+
{
219+
220+
GPIO_InitTypeDef GPIO_InitStructure;
221+
USART_InitTypeDef USART_InitStructure;
222+
223+
RCC_AHB1PeriphClockCmd(DEBUG_USART_TX_GPIO_CLK, ENABLE);
224+
225+
/* 使能 UART 时钟 */
226+
RCC_APB2PeriphClockCmd(DEBUG_USART_CLK, ENABLE);
227+
228+
/* 连接 PXx 到 USARTx__Rx*/
229+
GPIO_PinAFConfig(DEBUG_USART_TX_GPIO_PORT, DEBUG_USART_TX_SOURCE, DEBUG_USART_TX_AF);
230+
231+
/* 配置Tx引脚为复用功能 */
232+
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
233+
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
234+
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
235+
236+
GPIO_InitStructure.GPIO_Pin = DEBUG_USART_TX_PIN;
237+
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
238+
GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStructure);
239+
240+
/* 配置串DEBUG_USART 模式 */
241+
USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE;
242+
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
243+
USART_InitStructure.USART_StopBits = USART_StopBits_1;
244+
USART_InitStructure.USART_Parity = USART_Parity_No;
245+
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
246+
USART_InitStructure.USART_Mode = USART_Mode_Tx;
247+
248+
USART_Init(DEBUG_USART, &USART_InitStructure);
249+
USART_Cmd(DEBUG_USART, ENABLE);
250+
}
251+
252+
/**
253+
* @}
254+
*/
255+
256+
/**
257+
* @}
258+
*/
259+
260+
200261
/**
201262
* @defgroup NVIC
202263
* @brief 初始化AP和ST的串口中断
@@ -241,27 +302,27 @@ void NVIC_Configuration(void)
241302
* @{
242303
*/
243304

244-
///重定向c库函数printf到串口AP_USART,重定向后可使用printf函数
305+
///重定向c库函数printf到串口DEBUG_USART,重定向后可使用printf函数
245306
int fputc(int ch, FILE *f)
246307
{
247-
/* 发送一个字节数据到串口AP_USART */
248-
USART_SendData(AP_USART, (uint8_t)ch);
308+
/* 发送一个字节数据到串口DEBUG_USART */
309+
USART_SendData(DEBUG_USART, (uint8_t)ch);
249310

250311
/* 等待发送完毕 */
251-
while (USART_GetFlagStatus(AP_USART, USART_FLAG_TXE) == RESET)
312+
while (USART_GetFlagStatus(DEBUG_USART, USART_FLAG_TXE) == RESET)
252313
;
253314

254315
return (ch);
255316
}
256317

257-
///重定向c库函数scanf到串口AP_USART,重写向后可使用scanf、getchar等函数
318+
///重定向c库函数scanf到串口DEBUG_USART,重写向后可使用scanf、getchar等函数
258319
int fgetc(FILE *f)
259320
{
260321
/* 等待串口输入数据 */
261-
while (USART_GetFlagStatus(AP_USART, USART_FLAG_RXNE) == RESET)
322+
while (USART_GetFlagStatus(DEBUG_USART, USART_FLAG_RXNE) == RESET)
262323
;
263324

264-
return (int)USART_ReceiveData(AP_USART);
325+
return (int)USART_ReceiveData(DEBUG_USART);
265326
}
266327

267328
/**

panel_usart.h

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern UartMsg statusMsg;
4141
*/
4242

4343
/**
44-
* @defgroup Macro
44+
* @defgroup AP_Macro
4545
* @{
4646
*/
4747
#define AP_USART USART1
@@ -78,7 +78,7 @@ extern UartMsg statusMsg;
7878
*/
7979

8080
/**
81-
* @defgroup Macro
81+
* @defgroup ST_Macro
8282
* @{
8383
*/
8484
#define ST_USART USART3
@@ -108,11 +108,48 @@ extern UartMsg statusMsg;
108108
* @}
109109
*/
110110

111+
112+
/**
113+
* @defgroup DEBUG_UART
114+
* @brief 用于输出调试信息的串口
115+
* @{
116+
*/
117+
118+
/**
119+
* @defgroup DEBUG_Macro
120+
* @{
121+
*/
122+
#define DEBUG_USART USART6
123+
#define DEBUG_USART_CLK RCC_APB2Periph_USART6
124+
#define DEBUG_USART_BAUDRATE 115200
125+
126+
#define DEBUG_USART_TX_GPIO_PORT GPIOC
127+
#define DEBUG_USART_TX_GPIO_CLK RCC_AHB1Periph_GPIOC
128+
#define DEBUG_USART_TX_PIN GPIO_Pin_6
129+
#define DEBUG_USART_TX_AF GPIO_AF_USART6
130+
#define DEBUG_USART_TX_SOURCE GPIO_PinSource6
131+
132+
#define DEBUG_USART_RX_GPIO_PORT GPIOC
133+
#define DEBUG_USART_RX_GPIO_CLK RCC_AHB1Periph_GPIOC
134+
#define DEBUG_USART_RX_PIN GPIO_Pin_7
135+
#define DEBUG_USART_RX_AF GPIO_AF_USART6
136+
#define DEBUG_USART_RX_SOURCE GPIO_PinSource7
137+
138+
/**
139+
* @}
140+
*/
141+
142+
/**
143+
* @}
144+
*/
145+
146+
111147
/**
112148
* @defgroup Function
113149
* @{
114150
*/
115151
void PANEL_USART_Config(void);
152+
void DEBUG_USART_Config(void);
116153
void AP_USART_Config(void);
117154
void ST_USART_Config(void);
118155
void NVIC_Configuration(void);

stm32f4xx_it.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void AP_USART_IRQHandler(void) {
188188

189189
ucTemp = USART_ReceiveData( AP_USART );
190190

191-
//PANEL_DEBUG("Receive char is %#X, count is %d", ucTemp, uCount);
191+
PANEL_DEBUG("Receive char is %#X, count is %d", ucTemp, uCount);
192192

193193
if ( (ucTemp == statusMsg.MsgFlag) && (uCount == 0) ) { /* 接收到开始标志位,且之前没有收到消息 */
194194

0 commit comments

Comments
 (0)