TLLED 发表于 2026-7-19 22:11:36

【瑞萨RA-eco-RA6M4评测】搭建编译环境并驱动LED灯

搭建开发板编译环境并驱动LED灯。

一、下载软件

下载编译软件v6.5版,下载地址:https://github.com/renesas/fsp/releases#release-v6.5.0

下载完成后,安装软件;


二、配置硬件

2.1、在MDK工程中设置RASC
选择安装的6.5版本的rasc



2.2、配置开发板
根据开发板的硬件,配置时钟和LED灯对应的GPIO引脚
2.2.1、配置时钟
开发板上的时钟是12MHz

选择外部12MHz晶振



2.2.2、配置LED端口
LED部分电路图中对应的端口



配置LED端口


三、程序代码


3.1、fun_led.c
#include "hal_data.h"
#include "led/fun_led.h"

void init_led(void)
{
        led1_off();
        led2_off();
        led3_off();
}

3.2、fun_led.h
#ifndef FUN_LED_H_
#define FUN_LED_H_
#include "r_ioport.h"

#define LED1_PORT    BSP_IO_PORT_00_PIN_02
#define LED2_PORT    BSP_IO_PORT_04_PIN_04
#define LED3_PORT    BSP_IO_PORT_04_PIN_05

#define led1_on()R_IOPORT_PinWrite(&g_ioport_ctrl, LED1_PORT, BSP_IO_LEVEL_HIGH)
#define led2_on()R_IOPORT_PinWrite(&g_ioport_ctrl, LED2_PORT, BSP_IO_LEVEL_HIGH)
#define led3_on()R_IOPORT_PinWrite(&g_ioport_ctrl, LED3_PORT, BSP_IO_LEVEL_HIGH)

#define led1_off()R_IOPORT_PinWrite(&g_ioport_ctrl, LED1_PORT, BSP_IO_LEVEL_LOW)
#define led2_off()R_IOPORT_PinWrite(&g_ioport_ctrl, LED2_PORT, BSP_IO_LEVEL_LOW)
#define led3_off()R_IOPORT_PinWrite(&g_ioport_ctrl, LED3_PORT, BSP_IO_LEVEL_LOW)

void init_led(void);

#endif

3.3、main.c
#include "hal_data.h"
#include "led/fun_led.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_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();
        }

#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评测】搭建编译环境并驱动LED灯

Baidu
map