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

STEP2:選芯片型號(hào)跟IDE類型

STEP3:選擇芯片型號(hào)

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

STEP5:勾選確認(rèn)工程

STEP6:配置串口號(hào)跟IO口

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

STEP8:配置串口

STEP9:配置串口基本屬性

STEP10:生成工程

3.代碼
STEP11:打開(kāi)工程

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.結(jié)果
STEP19:接上串口工具,打印如下

-
mcu
+關(guān)注
關(guān)注
147文章
18392瀏覽量
379053
發(fā)布評(píng)論請(qǐng)先 登錄
【RA-Eco-RA6M4開(kāi)發(fā)板評(píng)測(cè)】搭建基于keil的開(kāi)發(fā)環(huán)境+串口打印+LED點(diǎn)亮
【RA-Eco-RA6M4開(kāi)發(fā)板評(píng)測(cè)】實(shí)現(xiàn)keil環(huán)境的搭建+串口打印+LED點(diǎn)亮
【RA4M2-SENSOR】介紹、環(huán)境搭建、工程測(cè)試
瑞薩RA2L1 MCU e2 studio和FSP的使用指南

【RA-Eco-RA6M4開(kāi)發(fā)板評(píng)測(cè)】1、開(kāi)發(fā)環(huán)境搭建和串口打印信息
【RA-Eco-RA6M4開(kāi)發(fā)板評(píng)測(cè)】——2.串口打印
【RA4L1-SENSOR】+ RA4L1-SENSOR開(kāi)發(fā)版之使用Jlink的RTT打印功能代替串口
【RA4L1-SENSOR】+ RA4L1-SENSOR開(kāi)發(fā)版串口打印功能printf實(shí)現(xiàn)
【RA-Eco-RA4M2開(kāi)發(fā)板評(píng)測(cè)】使用Jlink的RTT來(lái)實(shí)現(xiàn)串口打印功能
【RA-Eco-RA4M2開(kāi)發(fā)板評(píng)測(cè)】RA-Eco-RA4M2 串口通信
HSE FW AB分區(qū)作后如何控制 MCU 串口打印 HSE 狀態(tài)?
【瑞薩RA2L1入門學(xué)習(xí)】02. 串口打印 ADC 檢測(cè)電壓
基于瑞薩RA0E1開(kāi)發(fā)板的ThreadX實(shí)時(shí)操作系統(tǒng)串口回顯測(cè)試

評(píng)論