瑞萨单片机william hill官网
直播中

jf_66383146

2年用户 18经验值
擅长:嵌入式技术 EMC/MEI设计 EDA/IC设计
私信 关注

【瑞萨RA4系列开发板体验】+ E2 studio 初体验LED点灯和printf重定向

A.非常感谢william hill官网 和瑞萨的活动

B.没有用过瑞萨的开发环境,上手比较简单,要深入还是需要时间研究,逻辑和stm32还是有比较大的区别

话不多说直接入主题

1.打开E2左上角 file->new project

如图

0.png

2.依次点击 renesas RA-> renesas RA C/C++ project->next

1.png

3.输入项目名称(不能含中文和中文符号)

2.png

选择自己的芯片型号

3.png

进入工程界面

4.png

配置堆栈大小

5.png

配置串口

6.png

原理图是P110,P109

7.png

LED配置

8.png

LED原理图

9.png

printf重定向

快捷键 ctrl+alt+p进入项目设置

a.png

hal_entry.c 函数

#include "hal_data.h"
#include <stdio.h> //必须包含标准库

FSP_CPP_HEADER
void R_BSP_WarmStart(bsp_warm_start_event_t event);
FSP_CPP_FOOTER

fsp_err_t err = FSP_SUCCESS;
unsigned char send_buff[100];
volatile bool uart_send_complete_flag = false;
void user_uart_callback(uart_callback_args_t *p_args)
{
    if (p_args->event == UART_EVENT_TX_COMPLETE)
    {
        uart_send_complete_flag = true;
    }
}

#ifdef __GNUC__                                 //串口重定向
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE
{
    err = R_SCI_UART_Write (&g_uart9_ctrl, (uint8_t*) &ch, 1);
    if (FSP_SUCCESS != err)
        __BKPT();
    while (uart_send_complete_flag == false)
    {
    }
    uart_send_complete_flag = false;
    return ch;
}

int _write(int fd, char *pBuffer, int size)
{
    for (int i = 0; i < size; i++)
    {
        __io_putchar (*pBuffer++);
    }
    return size;
}
void hal_entry(void) //入口函数
{
    /* TODO: add your own code here */

    /* Open the transfer instance with initial configuration. */

    err = R_SCI_UART_Open (&g_uart9_ctrl, &g_uart9_cfg); //初始化串口和使能
    assert(FSP_SUCCESS == err);
    int int_i = 55;
    float float_i = 66.20f;
    char char_i[] = "hello e2studio";
    while (1)
    {
        R_IOPORT_PinWrite (&g_ioport_ctrl, BSP_IO_PORT_04_PIN_15, BSP_IO_LEVEL_LOW);//LED灭
        R_BSP_SoftwareDelay (500, BSP_DELAY_UNITS_MILLISECONDS); // 延时0.5s
        printf ("int_i=%d\r\n", int_i);
        printf ("float_i=%.2f\r\n", float_i);
        printf ("char_i='%s'\r\n", char_i);

        R_IOPORT_PinWrite (&g_ioport_ctrl, BSP_IO_PORT_04_PIN_15, BSP_IO_LEVEL_HIGH);//LED亮
        R_BSP_SoftwareDelay (500, BSP_DELAY_UNITS_MILLISECONDS); // 延时0.5s
    }
#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 (&g_ioport_ctrl, g_ioport.p_cfg);
    }
}

#if BSP_TZ_SECURE_BUILD

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 ()
{

}
#endif

编译输出

b.png

串口输出

c.png

更多回帖

发帖
×
20
完善资料,
赚取积分