Skip to main content
Renesas Electronics America - Knowledgebase

Running Blinky with an RTC

Latest Updated:10/04/2016


This self paced learning exercise show you how to create a Blinky design (Blink an LED on your Synergy board) using a simple RTC based implementation. This exercise uses brief descriptions of several common actions within the tool flow. This assumes you are somewhat familiar with the various operations within e2 studio. Feel free to 'pop out' of this guide and refresh your understanding of e2 studio operations by referring to the Starting Development section of the <SSP User's Manual> where each step is shown in more detail.


After completing this how-to you will have created a simple HAL based RTC program that illustrates how to initialize, and use RTC api calls and the associated interrupt callback function. Once you understand how this example operates you will be ready to move on to more complex designs.


Initial Set-Up

You must first have the Synergy software tool flow installed and a target Synergy board available to see Blinky work in hardware. If you don't, follow the below link to the SSP User's Manual, and read the SSP Overview and Starting Development sections. 

Create Your Project

If you followed the previous step you should have the Synergy Platform tool flow working and you should have exercised your target board, most likely with the introductory version of Blinky. Now you are ready for a HAL based version using the RTC and an interrupt callback function.

  1. Open e2 studio and create a new Synergy Project (refer back to the SSP User's Manual if you need a reminder).
  2. Target your board and select the BSP option.
  3. You should now have familiar a starting point for adding Blinky code.

Add RTC Blinky Code

In this step you will add the code for implementing the RTC based version of Blinky.

  1. Open the Threads Tab in the Configuration Window.
  2. Select the HAL components in the Threads window.
  3. Click on New> next to the HAL Modules Window.
  4. Select RTC Driver on RTC to add g_rtc RTC Driver on RTC to the HAL Modules window.
  5. Select g_rtc RTC Driver on RTC in the HAL Modules window.
  6. In the Properties tab change the Callback from NULL to periodic_callback.
  7. In the ICU tab find the RTC Interrupt and set RTC PRD to Priority 4.
  8. Press the Generate Project Content button.
  9. You should now have a file called hal_entry.c in the srs directory
  10. Open hal_entry.c and replace all the code below the first line comment with the following code:

/* HAL-only entry function */
#include "hal_data.h"
bsp_leds_t Leds;
ioport_level_t level = IOPORT_LEVEL_HIGH;
/* Set up the RTC periodic interrupt to fire once every second */
void periodic_interrupt_setup(void) {
/* Open the real time clock driver */
g_rtc.p_api->open(g_rtc.p_ctrl, g_rtc.p_cfg);
/* Set the periodic interrupt rate */
/* Start the counter */
/* Enable periodic interrupts */
g_rtc.p_api->irqEnable(g_rtc.p_ctrl, RTC_EVENT_PERIODIC_IRQ);
/* Close the real time clock driver */
/* periodic ISR that toggles a GPIO pin */
void periodic_callback(rtc_callback_args_t * p_args) {
if (p_args->event == RTC_EVENT_PERIODIC_IRQ)
  level = !level;
  g_ioport_on_ioport.pinWrite(Leds.p_leds[0], level);
void hal_entry(void) {
/* Get LED information for this board */
/* If this board has no LEDs then trap here */
if (!Leds.led_count)
  while(1); // There are no LEDs on this board
while (1);
  1. Save the changes to the file and build the debug configuration of your project.
  2. The design should build without errors. If not, look carefully at your added code.You may have missed or added some characters. When your code builds without errors, you are ready to run RTC Blinky on your target board.

Run RTC Blinky on Your Board

  1. Connect your board as you did when running your previous example design.
  2. Initialize the Debugger and select your new project build configuration.
  3. Click the Debug button to bring up the debug perspective.
  4. The debug session will halt at the beginning of the design, so you need to press the Resume button twice to get it to begin execution on your board.
  5. Your LED should now be blinking on and off. It should stay on for 1 second and then go off for 1 second until you pause or stop the debug session.
  6. You have completed your first interrupt callback design using the RTC with the Synergy Platform!

How RTC Blinky Works

RTC Blinky begins operation in the hal_entry as you may have noticed in previous examples (such as Regular Blinky). The first section of code in hal_entry adds the key include file, hal_data.h which brings in the HAL infrastructure needed by the balance of the design. If you inspect hal_data.h you will see it brings in several more include files for each of the peripherals and their associated api.h files. This file also sets up the g_rtc, g_ioport, g_elc and periodic_callback elements for use in hal_entry.c. After the include statement hal_entry.c identifies the two variables, Leds (to identify the location of the LED used on the board) and level (to identify the value of the signal driving the LED) used in the body of hal_entry.c.

The first function for RTC Blinky is the initialization code for the RTC. First the api call to open the RTC driver is used. The g_rtc structure, located in the hal_data.c file, uses three elements- .p_ctrl (the control block), .p_cfg (the configuration block) and .p_api (the api function block). Note the data initializing the g_rtc_cfg element is from the data entered into the RTC Properties window when g_rtc RTC Driver on RTC was configured. Similar elements are created for g_ioport and g_elc.

The various api functions available for he RTC are created in the SSP generated file r_rtc.c (located in the ssp/src/driver/r_rtc folder). These functions, including the ones used in RTC Blinky, are shown in the image below. Remember that r_rtc.c is auto generated and shouldn't be edited or changed in any way.


Take note of how RTC Blinky accesses the api functions used to control the RTC module. For example, the code listed below uses the g_rtc global variable to access the api structure selecting the open function. The parameters for the function are the g_rtc control (.p_ctrl) and g_rtc congiguration (.p_cfg) blocks provided in hal_data.c as previously described. Other RTC api calls use a similar format.

Open the real time clock driver */

g_rtc.p_api->open(g_rtc.p_ctrl, g_rtc.p_cfg);

The RTC is initialized with a periodic interrupt rate of 1 second, started and interrupts are enabled. The driver can then be closed.

The periodic callback function defines the interrupt service routine 'work'. It first checks to see if the interrupt event is the expected periodic IRQ. If the IRQ is as expected the level of the LED driving signal is toggled and the signal is written to the io port pin identified when the BSP function R_BSP_LedsGet is used to identify the first LED available on the target board (done in the hal_entry routine just below periodic_callback). 

The hal_entry function calls the above described R_BSP_LedsGet function to identify the LED to toggle (which allows RTC Blinky to work on any board with the Synergy BSP). If an LED exists, the periodic_interrupt_setup is called and the program enters a continuous loop. While in the loop the RTC interrupt will occur, every second, and the LED will toggle.

What's Next

Now that you have completed this example design here are some suggestions for building on this exercise to extend your knowledge and skills with the Synergy Platform.

Please provide feedback on this article by using the feedback buttons below.

  • Was this article helpful?