RA MCU 生態(tài)工作室致力于構建一個完善的 RA 生態(tài),這將會是一個好玩有趣的開放社區(qū),也提供各種RA相關問題的解決方法。
1.概述
通過RASC創(chuàng)建一個串口工程,具體配置如下,用戶可以根據(jù)自己定義來配置串口相關的基本參數(shù)。
2.創(chuàng)建工程
STEP1:RASC創(chuàng)建工程

STEP2:選芯片型號跟IDE類型

STEP3:選擇芯片型號

STEP4:選擇無操作系統(tǒng)

STEP5:勾選確認工程

STEP6:配置串口號跟IO口

STEP7:添加串口驅(qū)動

STEP8:配置串口

STEP9:配置串口基本屬性

STEP10:生成工程

3.代碼
STEP11:打開工程

STEP12:添加代碼

STEP13:具體代碼如下
void hal_entry( void )
{
/* TODO: add your own code here */
fsp_err_t err = R_SCI_UART_Open( &g_uart9_ctrl, &g_uart9_cfg );
assert( FSP_SUCCESS == err );
while ( true )
{
printf( "Hello RA MCU \r\n" );
}
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}
STEP14:添加頭文件跟串口回調(diào)函數(shù)

STEP15:具體代碼如下
#include "hal_data.h"
#include "stdio.h"
FSP_CPP_HEADER
void R_BSP_WarmStart( bsp_warm_start_event_t event );
FSP_CPP_FOOTER
uint8_t g_transfer_complete = 0;
void g_uart9_cb( uart_callback_args_t* p_args )
{
/* Handle the UART event */
switch ( p_args->event )
{
/* Received a character */
case UART_EVENT_RX_CHAR:
{
break;
}
/* Receive complete */
case UART_EVENT_RX_COMPLETE:
{
break;
}
/* Transmit complete */
case UART_EVENT_TX_COMPLETE:
{
g_transfer_complete = 1;
break;
}
default:
{
}
}
}
STEP16:添加打印接口重定向代碼,具體如下
/*******************
*
* Copyright 1998-2017 IAR Systems AB.
*
* This is a template implementation of the "__write" function used by
* the standard library. Replace it with a system-specific
* implementation.
*
* The "__write" function should output "size" number of bytes from
* "buffer" in some application-specific way. It should return the
* number of characters written, or _LLIO_ERROR on failure.
*
* If "buffer" is zero then __write should perform flushing of
* internal buffers, if any. In this case "handle" can be -1 to
* indicate that all handles should be flushed.
*
* The template implementation below assumes that the application
* provides the function "MyLowLevelPutchar". It should return the
* character written, or -1 on failure.
*
********************/
#include
#pragma module_name = "?__write"
int MyLowLevelPutchar(int x)
{
R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&x, 1);
while(g_transfer_complete == 0);
g_transfer_complete = 0;
return x;
}
/*
* If the __write implementation uses internal buffering, uncomment
* the following line to ensure that we are called with "buffer" as 0
* (i.e. flush) when the application terminates.
*/
size_t __write(int handle, const unsigned char * buffer, size_t size)
{
/* Remove the #if #endif pair to enable the implementation */
#if 1
size_t nChars = 0;
if (buffer == 0)
{
/*
* This means that we should flush internal buffers. Since we
* don't we just return. (Remember, "handle" == -1 means that all
* handles should be flushed.)
*/
return 0;
}
/* This template only writes to "standard out" and "standard err",
* for all other file handles it returns failure. */
if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR)
{
return _LLIO_ERROR;
}
for (/* Empty */; size != 0; --size)
{
if (MyLowLevelPutchar(*buffer++) < 0)
{
return _LLIO_ERROR;
}
++nChars;
}
return nChars;
#else
/* Always return error code when implementation is disabled. */
return _LLIO_ERROR;
#endif
}
4.工程配置
STEP17:工程配置

STEP18:彈出如下窗口

5.結果
STEP19:接上串口工具,打印如下

-
mcu
+關注
關注
146文章
17984瀏覽量
367184
發(fā)布評論請先 登錄
【RA-Eco-RA6M4開發(fā)板評測】——2.串口打印
【RA4L1-SENSOR】+ RA4L1-SENSOR開發(fā)版之使用Jlink的RTT打印功能代替串口
【RA4L1-SENSOR】+ RA4L1-SENSOR開發(fā)版串口打印功能printf實現(xiàn)
【RA-Eco-RA4M2開發(fā)板評測】使用Jlink的RTT來實現(xiàn)串口打印功能
【RA-Eco-RA4M2開發(fā)板評測】RA-Eco-RA4M2 串口通信
【RA-Eco-RA4M2開發(fā)板評測】RA-Eco-RA4M2 Keil 開發(fā)環(huán)境搭建
【RA-Eco-RA4M2開發(fā)板評測】1 RA4M2開發(fā)環(huán)境搭建
HSE FW AB分區(qū)作后如何控制 MCU 串口打印 HSE 狀態(tài)?
瑞薩RA8快速上手指南:Cortex-M85內(nèi)核瑞薩RA8開發(fā)環(huán)境搭建 并點亮一個LED

【瑞薩RA2L1入門學習】02. 串口打印 ADC 檢測電壓
基于瑞薩RA0E1開發(fā)板的ThreadX實時操作系統(tǒng)串口回顯測試

【RA-Eco-RA4E2-64PIN-V1.0開發(fā)板試用】串口打印功能
【RA-Eco-RA2E1-48PIN-V1.0開發(fā)板試用】(第二篇)串口打印+SPI_OLED顯示
【RA-Eco-RA2E1-48PIN-V1.0開發(fā)板試用】使用Jlink RTT完成printf打印功能
【GD32 MCU 入門教程】一、GD32 MCU 開發(fā)環(huán)境搭建(2)使用 IAR 開發(fā) GD32

評論