Professional Documents
Culture Documents
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
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.
Step 1.4 Click “FileNew C Project”, a below window will open. Enter the below information and
click Next.
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:
Step 1.5 Make the following selection in the window and click Next:
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.
Step 1.7 The next window selects the library. Leave this window to its default options and Click Finish.
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.
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.
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
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.
/* call to exit*/
_exit:
br $_exit
The startup routine in the reset_program.asm is called before the user application
executes main( ) function.
/* Set fMX */
CMC = 0x14;
MSTOP = 1;
MCM0 = 0;
/* Set fSUB */
XTSTOP = 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 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 */
}
//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 */
}
hardware_setup.c
void HardwareSetup(void)
{
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.
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
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.
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.
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.
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.10 Click yes, to confirm the perspective switch from C/C++ to Renesas Debug perspective.
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.
Procedural Steps
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”.
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.
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.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.12 Confirm the new option byte 0xEF at address 0xC0.
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.
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.2 Right click on your project name in the Project Explorer pane and select “Properties”. The
below window will open.
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”.
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
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.
myRL78Project.c
#include "iodefine.h"
int main(void)
{
IT_Start();
while (1) {
myfunction(); //Add this line
}
return 0;
}
//Add below function
void myfunction(void)
{
j++;
}
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.
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
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”.
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?