测试调试串口输出。
一、硬件电路
与JLINK仿真器连接的串口USART3,电路图部分如下
使用的端口是P408和P409。
二、串口配置
2.1、配置串口端口和波特率
2.2、设置串口时钟
三、代码
3.1、bsp_debug_uart3.c
#include "bsp_debug_uart.h"
void Debug_UART3_Init(void)
{
fsp_err_t err = FSP_SUCCESS;
err = R_SCI_B_UART_Open (&g_uart3_ctrl, &g_uart3_cfg);
assert(FSP_SUCCESS == err);
}
uint8_t uart_send_complete_flag = 0;
void debug_uart3_callback (uart_callback_args_t * p_args)
{
switch (p_args->event)
{
case UART_EVENT_RX_CHAR:
{
R_SCI_B_UART_Write(&g_uart3_ctrl, (uint8_t *)&(p_args->data), 1);
break;
}
case UART_EVENT_TX_COMPLETE:
{
uart_send_complete_flag = 1;
break;
}
default:
break;
}
}
3.2、bsp_debug_uart.h
#ifndef __BSP_DEBUG_UART_H
#define __BSP_DEBUG_UART_H
#include "hal_data.h"
#include "stdio.h"
void Debug_UART3_Init(void);
#endif
3.3、hal_entry.c
#include "hal_data.h"
#include "led/led.h"
#include "debug_uart/bsp_debug_uart.h"
fsp_err_t err;
void R_BSP_WarmStart(bsp_warm_start_event_t event);
//extern bsp_leds_t g_bsp_leds;
/*******************************************************************************************************************//**
* [url=home.php?mod=space&uid=159083]@brief[/url] Blinky example application
*
* Blinks all leds at a rate of 1 second using the software delay function provided by the BSP.
*
**********************************************************************************************************************/
void hal_entry (void)
{
init_led();
Debug_UART3_Init();
while (1)
{
printf("https://bbs.eeworld.com.cn!\r\n");
/* if(R_BSP_PinRead (BSP_IO_PORT_00_PIN_08)==0)
{
led201_on();
}
else
{
led201_off();
}*/
/* Delay */
//R_BSP_SoftwareDelay(delay, bsp_delay_units);
R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
led201_on();
R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
led201_off();
}
}
四、运行结果
五、附件
|