打印

【CPKCOR-RA8D1B核心板】6、指示明灯——串口打印

[复制链接]
2841|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
#申请原创# @21小跑堂 @21小跑堂 @21小跑堂

往期回顾
【CPKCOR-RA8D1B核心板】1、板卡基本信息
【CPKCOR-RA8D1B核心板】2、搭建开发环境
【CPKCOR-RA8D1B核心板】3、离不开的点灯——GPIO输出操作
【CPKCOR-RA8D1B核心板】4、另一种闪烁——非阻塞式闪烁
【CPKCOR-RA8D1B核心板】5、不一样的点灯系列——点呼吸灯

       随着我们使用的功能越来越多,有一些装填判断已经不是那么直观了,比如一些复杂功能的步骤都是很多的,那么如果最后的结果和我们的设想不符,到底问题是出在哪里,这个就不好定位,这个时候串口打印功能就非常适合我们的使用,在一些关键地方加上打印可以直观的进行进程的展示。
本核心板具有调试串口功能,也就是说通过调试连接后实际上虚拟串口也形成了,供电上可以看到:
       看一下原理图:
       实际上对应MCU的Uart3。
       串口通讯(Serial Communication)是一种设备间非常常用的串行通讯方式,因为它简单便捷,因此大部分电子设备都支持该通讯方式,电子工程师在调试设备时也经常使用该通讯方式输出调试信息。 在计算机科学里,大部分复杂的问题都可以通过分层来简化。如芯片被分为内核层和片上外设。对于通讯协议, 我们也以分层的方式来理解,最基本的是把它分为物理层和协议层。物理层规定通讯系统中具有机械、电子功能部分的特性,确保原始数据在物理媒体的传输。协议层主要规定通讯逻辑,统一收发双方的数据打包、解包标准。
       SCI(Serial Communications Interface),意为串行通信接口, 是相对与并行通信的概念,是串行通信技术的一种总称,包括了UART,SPI等串行通信技术。
       我们在FSP中新建一个串口之前先配置一下引脚:
       串口3属于SCI3中的一个分支,然后根据实际使用的引脚进行配置,然后新建串口功能模块:
       “属性”窗口中配置 名字(name)、通道(Channel)、回调函数(Callback)名字即可, 引脚(Pins)、波特率(Baud Rate)等其他的属性按照默认的配置即可:

Name
名字,根据读者需求设置即可。
Channel
通道,根据SCI号设置即可,例如实验使用SCI4,则这里配置为通道4。
Data Bits
每个字(word)的比特(bit)数,默认为8bits
Parity
校验模式,可选择“Odd”奇校验,“Even”偶校验或“None”无校验。
Stop Bits
停止位,可选1或2bit。
Baud Rate
波特率
Baud Rate Modulation
波特率调制,通过调整时钟周期,以减少申请波特率与实际波特率之间的误差。
Max Error(%)
计算波特率时允许的最大百分比误差。
Callback
回调函数的名字,根据读者需求设置即可。
Receive Interrupt Priority
接收中断优先级
Transmit Data Empty Interrupt Priority
发送数据空中断优先级
Transmit End Interrupt Priority
发送完成中断优先级
Error Interrupt Priority
错误中断优先级
       以上是一些常见的参数的含义,可以根据自己的要求进行修改;
       串口打印实际上使用的就是printf函数,这个函数需要使用到堆,默认情况下堆的大小为0,因此我们需要修改堆的大小。 可以在 FSP 配置界面中的“BSP”属性栏的“RA Common”中通过修改“Heap size”来设置堆区大小。 这里需要设置为 8 的整数倍,推荐至少为4K(0x1000):
       注意使用SCI的时候要在“Clocks”里面开启SCI的时钟;
       这个时候我们就需要进行串口的初始化的调用来启动串口了:
fsp_err_t err = FSP_SUCCESS;
err = R_SCI_B_UART_Open (&g_uart3_ctrl, &g_uart3_cfg);
assert(FSP_SUCCESS == err);
      然后就是发送程序的处理,这里有两种方式可以进行数据的发送,可以直接使用 R_SCI_B_UART_Write 函数来将字符串输出到串口:
fsp_err_t R_SCI_B_UART_Write (uart_ctrl_t * const p_api_ctrl, uint8_t const * const p_src, uint32_t const bytes)
             参数 p_src 指向要写入的字符串首地址;
              参数 bytes 为传入的要写入的字符的数目。
       这个在进行复杂多样的串口数据几乎是比较方便和灵活的,不过我们在使用 R_SCI_B_UART_Write 函数需要注意的一些事项:
       若使用了 R_SCI_B_UART_Write() 来发送数据, 在数据发送完成之后会导致 uart_send_complete_flag 这个标志位被置位, 因此程序在调用 R_SCI_UART_Write 函数之后需要等待 uart_send_complete_flag 标志位被置位, 然后将该标志位清零。否则当连续调用 R_SCI_UART_Write 函数时可能导致发送数据丢失。
       如果只是进行一下字符串的传输,建议printf函数将数据发送到串口,很多情况下使用 printf 函数那样方便,需要添加一段代码来将 printf 输出重定向到串口:
<article data-content="[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;zDfd-1728915508213&quot;,&quot;name&quot;:&quot;code&quot;,&quot;data&quot;:{&quot;wrap&quot;:false,&quot;tokensPerLine&quot;:[],&quot;language&quot;:&quot;&quot;,&quot;theme&quot;:&quot;default&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;bIWF-1728915508212&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;4Q7R-1728915508211&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;#if defined __GNUC__ && !defined __clang__&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;0KnP-1728915532904&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;WQKg-1728915532903&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _write(int fd, char *pBuffer, int size); //防止编译警告&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;vQWD-1728915532906&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Ddjc-1728915532905&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _write(int fd, char *pBuffer, int size)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;17dM-1728915532908&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;iqi2-1728915532907&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;{&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;1HkB-1728915532910&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;TERp-1728915532909&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   (void)fd;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Utw0-1728915532912&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;gmf2-1728915532911&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   R_SCI_UART_Write(&g_uart3_ctrl, (uint8_t *)pBuffer, (uint32_t)size);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;6LmN-1728915532914&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Kk6v-1728915532913&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   while(uart_send_complete_flag == false);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;w2dI-1728915532916&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;oJfV-1728915532915&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   uart_send_complete_flag = false;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;q5V3-1728915532918&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;4Hwp-1728915532917&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;wmzF-1728915532920&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;sU5f-1728915532919&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   return size;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;QBj3-1728915532922&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;VHSl-1728915532921&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Dh9s-1728915532924&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;oDeV-1728915532923&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;#else&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Fy2Z-1728915532926&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;IpFa-1728915532925&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int fputc(int ch, FILE *f)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;dXGp-1728915532928&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;AdRN-1728915532927&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;{&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;4lSr-1728915532930&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;zY96-1728915532929&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   (void)f;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;yIBk-1728915532932&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;2SL3-1728915532931&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   R_SCI_B_UART_Write(&g_uart4_ctrl, (uint8_t *)&ch, 1);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;oslL-1728915532934&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Pn2g-1728915532933&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   while(uart_send_complete_flag == false);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;EbfE-1728915532937&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;WKoN-1728915532936&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   uart_send_complete_flag = false;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;ICQ0-1728915532939&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;OuDi-1728915532938&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;uIKw-1728915532941&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;R9Su-1728915532940&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   return ch;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;RtF0-1728915532943&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;nIK5-1728915532942&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;KPYT-1728915532945&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Fdk2-1728915532944&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;#endif&quot;,&quot;marks&quot;:[]}]}]}],&quot;state&quot;:{}}]"><div yne-bulb-block="code" data-theme="default" style="white-space-collapse: preserve;" data-language="">#if defined __GNUC__ && !defined __clang__
int _write(int fd, char *pBuffer, int size); //防止编译警告
int _write(int fd, char *pBuffer, int size)
{
   (void)fd;
   R_SCI_UART_Write(&g_uart3_ctrl, (uint8_t *)pBuffer, (uint32_t)size);
   while(uart_send_complete_flag == false);
   uart_send_complete_flag = false;

   return size;
}
#else
int fputc(int ch, FILE *f)
{
   (void)f;
   R_SCI_B_UART_Write(&g_uart4_ctrl, (uint8_t *)&ch, 1);
   while(uart_send_complete_flag == false);
   uart_send_complete_flag = false;

   return ch;
}
#endif</div></article>
      然后还要在下图位置打开:
       还有一个比较容易忽略的一点就是,不要忘记调用#include"stdio.h"。
       在配置的时候我们定义的了一个Callback函数,这个函数是实际上就是我们串口中断的回调函数,我们需要重写一下:
<article data-content="[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;vLoq-1728915691229&quot;,&quot;name&quot;:&quot;code&quot;,&quot;data&quot;:{&quot;wrap&quot;:false,&quot;tokensPerLine&quot;:[],&quot;language&quot;:&quot;&quot;,&quot;theme&quot;:&quot;default&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;7gqp-1728915691228&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;G5rW-1728915691227&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;volatile bool uart_send_complete_flag = false;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Mvcz-1728915692112&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;gg3C-1728915692111&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;3YSn-1728915692114&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;L65r-1728915692113&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;/* 串口中断回调 */&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;bmuL-1728915692116&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;XPAH-1728915692115&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;void g_uart3_Callback (uart_callback_args_t * p_args){&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;x6sO-1728915692118&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;FUxc-1728915692117&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   switch (p_args->event){&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;iSDq-1728915692120&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;k5gA-1728915692119&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;       case UART_EVENT_RX_CHAR:{&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;shsw-1728915692122&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Zaex-1728915692121&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;            /* 把串口接收到的数据发送回去 */&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;EV99-1728915692124&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;1Xqy-1728915692123&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;            R_SCI_B_UART_Write(&g_uart3_ctrl, (uint8_t *)&(p_args->data), 1);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;jcbO-1728915692126&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;abO8-1728915692125&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;            break;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;0X71-1728915692128&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;pGVR-1728915692127&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;      }&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;dWld-1728915692130&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;GzD1-1728915692129&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;      case UART_EVENT_TX_COMPLETE:{&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;b5Gv-1728915692132&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;GPsC-1728915692131&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;            uart_send_complete_flag = true;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;UtBe-1728915692134&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;lcbd-1728915692133&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;            break;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;di7k-1728915692136&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;RGxd-1728915692135&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;      }&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;dOve-1728915692138&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;x8a6-1728915692137&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;      default:&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;HEG8-1728915692140&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;tkWy-1728915692139&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;            break;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;pPmy-1728915692142&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;mLA6-1728915692141&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;   }&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;k97g-1728915692144&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;rhD2-1728915692143&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]}],&quot;state&quot;:{}}]"><div yne-bulb-block="code" data-theme="default" style="white-space-collapse: preserve;" data-language="">volatile bool uart_send_complete_flag = false;

/* 串口中断回调 */
void g_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 = true;
            break;
      }
      default:
            break;
   }
}</div></article><p>      default:</p><p>            break;</p><p>   }</p><p>}</p>
      可以看到这里简单的写了一个回传函数,和中断发送的处理。
       接下来我们编译一下发现使用printf的时候提示了如下的错误:
       这其实就是一个标准库的使用问题,就目前的使用来说不管是使用STM32CubeIDE还是目前的e2studio,这类最新的基于GCC编译的,貌似都升级了,导致标准库的一些函数无法使用(不兼容),而printf还离不开,最新的IAR也是有这样的一个问题,目前貌似只有keil依然可以直接使用标准库,直接使用printf重定向就可以,而STM32CubeIDE和e2studio需要重写_write,上面的报错说明还有一些基础函数需要定义,为此我们创建一个“printf_redirect.c”,把printf重定向和相关支持函数都放到这里:
<article data-content="[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;WqiP-1728916513752&quot;,&quot;name&quot;:&quot;code&quot;,&quot;data&quot;:{&quot;wrap&quot;:false,&quot;tokensPerLine&quot;:[],&quot;language&quot;:&quot;&quot;,&quot;theme&quot;:&quot;default&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;avTc-1728916513751&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;naYE-1728916513750&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;#include \&quot;hal_data.h\&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;0l5V-1728916526584&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;M4gi-1728916526583&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;#include \&quot;stdio.h\&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;xdfp-1728916526586&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;TOyY-1728916526585&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;#include <sys/stat.h>&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;nOhd-1728916526588&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;YXmy-1728916526587&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;#include <errno.h>&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;UE3i-1728916526590&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Dc0X-1728916526589&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;#undef errno&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;KqsE-1728916526592&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;xJz5-1728916526591&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;extern int errno;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;UUST-1728916526594&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;7uqr-1728916526593&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;5Lg5-1728916526596&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Kb3A-1728916526595&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _write(int file, char *ptr, int len);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;3ETm-1728916526598&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;6tUD-1728916526597&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _close(int file);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;nLTK-1728916526600&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;N1Y8-1728916526599&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _fstat(int file, struct stat *st);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;I2bU-1728916526602&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;NPCH-1728916526601&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _isatty(int file);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;m1ph-1728916526604&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;0wyl-1728916526603&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _read(int file, char *ptr, int len);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;BWtA-1728916526606&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Yquz-1728916526605&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _lseek(int file, int ptr, int dir);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;jPah-1728916526608&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;dPf7-1728916526607&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;amfp-1728916526610&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;0O54-1728916526609&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;#define DEBUG_SERIAL_TIMEOUT 2000/portTICK_PERIOD_MS&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;SDXy-1728916526612&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;3rNz-1728916526611&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;umvg-1728916526614&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;mC2u-1728916526613&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;extern uint8_t uart_send_complete_flag;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;rm7C-1728916526616&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;6nVo-1728916526615&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;I9ci-1728916526618&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;zxqk-1728916526617&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _write(int file, char *ptr, int len)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;MWj5-1728916526620&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;OSkX-1728916526619&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;{&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;r5kp-1728916526622&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;BXUK-1728916526621&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    fsp_err_t err = FSP_SUCCESS;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;mumW-1728916526624&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;ZNkb-1728916526623&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    FSP_PARAMETER_NOT_USED(file);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;s2lc-1728916526626&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Roqy-1728916526625&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;q2CQ-1728916526628&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;SH49-1728916526627&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    static bool uart_open = false;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;d3G4-1728916526630&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;mYBj-1728916526629&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;N5Su-1728916526632&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;wTAH-1728916526631&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    if (false == uart_open)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;6ksn-1728916526634&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;EqGz-1728916526633&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    {&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;UlCD-1728916526636&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;3IHQ-1728916526635&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        err = R_SCI_B_UART_Open(&g_uart3_ctrl, &g_uart3_cfg);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;eUpb-1728916526638&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;IuXs-1728916526637&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    }&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;TSdn-1728916526640&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;JqkC-1728916526639&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;EHdy-1728916526642&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;WRc6-1728916526641&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    if (FSP_SUCCESS == err)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;NCJ3-1728916526644&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;U4a0-1728916526643&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    {&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;8gM5-1728916526646&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;JH6N-1728916526645&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;          err = R_SCI_B_UART_Write(&g_uart3_ctrl, (uint8_t *)ptr, (uint32_t)len);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Ksv9-1728916526648&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;xhVE-1728916526647&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    }&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;4mg8-1728916526650&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;f5Ji-1728916526649&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;GDsn-1728916526652&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;xzQo-1728916526651&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    if (FSP_SUCCESS != err)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;xufW-1728916526654&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;UxgR-1728916526653&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    {&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Iecm-1728916526656&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;bI9z-1728916526655&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        len = -1;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;I43R-1728916526658&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;2VY1-1728916526657&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    }&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;HzB7-1728916526660&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;fync-1728916526659&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;vLnk-1728916526662&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;GYJI-1728916526661&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    while(uart_send_complete_flag == 0)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;9TfF-1728916526664&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;1Y9C-1728916526663&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    {&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;i5IN-1728916526666&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;ctgx-1728916526665&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;        R_BSP_SoftwareDelay(10, BSP_DELAY_UNITS_MILLISECONDS);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;TcUR-1728916526668&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;hM6l-1728916526667&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    }&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;DvGz-1728916526670&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;zCgG-1728916526669&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    uart_send_complete_flag = 0;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;g8Gr-1728916526672&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;RH1q-1728916526671&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;p3Ow-1728916526674&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;6EFV-1728916526673&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    return len;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;4rPG-1728916526676&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;NNzk-1728916526675&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;I2K5-1728916526678&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;dIZ1-1728916526677&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;d5Va-1728916526680&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;cxv6-1728916526679&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _close(int file)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;mTnI-1728916526682&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;qEVb-1728916526681&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;{&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;nrdo-1728916526684&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;0Epc-1728916526683&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;  FSP_PARAMETER_NOT_USED(file);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;6Zl8-1728916526686&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;zs04-1728916526685&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;  return -1;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;I5bv-1728916526688&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;WfYr-1728916526687&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;WwyF-1728916526690&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;KOZE-1728916526689&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _fstat(int file, struct stat *st)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;blpS-1728916526692&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;lMdt-1728916526691&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;{&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;DR9w-1728916526695&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;ipfS-1728916526694&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    FSP_PARAMETER_NOT_USED(file);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;A4Y1-1728916526697&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;TGcv-1728916526696&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;  st->st_mode = S_IFCHR;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;SO0o-1728916526699&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;hoFV-1728916526698&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;  return 0;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;hqFf-1728916526701&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;TMIG-1728916526700&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Nt69-1728916526703&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;cr1d-1728916526702&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;JHbg-1728916526705&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Xkh0-1728916526704&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _isatty(int file)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;aaFB-1728916526707&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;176b-1728916526706&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;{&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;kpqD-1728916526709&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;qkBn-1728916526708&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    FSP_PARAMETER_NOT_USED(file);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;wD7t-1728916526711&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;R1mc-1728916526710&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;  return 1;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;uvi3-1728916526713&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;axVc-1728916526712&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;yF7n-1728916526715&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;RCy6-1728916526714&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;nmwM-1728916526717&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;zYrV-1728916526716&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _lseek(int file, int ptr, int dir)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Po5k-1728916526719&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;EzVD-1728916526718&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;{&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;MNGK-1728916526721&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;rjGS-1728916526720&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    FSP_PARAMETER_NOT_USED(file);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;ok1y-1728916526723&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;pPNo-1728916526722&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    FSP_PARAMETER_NOT_USED(ptr);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;EX0A-1728916526725&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;3MIj-1728916526724&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    FSP_PARAMETER_NOT_USED(dir);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;UZ6v-1728916526727&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;2Rjl-1728916526726&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;  return 0;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Pnnk-1728916526729&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;MER4-1728916526728&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;ZHhd-1728916526731&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;1zBc-1728916526730&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;nlFk-1728916526733&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Jbpc-1728916526732&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;int _read(int file, char *ptr, int len)&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;v6Hi-1728916526735&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;tE9U-1728916526734&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;{&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;RTqw-1728916526737&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;KPnt-1728916526736&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    FSP_PARAMETER_NOT_USED(file);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;PDal-1728916526739&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;l2Q9-1728916526738&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    FSP_PARAMETER_NOT_USED(ptr);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;kqgL-1728916526741&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;3rUf-1728916526740&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    FSP_PARAMETER_NOT_USED(len);&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;LnBn-1728916526743&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;viop-1728916526742&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    return 0;&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;EvCB-1728916526745&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;gEtk-1728916526744&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;}&quot;,&quot;marks&quot;:[]}]}]}],&quot;state&quot;:{}}]"><div yne-bulb-block="code" data-theme="default" style="white-space-collapse: preserve;" data-language="">#include "hal_data.h"
#include "stdio.h"
#include <sys/stat.h>
#include <errno.h>
#undef errno
extern int errno;

int _write(int file, char *ptr, int len);
int _close(int file);
int _fstat(int file, struct stat *st);
int _isatty(int file);
int _read(int file, char *ptr, int len);
int _lseek(int file, int ptr, int dir);

#define DEBUG_SERIAL_TIMEOUT 2000/portTICK_PERIOD_MS

extern uint8_t uart_send_complete_flag;

int _write(int file, char *ptr, int len)
{
    fsp_err_t err = FSP_SUCCESS;
    FSP_PARAMETER_NOT_USED(file);

    static bool uart_open = false;

    if (false == uart_open)
    {
        err = R_SCI_B_UART_Open(&g_uart3_ctrl, &g_uart3_cfg);
    }

    if (FSP_SUCCESS == err)
    {
          err = R_SCI_B_UART_Write(&g_uart3_ctrl, (uint8_t *)ptr, (uint32_t)len);
    }

    if (FSP_SUCCESS != err)
    {
        len = -1;
    }

    while(uart_send_complete_flag == 0)
    {
        R_BSP_SoftwareDelay(10, BSP_DELAY_UNITS_MILLISECONDS);
    }
    uart_send_complete_flag = 0;

    return len;
}

int _close(int file)
{
  FSP_PARAMETER_NOT_USED(file);
  return -1;
}
int _fstat(int file, struct stat *st)
{
    FSP_PARAMETER_NOT_USED(file);
  st->st_mode = S_IFCHR;
  return 0;
}

int _isatty(int file)
{
    FSP_PARAMETER_NOT_USED(file);
  return 1;
}

int _lseek(int file, int ptr, int dir)
{
    FSP_PARAMETER_NOT_USED(file);
    FSP_PARAMETER_NOT_USED(ptr);
    FSP_PARAMETER_NOT_USED(dir);
  return 0;
}

int _read(int file, char *ptr, int len)
{
    FSP_PARAMETER_NOT_USED(file);
    FSP_PARAMETER_NOT_USED(ptr);
    FSP_PARAMETER_NOT_USED(len);
    return 0;
}</div></article>
      准备工作以及一些报错问题都解决了,接下来我们可以编译下载了
       可以看到串口数据收发正常,在初始化完成后加了一个printf也打印成功,这里就实现了串口通信的基本功能。


使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

认证:硬件工程师
简介:有着多年硬件开发经验的专业人员,专注于医疗电子领域,热衷于对新鲜事物的探索,喜欢DIY!

300

主题

1742

帖子

8

粉丝