You are on page 1of 26

LAB PROCEDURE

RL78 Project Configuration Tips


RL78 Family
Description: The purpose of this lab is to allow the user who is unfamiliar with the Renesas e2studio
development environment for RL78 device to quickly come up to speed by following the tips for creating,
configuring, managing, and debugging the embedded software. This lab will provide an in-depth look at
the option byte setting, section configuration, optimization options, interrupt configuration, startup files
review, and add necessary initialization code in the project template to run on the target board.

Lab Objectives Lab Materials


1. Learn Project wizard configuration Please verify you have the following materials at
2. Learn clock/interrupt configuration your lab station.
3. Learn option byte/security ID configuration • Laptop PC with e studio
2

4. Learn section configuration • GNU compiler version 12.02 or later


5. Learn optimization configuration • RL78/G14 RDK board
• This lab sheet

Skill Level Time to Complete Lab


2
1. New to RL78/ e studio Tools 2 hours

Lab Sections
1 e2studio Project Wizard Tips ................................................................. 2
2 Review Renesas Project Template........................................................ 7
3 Interrupt configuration ......................................................................... 11
4 Option Byte and Security Byte configuration ....................................... 16
5 Section Configuration .......................................................................... 19
6 Optimization Configuration .................................................................. 23

RL78 Project Configuration Tips Page 1 of 26


LAB PROCEDURE
1 e2studio Project Wizard Tips
2
This lab section will create an RL78 project using e studio Project Wizard while learning tips for how to
select the various wizard options to configure best for the RL78 device. The project uses RL78/G14 family
device, R5F104PJAFB, the device used on the RL78/G14 RDK board.

Procedural Steps
2 2
Step 1.1 Start -> All Programs -> Renesas Electronics e studio -> Renesas e studio.

Step 1.2 In the Workspace Launcher, select C:\Workspace or any other directory where you want to
create the project.

Step 1.3 A window similar to the one will appear. Close the “Welcome” window.

RL78 Project Configuration Tips Page 2 of 26


LAB PROCEDURE

Step 1.4 Click “FileNew  C Project”, a below window will open. Enter the below information and
click Next.

Project name: myRL78Project

Project type: Executable (Renesas) -> Sample Project

Toolchains: KPIT GNURL78-ELF Toolchain

RL78 Project Configuration Tips Page 3 of 26


LAB PROCEDURE

Several ‘Project Types’ choices can be seen here depending on what tools are
installed and registered in the e2studio environment. The project type will determine the
toolchain and tabs that CDT (C/C++ Development Tooling) uses. A short summary of
Project types are:

 Executable (Renesas): Create a Renesas project template which


includes IO register definition, startup file, and basic project setup
files.
 Debug- Only Project: Mainly used when Third party tools are used.
 Makefile project: Creates an empty project. This selection is useful for
importing and modifying existing make-file based projects.

Step 1.5 Make the following selection in the window and click Next:

Toolchain Version  v12.02.

Debug Hardware  E1 (RL78)

Select Target  R5F104PJ


Select Configurations from List
Below Use Default setting
(Check mark on Hardware debug
and Release (no debug))

If there are many version of the same tools chain installed in the PC, e2studio will
show option for all the Toolchain Versions. The default selection is the latest version.

Step 1.6 Select additional CPU option. Leave this window to its default options and Click Next.

RL78 Project Configuration Tips Page 4 of 26


LAB PROCEDURE

Step 1.7 The next window selects the library. Leave this window to its default options and Click Finish.

The Library source selection:


Newlib : Complete ISO C library supporting C/C++ code.
Optimized: Subset of ISO C library, size-optimised, does not fully support
C++ code but sufficient for most of the application.

RL78 Project Configuration Tips Page 5 of 26


LAB PROCEDURE
Step 1.8 The following summary window will open. Click OK to generate the project.

Step 1.9 Your project workspace should now look like this:

Step 1.10 Build the project,”Project->Build All” and observe the output in Console window. The Project
Template compiles with no error.

RL78 Project Configuration Tips Page 6 of 26


LAB PROCEDURE
2 Review Renesas Project Template
2
This section reviews RL78 project template created by the e studio project wizard and add necessary
initialization code to run the code on the target board.

This section also configures the template project to blinks LED15 every 100 ms with interval timer
interrupt. The microcontroller peripheral used in the project are GPIO port P41 and Interval timer.

Procedural Steps
Step 2.1 Open and review the startup file “reset_program.asm “under “src” folder by double click on
the file name in “Project Explorer” window. The contents will open in the editor panel. The
snippets below are sections from the file.

The basic functionality includes:


o stack Pointer Initialization
o Copy Data section from ROM to RAM
o Clear the uninitialized RAM area
o Call Hardware initialization function
o main and exit function call

stack pointer initialization Copy Data section from ROM to RAM

mov es, #0
movw sp,#_stack /* Set sel rb0 /* ;;bank 0 */
stack pointer */ movw de, #_mdata /* src ROM address of data */
movw hl, #_data /* dest start RAM address */
sel rb1 /* bank 1 */
movw hl, #_data /* dest start RAM address of
data section in hl */
movw ax, #_edata /* ;; size of romdata
section in ax */
subw ax,hl /* store data size */
shrw ax,1
1:
cmpw ax, #0 /* check if end of
data */
bz $1f
decw ax
sel rb0 /* bank 0 */
movw ax, es:[de]
movw [hl], ax
incw de
incw de
incw hl
incw hl
sel rb1 /* bank 1 - compare and
decrement*/
br $1b
1:decrement*/
br $1b

RL78 Project Configuration Tips Page 7 of 26


LAB PROCEDURE
Step 2.2 Clear the uninitialized RAM area

Clear RAM area for non-initialized RAM (bss)

sel rb0 /* bank 0 */


movw hl, #_bss /* store the start address of bss in hl */
movw ax, #0 /* load AX reg with zero */
sel rb1 /* bank 1 */
movw ax, #_ebss /* store the end address (size of) bss section in ax
*/
subw ax,hl ;; store data size
shrw ax,1
1:
cmpw ax, #0
bz $1f
decw ax
sel rb0 /* bank 0 */
movw [hl], ax
incw hl
incw hl
sel rb1
br $1b
1:
sel rb0 /* bank 0 */

Step 2.3 The startup routine calls the HardwareSetup function before calling the main() function in the
program. The HardwareSetup() function is part of the template and added in the
“hardware_setup.c” file. If the user does not add any initialization code in the
HardwareSetup() function, the process returns without doing anything and control is
transferred to the main() function.

Hardware Initialization main and exit function call

call !!_HardwareSetup call !!_main

/* call to exit*/
_exit:
br $_exit

The startup routine in the reset_program.asm is called before the user application
executes main( ) function.

RL78 Project Configuration Tips Page 8 of 26


LAB PROCEDURE
Step 2.4 Open hardware_setup.c file. The Renesas project template doesn’t include the clock
Initialization code. Add the below clock initialization function in the hardware_setup.c file.
//RL78 Clock Initialization

#include "iodefine.h" //Add this line on the top of the file


#include "iodefine_ext.h" //Add this line on the top of the file

//Add below code after the HardwareSetup() function


void CLOCK_Init(void)
{
unsigned int i;

/* Set fMX */
CMC = 0x14;
MSTOP = 1;
MCM0 = 0;
/* Set fSUB */
XTSTOP = 0;

/* Software wait 5us or more */


for( i=0U; i<=100; i++ )
{
asm("nop");
}
OSMC = 1;
/* Set fCLK */
CSS = 0U;
/* Set fIH */
HIOSTOP = 0;
}

Step 2.5 We will be using the GPIO port P41 and Interval timer in our example code. Add the below
code to Initialize the GPIO port P41 and Interval Timer in the hardware_setup.c file:

//Port and Timer Initialization

//Port Initialization
void PORT_Init(void)
{
PM4_bit.no1 =0 ; //Make pin P41 as an output pin.
}

//Timer Initialization
void IT_Init(void)
{
RTCEN = 1U; /* supply RTC clock */
ITMC = 0; /* disable ITMC operation */
ITMK = 1U; /* disable INTIT interrupt */
ITIF = 0U; /* clear INTIT interrupt flag */
/* Set INTIT low priority */
ITPR1 = 1U;
ITPR0 =1;
ITMC = 0x5DB; /*100ms timer count */
}

RL78 Project Configuration Tips Page 9 of 26


LAB PROCEDURE
Step 2.6 Add below function in the hardware_setup.c file to start/stop the Interval timer

// Timer start/stop function

//Timer start
void IT_Start(void)
{
ITMC |= 0x8000U;; /* enable IT operation */
ITIF = 0U; /* clear INTIT interrupt flag */
ITMK = 0U; /* enable INTIT interrupt */}

//Timer stop
void IT_Stop(void)
{
ITMK = 1U; /* disable INTIT interrupt */
ITIF = 0U; /* clear INTIT interrupt flag */
ITMC &= 000U;; /* disable IT operation */
}

Step 2.7 Review the function “HardwareSetup() in the hardware_setup.c file.

hardware_setup.c

void HardwareSetup(void)
{

HardwareSetup() function is the same function called in the startup


routine in the reset_program.asm file. The purpose of this function is to
initialize the HW before control is transferred to main program.

Step 2.8 Add following highlighted line inside the HardwareSetup() function in the hardware_setup.c file
to initialize the port and interval timer before main() function is called.

RL78 Project Configuration Tips Page 10 of 26


LAB PROCEDURE
// hardware_setup.c file

void HardwareSetup(void)
{
asm("di"); //Add this line inside the function
CLOCK_Init(); //Add this line inside the function
PORT_Init(); //Add this line inside the function
IT_Init(); //Add this line inside the function
asm("ei"); //Add this line inside the function

All the peripheral initialization code can be called in the


HardwareSetup() function to initialize the peripherals before main ()
function is called.

Step 2.9 Open myRL78Project.c file. Add the highlighted code inside the main() function to start the
timer.

//myRL78Project.c

int main(void)
{
// TODO: add application code here
IT_Start(); //Add this line inside the function
while (1) {
}
return 0;
}

3 Interrupt configuration
This section continues to review the RL78 project template and provide an example how to configure the
interrupt in the project template by taking interval timer example.

Procedural Steps

Step 3.1 Open vector_table.c and review the vector initialization. All the vectors in the R5F104PJ
device are pre-initialized here. The snippets below are sections from the file.

RL78 Project Configuration Tips Page 11 of 26


LAB PROCEDURE

Initializes all the vectors in the device

INT_IICA0,
// Address 0x2C
INT_TM00,
// Address 0x2E
INT_TM01,
// Address 0x30
INT_TM02,
// Address 0x32
INT_TM03,
// Address 0x34
INT_AD,
// Address 0x36
INT_RTC,

Step 3.2 The Renesas template includes the default interrupt handler for all the interrupts. Open the
interrupt_handlers.c and see the default interrupt handler routine for each interrupt. The
snippets below are sections from the file.

Default interrupt handler function


//0x4
void INT_WDTI (void) {
}
//0x6
void INT_LVI (void) {
}

The user can modify or replace the default handler with the
application specific interrupt handler.

Step 3.3 Go to interrupt_handlers.c file and add the following highlighted code to interrupt service
routine for the Interval timer, ~line no. 157. By adding the below code will blink the LED15
on target board every 100 ms.

//interrupt_handler.c file
Step 3.4
#include "iodefine.h" //Add this line on the top B
#include "iodefine_ext.h" //Add this line on the top u
i
void INT_IT (void) { l
P4_bit.no1^=1; //Add this line inside the function. d
}
t
he project, “Project Build All”. The Console window will show the below output.

RL78 Project Configuration Tips Page 12 of 26


LAB PROCEDURE

Step 3.5 Connect the RDK board to PC via USB cable. Make sure RDK board has DIP switch SW5
setting as below:
1: ON, 2: OFF, 3: ON, 4: ON

Step 3.6 Go to “Run Debug Configuration”.

RL78 Project Configuration Tips Page 13 of 26


LAB PROCEDURE

Step 3.7 Click on myRL78Project under “Renesas GDB Hardware Debugging”.

RL78 Project Configuration Tips Page 14 of 26


LAB PROCEDURE
Step 3.8 Click on the Startup tab and put a check mark on the “Halt”.

Step 3.9 Click “Debug” button to start the debugger.

Step 3.10 Click yes, to confirm the perspective switch from C/C++ to Renesas Debug perspective.

RL78 Project Configuration Tips Page 15 of 26


LAB PROCEDURE
Step 3.11 Open interrupt_handler.c file under Debug perspective. Put a break in the following line of
code, line number 157 (approx).

Step 3.12 Run the program by clicking the Resume button . The program will first break at main()
function. This breakpoint is set automatically in the debugger configuration setting and can be
removed by the user.

Step 3.13 Click Resume button to run the program again. The program will break at Interval timer
interrupt function.

Step 3.14 Remove the break point from the Interval timer interrupt function.

Step 3.15 Click Resume button to run the program and observe the LED15 on the RDK board.

4 Option Byte and Security Byte configuration


Overview:
This section reviews the option byte and security byte setting in the project template.

Procedural Steps

Step 4.1 Click Suspend button to stop running the program.

Step 4.2 Switch to the C/C++ perspective, by clicking the C/C++ option on top right corner of the
debug perspective window. If this option is not shown in the window, you may want to click
on the expand button as >> to make this option visible.

Step 4.3 Go to “Run Debug Configuration”. In the window open, click on myRL78Project under
“Renesas GDB Hardware Debugging”.

RL78 Project Configuration Tips Page 16 of 26


LAB PROCEDURE

Step 4.4 Click on the “Debugger” tab and Go to “Connection Settings”. You will see the default
Security ID bit setting as all 0s. Leave this setting at a default setting and close the window.

RL78 Project Configuration Tips Page 17 of 26


LAB PROCEDURE
Step 4.5 Open vector_table.c file. Review the security ID setting at Line 21 in the code. This is the
security ID bit set in the device when project is loaded on the device. The user can change
this code to any other code to stop preventing the code read by the debugger.

The security ID bits are compared, when the new project is loaded on to the
device later with the current project security ID bits which is already on the
device. If security ID is mismatched, the debugger will not start and required to
erase the flash before the debug session can be started.

Step 4.6 Review the Option Byte setting at Line 17. The four option bytes mainly sets the WDT, LVD,
On chip oscillator frequency, and enable/disable the OCD debugger.

Step 4.7 Modify the first Option Byte setting which configures the WDT and located at 0xC0 as 0xee
from 0xef.

Step 4.8 Build the project,”Project-> Build All”.

Step 4.9 A new window will appear which will ask to Reload the new image to the debug session. Click
yes on the below window.

Step 4.10 Switch to Renesas debug perspective.

RL78 Project Configuration Tips Page 18 of 26


LAB PROCEDURE
Step 4.11 Go to “Window->Show View Memory”. Click on the + sign. Enter the address as 0xC0 to
view the option byte value at address 0xC0.

Step 4.12 Confirm the new option byte 0xEF at address 0xC0.

Step 4.13 Click terminate button to stop the debugger.

The RL78 option bytes are located from address 0xC0 to 0xC3. The option
byte at address 0xC0 configures the watchdog timer, 0xC1 configured LVD,
0xC2 configures on chip oscillator speed, and 0xC3 enables or disables the OCD
debugger.

The Security ID allows an authentication check before the debug session is


started. The default Security ID of an erased device is 10 times 0xFF.

5 Section Configuration
Overview:
This section provides how to locate a C code in the specific memory area by creating a new section in the
code.

Procedural Steps

Step 5.1 Switch back to the C/C++ Perspective.

Step 5.2 Right click on your project name in the Project Explorer pane and select “Properties”. The
below window will open.

RL78 Project Configuration Tips Page 19 of 26


LAB PROCEDURE

Step 5.3 Navigate to “C/C++ Build > Settings”. The below window will open.

Step 5.4 In the “Tool Settings” Tab, you will see several options as compiler, assembler and linker etc.
Select “Linker -> Sections”.

RL78 Project Configuration Tips Page 20 of 26


LAB PROCEDURE

Step 5.5 Create a New Section by clicking add section button. The default section name will
be .section1. In the “Sections details” enter the below information:

Name: .newsection

Fixed Address: 0xFF000

RL78 Project Configuration Tips Page 21 of 26


LAB PROCEDURE
Step 5.6 Right click on section name and click add expression.

Step 5.7 The default expression name will be .expression shown as below.

Step 5.8 “Enter the Expression Name” as “.mysection” and click “Apply” button. Click OK to exit the
window.

RL78 Project Configuration Tips Page 22 of 26


LAB PROCEDURE
Step 5.9 Once Section has been created, add the following highlighted code in the myRL78Project.c to
demonstrate placing a function in a specified area of memory:

myRL78Project.c

#include "iodefine.h"

//Add below line


void myfunction (void) __attribute__ ((section (".mysection")));
unsigned int j = 0; //Add this line

int main(void)
{
IT_Start();

while (1) {
myfunction(); //Add this line
}
return 0;
}
//Add below function
void myfunction(void)
{
j++;
}

Step 5.10 Build the Project, “Project->Build All”.

Step 5.11 Open myRL78Project.map file under “HardwareDebug” folder in the “Project Explorer”
window. Confirm the section allocation in the map file at 0xFF000.

Question
3. Can you confirm the size of the section .mysection created in the
above example?

6 Optimization Configuration
Overview:
This section covers how to configure the optimization setting for RL78 project.

RL78 Project Configuration Tips Page 23 of 26


LAB PROCEDURE
Procedural Steps
Step 6.1 Right click on your project name in the Project Explorer pane and select “Renesas Quick
Settings”. Review the Optimization level setting and Click Finish.

The optimization for Template project is disabled by default.

Step 6.2 Add the below line of code inside the main() function in myRL78Project.c file.

int main(void)
{
int x; //Add this line

if(x < 0 && x > 0) //Add this line


{ //Add this line
x = 99; //Add this line
} //Add this line
IT_Start();
while (1) {
myfunction();
}
return 0;
}

RL78 Project Configuration Tips Page 24 of 26


LAB PROCEDURE
Step 6.3 Build the project, “ProjectBuild All”.

Step 6.4 Open myRL78Project.list file under HardwareDebug folder in the Project explorer. Review the
assembly code for the added c code lines in Step 6.2.

Step 6.5 Right click on your project name in the Project Explorer pane and select “Renesas Quick
Settings”. Change the Optimization level to” Speed and Size”. Build the project,”Project
Build all”.

RL78 Project Configuration Tips Page 25 of 26


LAB PROCEDURE
Step 6.6 Open the myRL78Project.list file and review the assembly code for the added c code lines.
Observe the optimized code. The code added in the above steps has been optimized by the
compiler.

Question
4. What feature can be configured from the Renesas Quick setting
window?
5. What are the optimization options available from the Renesas
Quick setting?

RL78 Project Configuration Tips Page 26 of 26

You might also like