Yuqiang Wang e1498cabc9 SDK build (#47) 5 сар өмнө
..
.settings 4795f3d206 更新fsp为2.2.0 6 сар өмнө
board 4795f3d206 更新fsp为2.2.0 6 сар өмнө
figures eef1e05537 Improve engineering documentation and upload user manual 1 жил өмнө
rzn 0e9a0dfdbd fix iar link source 6 сар өмнө
rzn_cfg 0e9a0dfdbd fix iar link source 6 сар өмнө
rzn_gen 0e9a0dfdbd fix iar link source 6 сар өмнө
script 4795f3d206 更新fsp为2.2.0 6 сар өмнө
src f4bde77e2a 修复gpt 使用pwm 框架 以及其他示例中hal_entry 中的 主循环内容 1 жил өмнө
.api_xml 765c2c53ee upload sample project 1 жил өмнө
.config 4795f3d206 更新fsp为2.2.0 6 сар өмнө
.cproject 4795f3d206 更新fsp为2.2.0 6 сар өмнө
.gitignore 43669c1c97 Fixed some known issues 1 жил өмнө
.project 765c2c53ee upload sample project 1 жил өмнө
.secure_azone 765c2c53ee upload sample project 1 жил өмнө
.secure_rzone 4795f3d206 更新fsp为2.2.0 6 сар өмнө
.secure_xml 4795f3d206 更新fsp为2.2.0 6 сар өмнө
Kconfig 4795f3d206 更新fsp为2.2.0 6 сар өмнө
README.md e1498cabc9 SDK build (#47) 5 сар өмнө
README_zh.md e1498cabc9 SDK build (#47) 5 сар өмнө
SConscript 0e9a0dfdbd fix iar link source 6 сар өмнө
SConstruct 765c2c53ee upload sample project 1 жил өмнө
buildinfo.ipcf 0e9a0dfdbd fix iar link source 6 сар өмнө
buildinfo.json 4795f3d206 更新fsp为2.2.0 6 сар өмнө
configuration.xml 4795f3d206 更新fsp为2.2.0 6 сар өмнө
envsetup.sh 765c2c53ee upload sample project 1 жил өмнө
mklinks.bat 765c2c53ee upload sample project 1 жил өмнө
mklinks.sh 765c2c53ee upload sample project 1 жил өмнө
ozone_scons.jdebug 384e7a31df 修复scons固件无法运行的问题,添加ozone调试脚本 1 жил өмнө
project.ewd 0e9a0dfdbd fix iar link source 6 сар өмнө
project.ewp 0e9a0dfdbd fix iar link source 6 сар өмнө
project.ewt 0e9a0dfdbd fix iar link source 6 сар өмнө
project.eww 765c2c53ee upload sample project 1 жил өмнө
rtconfig.h 4795f3d206 更新fsp为2.2.0 6 сар өмнө
rtconfig.py 384e7a31df 修复scons固件无法运行的问题,添加ozone调试脚本 1 жил өмнө
rzn_cfg.txt 4795f3d206 更新fsp为2.2.0 6 сар өмнө
template.ewd 0e9a0dfdbd fix iar link source 6 сар өмнө
template.ewp 0e9a0dfdbd fix iar link source 6 сар өмнө
template.ewt 0e9a0dfdbd fix iar link source 6 сар өмнө
template.eww 765c2c53ee upload sample project 1 жил өмнө

README.md

RTC and Alarm Usage Instructions

English | 中文

Introduction

This example demonstrates how to use the RTC (Real-Time Clock) on the EtherKit. RTC provides accurate real-time information, such as the year, month, day, hour, minute, and second. Most real-time clock chips use high-precision crystal oscillators as clock sources. Some RTC chips have a battery backup to keep time information valid when the main power supply is off.

RT-Thread’s RTC device provides foundational services for the operating system’s time system. With the increasing number of IoT scenarios, RTCs have become standard in products, and are even indispensable in secure communication protocols like SSL.

Hardware Description

The RTC device used in this example relies on the LSE (Low-Speed External) clock. No other special connections are required.

FSP Configuration Instructions

Open the FSP configuration tool and select the configuration.xml file under the corresponding project directory. Add the RTC Stack:

image-20241126095958347

Next, configure the RTC parameters. Set the RTC stack name to g_rtc, configure the RTC interrupt callback function to rtc_callback, and set the interrupt callback priority:

image-20241126100015969

RT-Thread Settings Configuration

Open RT-Thread Settings and enable the RTC under the hardware options:

image-20241126100054404

Next, configure the RTC by enabling RT-Thread’s RTC device framework and the software alarm feature. (Note: Currently, the alarm feature in Renesas RZ series has some issues, so the alarm function is simulated with software, but this does not affect its usage):

image-20241126100122281

Example Code Description

The source code for this example is located at /projects/etherkit_basic_rtc. In the hal_entry() function, the RTC device is accessed, the system time is set, and then the system time is retrieved to check if it has been set correctly. After a 1-second delay, the system time is retrieved again.

    rt_err_t ret = RT_EOK;
    time_t now;
    rt_device_t device = RT_NULL;

    device = rt_device_find(RTC_NAME);
    if (!device)
    {
      rt_kprintf("find %s failed!\n", RTC_NAME);
    }

    if(rt_device_open(device, 0) != RT_EOK)
    {
      rt_kprintf("open %s failed!\n", RTC_NAME);
    }

    /* Set date */
    ret = set_date(2024, 11, 11);
    rt_kprintf("set RTC date to 2024-11-11\n");
    if (ret != RT_EOK)
    {
        rt_kprintf("set RTC date failed\n");
    }

    /* Set time */
    ret = set_time(15, 00, 00);
    if (ret != RT_EOK)
    {
        rt_kprintf("set RTC time failed\n");
    }

    /* Delay for 3 seconds */
    rt_thread_mdelay(3000);

    /* Get time */
    get_timestamp(&now);
    rt_kprintf("now: %.*s", 25, ctime(&now));

The following code creates an RTC alarm and sets it to trigger in 1 second. Finally, the function is exported to the MSH command line.

void user_alarm_callback(rt_alarm_t alarm, time_t timestamp)
{
    rt_kprintf("user alarm callback function.\n");
}

void alarm_sample(void)
{
    rt_device_t dev = rt_device_find("rtc");
    struct rt_alarm_setup setup;
    struct rt_alarm * alarm = RT_NULL;
    static time_t now;
    struct tm p_tm;

    if (alarm != RT_NULL)
        return;

    /* Get the current timestamp and set the alarm to trigger in the next second */
    now = get_timestamp(NULL) + 1;
    gmtime_r(&now,&p_tm);

    setup.flag = RT_ALARM_SECOND;
    setup.wktime.tm_year = p_tm.tm_year;
    setup.wktime.tm_mon = p_tm.tm_mon;
    setup.wktime.tm_mday = p_tm.tm_mday;
    setup.wktime.tm_wday = p_tm.tm_wday;
    setup.wktime.tm_hour = p_tm.tm_hour;
    setup.wktime.tm_min = p_tm.tm_min;
    setup.wktime.tm_sec = p_tm.tm_sec;

    alarm = rt_alarm_create(user_alarm_callback, &setup);
    if(RT_NULL != alarm)
    {
        rt_alarm_start(alarm);
    }
}
/* Export MSH cmd */
MSH_CMD_EXPORT(alarm_sample, alarm sample);

Compilation & Download

  • RT-Thread Studio: In RT-Thread Studio's package manager, download the EtherKit resource package, create a new project, and compile it.
  • IAR: First, double-click mklinks.bat to create symbolic links between RT-Thread and the libraries folder. Then, use the Env tool to generate the IAR project. Finally, double-click project.eww to open the IAR project and compile it.

After compilation, connect the development board's JLink interface to the PC and download the firmware to the development board.

Run Effect

After pressing the reset button to restart the development board, you should see the following printed information on the board:

 \ | /  
- RT -     Thread Operating System  
 / | \     5.1.0 build Nov 13 2024 13:35:43  
 2006 - 2024 Copyright by RT-Thread team  

Hello RT-Thread!  
==================================================  
This example project is an rtc and alarm routine!  
==================================================  
set RTC date to 2024-11-11  
msh >now: Sat Nov 19 07:42:42 3385  
msh >alarm_sample  
user alarm callback function.  
user alarm callback function.  
user alarm callback function.  
user alarm callback function.