TLLED 发表于 2026-7-20 23:49:06

【瑞萨RA-eco-RA6M4评测】串口测试

测试开发板串口输出。



一、硬件部分

开发板上自带USB-TTL串口电路,连接到串口9对应的P110和P109引脚



二、配置串口


使用RASC软件配置串口9.


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、main.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)
{
        init_uart();
        init_led();
        while(1)
        {
                R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
                led1_on();
                led2_off();
                led3_off();
                R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
                led1_off();
                led2_on();
                led3_off();
                R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
                led1_off();
                led2_off();
                led3_on();
                printf("RA-eco-RA6M4 uart 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.
*
* @paramevent    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


四、运行结果

下载程序后,串口输出

页: [1]
查看完整版本: 【瑞萨RA-eco-RA6M4评测】串口测试

Baidu
map