测试开发板的串口输出。
一、硬件部分
1.1、电路图部分
开发板上有USB转串口TTL部分,电路图如下:

1.2、手册部分资料
串口使用了P110和P109引脚,引脚对应的串口功能,对应的串口9。

二、配置串口
在RASC软件中配置串口。
2.1、配置串口9引脚

2.2、配置串口参数

三、程序部分
3.1、fun_uart.c
#include "hal_data.h"
#include "uart/fun_uart.h"
volatile bool uart9_send_complete_flag = false;
void init_uart(void)
{
R_SCI_UART_Open (&g_uart9_ctrl, &g_uart9_cfg);
}
void g_uart9_callback(uart_callback_args_t *p_args)
{
switch(p_args->event)
{
case UART_EVENT_RX_CHAR:
R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&(p_args->data),1);
break;
case UART_EVENT_TX_COMPLETE:
uart9_send_complete_flag=true;
break;
default:
break;
}
}
int fputc(int ch, FILE *f)
{
(void)f;
R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&ch, 1);
while(uart9_send_complete_flag == false);
uart9_send_complete_flag = false;
return ch;
}
3.2、fun_uart.h
#ifndef FUN_UART_H_
#define FUN_UART_H_
#include <stdio.h>
void init_uart(void);
void senddat(int ch);
#endif
3.3、hal_entry.c
#include "hal_data.h"
#include "led/fun_led.h"
#include "uart/fun_uart.h"
FSP_CPP_HEADER
void R_BSP_WarmStart(bsp_warm_start_event_t event);
FSP_CPP_FOOTER
/*******************************************************************************************************************//**
* main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function
* is called by main() when no RTOS is used.
**********************************************************************************************************************/
void hal_entry(void)
{
/* TODO: add your own code here */
init_uart();
init_led();
while(1)
{
R_BSP_SoftwareDelay(500, BSP_DELAY_UNITS_MILLISECONDS);
led1_on();
led2_off();
led3_on();
R_BSP_SoftwareDelay(500, BSP_DELAY_UNITS_MILLISECONDS);
led1_off();
led2_on();
led3_off();
printf("RA6M4 Board UART9 TEST!\r\n");
}
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}
/*******************************************************************************************************************//**
* This function is called at various points during the startup process. This implementation uses the event that is
* called right before main() to set up the pins.
*
* @param[in] event Where at in the start up process the code is currently at
**********************************************************************************************************************/
void R_BSP_WarmStart (bsp_warm_start_event_t event)
{
if (BSP_WARM_START_RESET == event)
{
#if BSP_FEATURE_FLASH_LP_VERSION != 0
/* Enable reading from data flash. */
R_FACI_LP->DFLCTL = 1U;
/* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
* C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
#endif
}
if (BSP_WARM_START_POST_C == event)
{
/* C runtime environment and system clocks are setup. */
/* Configure pins. */
R_IOPORT_Open(&IOPORT_CFG_CTRL, &IOPORT_CFG_NAME);
#if BSP_CFG_SDRAM_ENABLED
/* Setup SDRAM and initialize it. Must configure pins first. */
R_BSP_SdramInit(true);
#endif
}
}
#if BSP_TZ_SECURE_BUILD
FSP_CPP_HEADER
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();
/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
{
}
FSP_CPP_FOOTER
#endif
四、运行结果
下载程序后,串口输出内容

|