Preview only show first 10 pages with watermark. For full document please download

Rl78 Microcontroller Usb Peripheral Firmware Updater Gnu/iar Ver.

   EMBED


Share

Transcript

APPLICATION NOTE RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Summary This application note describes the firmware update program created for the USB controller incorporated in the RL78 microcontrollers with USB peripheral GNU/IAR version. This application note provides the following information:  The specifications for the sample driver  Information about the environment used to develop an application program by using the sample driver  The reference information provided for using the sample driver Target devices RL78/G1C, RL78/L1C When this application note is applied to other microcontrollers, make the necessary changes according to the specifications of the microcontroller and verify them thoroughly. Contents 1. Overview ........................................................................................................................................... 2 2. Overview of Updating the USB Peripheral Firmware ........................................................................ 4 3. EXECUTING THE SAMPLE PROGRAM FOR UPDATING THE USB PERIPHERAL FIRMWARE 7 4. FIRMWARE UPDATE PROGRAM ................................................................................................. 16 5. FILE TRANSFER APPLICATION ................................................................................................... 50 6. CREATING A PROGRAM ............................................................................................................... 62 7. DATA COMMUNICATION SPECIFICATIONS ............................................................................... 69 8. Setup for the e2 studio project ......................................................................................................... 74 R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 1 of 76 RL78 microcontroller 1. USB Peripheral Firmware Updater GNU/IAR Ver. Overview This application note describes the firmware updater using the RL78 microcontroller. This document is intended to be used together with the device’s data sheet of Chapter1.2 1.1 Functions and Features The firmware updater can update of user program to the Full-Speed Universal Serial Bus Specification (USB from now on and description). 1.2 1. 2. Related Documents Universal Serial Bus Revision 2.0 specification Battery Charging Specification Revision 1.2 [http://www.usb.org/developers/docs/] RL78 microcontroller User’s Manual: Hardware CS+ Integrated Development Environment User's Manual: RL78,78K0R Coding USB Basic Mini Firmware application note USB Peripheral Communications Device Class Driver (PCDC) for Basic Mini Firmware application note RL78 Family Flash Self Programming Library Type01 application note Available from the Renesas Electronics Website 3. 4. 5. 6. 7.  Renesas Electronics Website http://www.renesas.com/ USB Devices Page http://www.renesas.com/prod/usb/  1.3 Note Please do the following works since the Flash Self Library (FSL) is not included in this project. 1. Get the Flash Self Library for RL78. 2. Copy the Flash Self Library in the "src\FSL" folder. src\FSL\lib\fsl.a src\FSL\lib\fsl.h src\FSL\lib\fsl_type.h 3. Set the include path and the library path for the Flash Self Library to the compiler and linker. 1.4 List of Terms Terms and abbreviations used in this document are listed below. API APL cstd CS+ CDP DCP HBC Data Transfer : : : : : : : : EVA EWRL78 : e2 studio : Application Program Interface Application program Prefix for peripheral & host common function of USB-BASIC-F/W Renesas integration development environment (for RL78) Charging Downstream Port Dedicated Charging Port Host Battery Charging control Generic name of Bulk transfer and Interrupt transfer (When the host mode is selected, the Control transfer is contained.) Evaluation board IAR Embedded Workbench for RL78 IAR integration development environment (for RL78) Eclipse embedded studio R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 2 of 76 RL78 microcontroller HCD HDCD HEW HM hstd H/W MGR PBC PCD PDCD PP pstd RSK Scheduler Scheduler Macro SDP Task UPL USB USB-BASIC-F/W : : : : : : : : : : : : : : : : : : : USB Peripheral Firmware Updater GNU/IAR Ver. Host control driver of USB-BASIC-F/W Host device class driver (device driver and USB class driver) High-performance Embedded Workshop Hardware Manual Prefix for host function of USB-BASIC-F/W Renesas USB device Sequencer of HCD to manage state of the peripheral device Peripheral Battery Charging control Peripheral control driver of USB-BASIC-F/W Peripheral device class driver (device driver and USB class driver) Pre-processed definition Prefix for peripheral function of USB-BASIC-F/W Renesas Starter Kit Used to schedule functions, like a simplified OS. Used to call a scheduler function Standard Downstream Port Processing unit User Programming Layer (Upper layer of USB-BASIC-F/W:HDCD, PDCD, APL or etc) Universal Serial Bus Peripheral & Host USB basic firmware(USB low level) for Renesas USB MCU R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 3 of 76 RL78 microcontroller 2. USB Peripheral Firmware Updater GNU/IAR Ver. Overview of Updating the USB Peripheral Firmware The sample program used to update the USB Peripheral firmware uses the file transfer application on the host (computer) to transfer the specified files to the evaluation board by means of USB serial communication. These files are then written to the boot area for the user-created program or to a memory location using the self-programming library. The sample program used to update the USB Peripheral firmware includes the following:  Firmware update program This program is written to the memory on the evaluation board and overwrites the USB Peripheral firmware via USB serial communication.  File transfer application The file transfer application runs on the host and transfers the specified files to the evaluation board using serial communication.  Sample user-created program This is a group of HEX files used to confirm that the programs are running correctly.  For RL78/G1C and RL78/L1C RSK board Program 1: Shown to the LCD upper row of a RSK board with "Program1". Program 2: Shown to the LCD lower row of a RSK board with "Program2". The flow of data when updating the USB Peripheral firmware is shown below. File transfer application User-created program Firmware update program USB connection CDC Host Data transferred from the host is written to memory (Memory image) Evaluation board Figure 2-1 Flow of Data When Updating USB Peripheral Firmware Usually, the user-created program runs when the evaluation board is started up. However, the firmware update program will run when the evaluation board is started up under certain conditions or when the evaluation board is reset. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 4 of 76 RL78 microcontroller 2.1 USB Peripheral Firmware Updater GNU/IAR Ver. Features The sample program for updating the USB Peripheral firmware has the following features:  The firmware update program uses 16 blocks (16 KB) of internal flash memory.  The user-created program (HEX files) can be overwritten in Motorola S-record format or Intel extended HEX format.  Data can be written to any area in the memory by specifying memory addresses.  All types of interrupts can be used in the user-created program. The on-chip resources used by the firmware update program are shown in Table 2-1. Table 2-1 Internal Resources Used by Firmware Update Program Size (Bytes) Resource Name Usage RL78/G1C ROM program IAR (including boot strap and library) GNU Self programming library IAR Firmware update 11.5kB (14 KB RL78/L1C Note 1 ) 11.4kB (14 KBNote 1) 780 (1 KBNote 2) 780 (1 KBNote 2) 1 KB 1 KB 3.1 KB 3.1 KB 1034 1034 1252Note 3 1252Note 3 GNU User reset vector saving area IAR GNU RAM For firmware update program IAR GNU For self programming library IAR GNU Stack area IAR GNU Notes 1. Basic Mini Firmware include PCDC. 2. Allocated size for block 3. Maximum value R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 5 of 76 RL78 microcontroller 2.2 USB Peripheral Firmware Updater GNU/IAR Ver. Folder organization The folders in the sample program for updating the USB Peripheral firmware are organized as shown. (Top Directroy) +―reference | +―cdc_inf | | Sample INF file for Windows.(CDC_Demo.inf) | +―FirmupdateGUI | | | FWUpdate GUI Software.(UsbfUpdate.exe / UsbfUpdate.ini) | | +―source | | FWUpdate GUI Software source code. | +―FWUpdate_sampleHex | User sample software for FWUpdate. +―workspace +―USB_FWUpdate_nonOS_Rev101_BasicMiniRev213_e2studio | GNU Ver. USB Peripheral Firmware Update program project file +―USB_FWUpdate_nonOS_Rev101_BasicMiniRev213_IAR IAR Ver. USB Peripheral Firmware Update program project file The contents of these folders are described below. (1) reference\cdc_inf This folder stores the CDC driver for WindowsTM. CDC_Demo.inf: CDC driver for Windows(Windows XP/Vista/7/8(※) 32/64bit ver.) (※) To request a digital signature in Windows8, please use a digital signature by the setting which isn't forced. Please refer to help of Windows of the setting. (2) reference\FirmupdateGUI This folder stores the file transfer application. UsbfUpdate.exe: Executable file for the file transfer application UsbfUpdate.ini: Configuration file for the file transfer application (3) reference\FirmupdateGUI\source This folder stores the source program for the file transfer application. For details about this application, see 5.FILE TRANSFER APPLICATION. (4) reference\FWUpdate_sampleHex This folder stores the sample user-created program.  For RL78/G1C and RL78/L1C RSK board Program1\FWUpdate_sampleHex.hex: Program2\FWUpdate_sampleHex.hex: (5) LCD first line “Program1” LCD second line “Program2” workspace This folder stores the firmware update program. For details about this program, see 4.FIRMWARE UPDATE PROGRAM. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 6 of 76 RL78 microcontroller 3. USB Peripheral Firmware Updater GNU/IAR Ver. EXECUTING THE SAMPLE PROGRAM FOR UPDATING THE USB PERIPHERAL FIRMWARE This chapter describes how to execute the sample program for updating the USB Peripheral firmware. It's explained about IAR edition. In this chapter, the RL78/G1C RSK board is used to confirm that the user program has been updated in order of touch panel program and then photo frame program. 3.1 Operating Environment The hardware environment is as follows:  Evaluation board  Evaluation board CPU  In-circuit emulator  USB cable  Host RL78/G1C RSK Board R5F10JGC ( RL78/G1C ) E1 Emulator For executing serial communication between the evaluation board and host Computer running Windows7 The software environment is as follows:  Integrated development environment IAR Embedded Workbench  Compiler iccrl78  Flash Writer Renesas Flash Programmer  Sample program for updating USB Peripheral firmware, which includes the following:  Firmware update program  File transfer application  Sample user-created program R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 7 of 76 RL78 microcontroller 3.2 USB Peripheral Firmware Updater GNU/IAR Ver. Executing the Sample Program The operating environment in which the sample program for updating the USB Peripheral firmware is executed and the procedure for overwriting the firmware are shown below. 3.2.1 Running the firmware update program (1) To run the firmware update program, connect E1 emulator and the evaluation board. The following figure illustrates the connections. E1 emulator USB bus power connect RL78-RSK Board Figure 3-1 Connecting E1 emulator to the Evaluation Board R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 8 of 76 RL78 microcontroller (2) USB Peripheral Firmware Updater GNU/IAR Ver. Start Renesas Flash Programmer, select “RL78G1C.hex”, and then download the firmware update program to the target board Figure 3-2 Specifying the Workspace File Remark For details about Renesas Flash Programmer, visit the following URL: http://www.renesas.com/products/tools/flash_prom_programming/rfp/index.jsp R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 9 of 76 RL78 microcontroller 3.2.2 USB Peripheral Firmware Updater GNU/IAR Ver. Updating the firmware information (1). To update the firmware information, disconnect E1 emulator, and then connect the host to the evaluation board using the USB cable. The following figure illustrates the connections. USB bus power RL78-RSK Board Figure 3-3 Connecting the Host to the Evaluation Board (2). Press the SW1 on the evaluation board and then press the RESET button. When the mode changes to update mode, LCD upper line “FWUpdate” and LCD lower line “Ready” , indicating that the host is ready to transfer data. Caution The CDC driver must be installed the first time the mode changes to update mode after connecting the host to the RL78/G1C RSK board. For details, see 3.2.3. Installing the CDC driver. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 10 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. (3). Load the HEX files of the sample user-created program to be transferred to the evaluation board into the host by specifying “FWUpdate_sampleHex.hex” from the 1-second timer count program. Start the file transfer application on the host (see Figure 3-5). Click the Load File button, and then select the HEX file to be transferred. The file can be specified by typing the file path directly into the Path textbox, or by dragging the file path and dropping it into the Path textbox. Under Mode, select Chip. In the COM drop-down list, select the USB port to which the host is connected. The USB port can be identified in the Device Manager window. Caution The COM number differs depending on the environment. Figure 3-4 Device Manager R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 11 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. Figure 3-5 Selecting the File to Be Transferred by the File Transfer Application (4). Click the Update button in the USB Function Firmware Updater window. A message indicating the start of transfer is displayed, the files are transferred, and the firmware information is updated. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 12 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. (5). When the file transfer and firmware information update are complete, the file transfer application displays a message indicating the end of file transfer. This also means that the firmware information has been updated. Figure 3-6 End of Firmware Update (6). Then reset the evaluation board. Start the user-created program that was written to the evaluation board in the previous steps.Output the LCD upper line “Program1”. (7). Update the user-created program. Load the LCD lower line “Program2” program “FWUpdate_sampleHex.hex” and execute the above procedure again from step (4). (8). Then reset the evaluation board. Start the user-created program that was written to the evaluation board in the previous steps.Output the LCD lower line “Program2”. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 13 of 76 RL78 microcontroller 3.2.3 USB Peripheral Firmware Updater GNU/IAR Ver. Installing the CDC driver The CDC driver must be installed on the host the first time the mode changes to update mode after connecting the host to the RSK board. The procedure for installing the CDC driver is shown below, using the Windows7 environment as an example. (1) Device Manager open, and select Update Driver Software. Select “Browse my computer for driver software”. Figure 3-7 Update driver Software (2) Under Search for driver software in this locations, select Include subfolders.. Click Browse, select the folder that includes the file “CDC_Demo.inf”, and then click Next. Figure 3-8 Selecting the Driver Location R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 14 of 76 RL78 microcontroller (3) USB Peripheral Firmware Updater GNU/IAR Ver. A warning message appears. Click Install this driver software anyway. Figure 3-9 Warning Message (4) The installation wizard ends with the following window. Click Close. Figure 3-10 End of Installation R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 15 of 76 RL78 microcontroller 4. USB Peripheral Firmware Updater GNU/IAR Ver. FIRMWARE UPDATE PROGRAM This chapter describes the files used by the firmware update program. 4.1 Organization of Files and Folders The files and folders that store the source code of the firmware update program are organized as follows.  (MCU name) Project file + Peripheral_FWUpdate Build result + src + ――― USBSTDFW[Common USB code that is used by all USB firmware] | + ――― inc Common header file of USB driver | + ――― src USB driver + ――― SmplMain[Firmware Update sample application] | + ――― APL Firmware update sample application + ―――PCDC [Peripheral Communication Device Class driver] | + ――― inc Common header file of CDC Class | + ――― src CDC Class driver + ―――FSL [Flash Self Programming Library] | + ――― lib FSL library(※) + ―――HwResouce [Hardware access layer; to initialize the MCU] + ――― inc Hardware resource header file + ――― src Hardware resouce (※) FSL library file of IAR/GNU edition isn't bundled. Please download it from Renesas Electronics Web page in Americas area or Europe area . It isn't possible to download to the certain area. Figure 4-1 Organization of Firmware Update Program Folders R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 16 of 76 RL78 microcontroller 4.1.1 USB Peripheral Firmware Updater GNU/IAR Ver. (MCU name) folder This folder stores the project files used by the firmware update program. The main project files in the Project folder are shown in Table 4-1 below. Table 4-1 Project Files Used by the Firmware Update Program File Name Description RL78G1C.eww EWRL78 workspace file (For RL78/G1C) RL78L1C.eww EWRL78 workspace file(For RL78/L1C) RL78G1C\.cproject e2studio workspace file(For RL78/G1C) RL78L1C\.cproject e2studio workspace file(For RL78/L1C) 4.1.2 src\FSL folder This folder stores Flash Self Programming Library files used by the firmware update program. Please put the FSL library downloaded from Web site of Renesas Electronics to the following folder and do build. (*) Table 4-2 Header Files Used by the Firmware Update Program File Name Description IAR/GNU lib\fsl.h Flash Self Programming Library header file. Common file lib\fsl_types.h Flash Self Programming Library defining data types header file. IAR version lib\fsl.r87 Flash Self Programming Library(IAR version) GNU version lib\fsl.a Flash Self Programming Library(GNU version) (*)A FSL file of IAR/GNU edition isn't bundled. Please download it from a Web page in America area or Europe area in Renesas Electronics. It isn't possible to download to the certain area. 4.1.3 src\SmplMain folder This folder stores the source files for the firmware update program. Table 4-3 Source Files for Firmware Update Program File Name Description main.c File containing main function in C APL\r_usb_fwupdate_apl.c File containing firmware update programming processing. APL\r_usb_fwupdate_apl_descriptor.c Descriptor and Endpoint information. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 17 of 76 RL78 microcontroller 4.1.4 USB Peripheral Firmware Updater GNU/IAR Ver. src\PCDC folder This folder stores the source files and header files used by the CDC program. For details, please refer to the USB Peripheral Communications Device Class Driver (PCDC) for Basic Mini Firmware application note. 4.1.5 src\USBSTDFW folder This folder stores the source files and header files used by the USB-BASIC-F/W program. For details, please refer to the USB-BASIC-F/W application note. 4.1.6 Peripheral_FWUpdate folder This folder stores the executable object file and HEX file used by the firmware update program. Table 4-4 Object Files Used by the CDC Program Development MCU environment name IAR File Name RL78/G1C RL78G1C.d87 RL78G1C.hex RL78/L1C RL78L1C.d87 RL78L1C.hex GNU RL78/G1C USB_FWUpdate_nonOS_Rev100_BasicMiniRev212_G1C.x USB_FWUpdate_nonOS_Rev100_BasicMiniRev212_G1C.mot RL78/L1C USB_FWUpdate_nonOS_Rev100_BasicMiniRev212_L1C.x USB_FWUpdate_nonOS_Rev100_BasicMiniRev212_L1C.mot R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Description Executable object file Executable object file in HEX format Executable object file Executable object file in HEX format Executable object file Executable object file in HEX format Executable object file Executable object file in HEX format Page 18 of 76 RL78 microcontroller 4.2 USB Peripheral Firmware Updater GNU/IAR Ver. Memory Map This section describes the memory allocation and the linker directive file. The RL78/G1C is used in this example. 4.2.1 Memory map The memory map of the self-update program is shown below. In the memory map below, block refers to the unit in which the on-chip flash memory is updated by the selfprogramming library. SFR General-purpose registers F FEE0 H RAM F ED09 H F E900 H 2nd SFR Used by self programming library F 0000 H Use prohibited 0 8000 H Flash Block 31 Program area ROM area ・・・ 0 6000 H Firmware Update Program Flash Block 8 - 23 0 2000 H Program area 0 10CE H Security Boot cluster 1 0 10C4 H ・・・ Option byte 0 10C0 H CALLT table 0 1080 H Flash Block 4 Vector table 0 1000 H Program area 0 00CE H Security 0 00C4 H Boot cluster 0 ・・・ Option byte 0 00C0 H CALLT table 0 0080 H Flash Block 0 Vector table 0 0000 H Figure 4-2 Memory Map R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 19 of 76 RL78 microcontroller 4.2.2 USB Peripheral Firmware Updater GNU/IAR Ver. Mapping by a segment definition The memory is mapped by defining segments. When it's IAR, territory is allocated in link directive file r_usb_fwupdate.xcl. When it's GNU, territory is allocated by section designation of Linker in Renesas Tool Settings in e2 studio. Areas such as ROM areas and RAM areas are allocated to the memory of the RL78/G1C based on the information in this file. (1) Assignment of ROM area Data used by the firmware update program is allocated to the 16 KB ROM area of addresses 00 2000H to 00 5FFFH. The user-created program must therefore be allocated to an area other than the 16 KB ROM area of addresses 00 2000H to 00 5FFFH. The sections added by these directives are described below. (2) Assignment of the RAM area The RAM area is allocated to addresses 0F E900H to 0F FEDFH. The self programming library uses addresses 0F E900H to 0F ED09H. However, these addresses are only used while the firmware update program is running. Therefore, the user-created program is not affected by RAM area allocation. 0F FF00 H 0F FE20H 0F ED10H 0F E900H r_usb_fwupdate.xcl RAM area Firmware Update Program Flash Self Programming Library Segment:SADDR_X Segment:DATA Use Flash Self Programming Library. -Z(CODE)RCODE,CODE=02000-057FF -Z(CONST)SWITCH=02000-057FF -Z(DATA)HUGE_I=FED10-FFE1F -Z(DATA)FAR_I=FED10-FFE1F -Z(DATA)SADDR_I,SADDR_Z,SADDR_N=FFE20-F FEDF -P(CODE)XCODE=[02000-057FF]/10000 00 7FFF H ROM area Segment:Undefined 00 6000 H 00 5C00 H User-created program address 0 saved Flash Self Programming Library Segment:ROM_UBT // FSL // ============ -Z(CODE)FSL_FCD=[5800-5FFF]/10000 -Z(CODE)FSL_FECD=[5800-5FFF]/10000 -Z(CODE)FSL_BCD=[5800-5FFF]/10000 -Z(CODE)FSL_BECD=[5800-5FFF]/10000 -Z(CODE)FSL_RCD=[5800-5FFF]/10000 -Z(DATA)HUGE_Z=FE900-FFE1F -P(DATA)HUGE_N=FE900-FFE1F Segment:FSL_XXX 00 5800 H Firmware Update Program (Include USB Basic FW) Segment:CODE , CONST 00 2000 H Segment:Undefined 00 1000 H Segment:Undefined 00 0000 H Figure 4-3 Linker Directives for Assigning the ROM or RAM Area R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 20 of 76 RL78 microcontroller 4.3 USB Peripheral Firmware Updater GNU/IAR Ver. Boot Processing Boot processing is executed by the boot program before the main function (main() in C) is executed after the RL78 microcontroller is reset. After the RL78 microcontroller is reset, the following initialization processing is executed:      The stack area is allocated and the stack pointer is set up. The area for storing the arguments of the main function is allocated. The data and stack areas are initialized. hdwinit() function switch user-created program and MCU initialize. The program branches to the main function. For details about this processing, see the CA78K0R User’s Manual. When the above processing is executed and reaches the main function code, the firmware update program branches to the user-created program and performs the RL78 microcontroller initialization processing required when running the firmware update program. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 21 of 76 RL78 microcontroller 4.3.1 USB Peripheral Firmware Updater GNU/IAR Ver. Operation flow at power-on The following describes the firmware update program operation flow when the power is turned on. Power-on 00 0000 H Branch to the startup routine *Specify branching to 2000H as the reset vector 00 2000 H Startup routine Execute the startup routine branch hdwinit() function. hdwinit() Branch to the main routine of firmware update program or user-created program Not press SW1 Press SW1 Update mode? Branch to 5C00H 00 5C00H Branch to the startup routine user-created of the CPU initialize main() function Firmware Update Program program included by 5C00H code End User-created Program Figure 4-4 Operation Flow at Power-on The operation is not guaranteed if an attempt is made to execute the user-created program when the user-created program has not been written or a branch code has not been written at 5C00H. For details about the CPU, see the Hardware User’s Manual. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 22 of 76 RL78 microcontroller 4.3.2 USB Peripheral Firmware Updater GNU/IAR Ver. Option bytes The RL78 microcomputer references the option bytes when powered on or when restarting after a reset and performs the specified initial settings. Therefore, the initial settings must be specified in advance for the option byte space.  User-defined option bytes (0 00C0H to 0 00C2H) - Settings for the watchdog timer - Settings for the LVD at power-on - Settings for the high-speed on-chip oscillator frequency  On-chip debug option byte (0 00C3H) - Settings for on-chip debugging - Settings for security items The table below shows the values specified for each option byte space in the self-update program. Table 4-5 Settings Specified by Option Bytes Option Byte Address Used for Value Description 000C0H Watchdog timer EFH Watchdog timer not used 000C1H LVD at power-on FFH LVD Off F0H 48MHz High-speed on-chip oscillator 000C2H frequency Enable on-chip debugging 000C3H On-chip debugging 85H Flash memory not erased Remark For details about the option bytes, see the Hardware User’s Manual. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 23 of 76 RL78 microcontroller 4.4 USB Peripheral Firmware Updater GNU/IAR Ver. Main Routine At the end of boot processing, the program branches to the hdwinit()function and executes the main routine. The main routine initializes the on-chip CPU functions and peripheral circuits, and then executes the firmware update program. void hdwinit(void) { DI(); Determines whether to boot the user-created program /* SW1 push? */ if (P13.7 == 1) { /* User proguram jump */ #if __ICCRL78__ __asm("BR N:5C00H"); #endif #if __GNU__ __asm("BR !0x5C00"); #endif } Initializes on-chip CPU functions and peripheral circuits. } /* FWUpdate exec */ usb_cpu_mcu_initialize(); EI(); /* eof hdwinit() */ Executes the firmware update processing. Figure 4-5 Main Routine The self-update program defines that the user-created program starts at address 00 5C00H. The self-update feature saves the start address of the user-created program (allocated to address 00 0000H in the user-created program) at addresses 00 5C00H to 00 5C03H. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 24 of 76 RL78 microcontroller 4.4.1 USB Peripheral Firmware Updater GNU/IAR Ver. Initialization of on-chip CPU functions and peripheral circuits (rl78usbmcu.c) Before executing the flash self-update program, the main routine initializes the on-chip CPU functions and peripheral hardware by using the usb_cpu_mcu_initialize() function. void usb_cpu_mcu_initialize(void) { volatile uint8_t ostc_reg_val; /* Clock Mode Control Register (CMC) Address FFFA0h */ CMC = 0x51; /* X1, XT1, Low Consumption Oscillation, 10MHz Waiting */ usb_cpu_LcdDisp(0, (uint8_t *)"FWUpdate"); usb_cpu_LcdDisp(8, (uint8_t *)"Ready"); /* FSL initialize */ fslRetCode = FSL_Init( &fsl_descriptor_pstr ); FSL_Open(); fslRetCode = FSL_GetSwapState( &fsl_data_buffer[0] ); FSL_Close(); /* variable initialize */ recv_buf = serial_buf; recv_buf_size = SERIAL_BUF_SIZE; /* flash buffer initialize */ for ( lp=0;lp Initialize the buffer memory used by the firmware update program. <2> Receive the first USB packet including enumeration data as the USB peripheral device (CDC). The firmware update program waits for the bulk-out transfer that handles the start record to start. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 26 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. /* ACK Start record response */ send_startres( RESPONSE_ACK ); /* LCD output message -> FW Update start */ usb_cpu_LcdDisp(8, (uint8_t *)"Start"); /* first block data receive */ ret = recv_record(); while (ret != RECORD_TYPE_DATA) { if (ret == RECORD_TYPE_START) { send_startres(RESPONSE_ACK); } else if (ret == RECORD_TYPE_END) { goto end; } else { send_datares(RESPONSE_NAK); } ret = recv_record(); } ・・・① /* Flash address & block number calc */ flash_addr = get_addr(); ・・・② flash_block = (uint16_t)(flash_addr / FLASH_BLOCK_SIZE);・・・③ /* Boot swap area check */ if (flash_block < 4) { first_addr = flash_addr; flash_buf.block = flash_block + 4; flash_block = recv_block(); if (first_addr == 0) { replace_apstart(); } ・・・④ ・・・⑤ Figure 4-8 flash_update() Function (2/5) <1> After receiving the start record, the firmware update program waits for the bulk-out transfer that handles the data record to start. <2> Extract information about the flash memory address to manipulate from the received data record. <3> In the same way, calculate the flash memory block number from the extracted address. <4> If the data record includes information about boot cluster 0 (flash memory blocks 0 to 3), write data to the corresponding area in boot cluster 1 (flash memory blocks 4 to 7). <5> If the data record includes information about flash memory block 0, only extract reset vector information and save it to a RAM space. Note that reset information in the user-created program is not written to addresses 0000H to 0001H. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 27 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. /* Boot swap area1 write */ ・・・① while (flash_block < 4) { if ( (ret=flashrom_write(&flash_buf)) != 0 ) { code = ERROR_FLASH_WRITE | ERROR_FLASH_WRITE_BBERR1; goto error; } /* swap area calc */ flash_buf.block = flash_block + 4; flash_block = recv_block(); } /* Boot block write */ if (first_addr == 0) { if ( (fslRetCode=FSL_Init(&fsl_descriptor_pstr))!=0 ) { code = ERROR_FLASH_WRITE | ERROR_FLASH_WRITE_FSLOPENERR; goto error; } FSL_Open(); FSL_PrepareFunctions(); FSL_PrepareExtFunctions(); fslRetCode = FSL_GetSecurityFlags(&data_destination_pu08); if( fslRetCode != 0 ) { code = ERROR_FLASH_WRITE | ERROR_FLASH_WRITE_FSLGSFERR; FSL_Close(); goto error; } if ( (fslRetCode=FSL_InvertBootFlag())!=0 ) { ・・・② code = ERROR_FLASH_WRITE | ERROR_FLASH_WRITE_FSLIBFERR; FSL_Close(); goto error; } if ( (fslRetCode=FSL_GetSwapState(&fsl_data_buffer[0]))!=0 ) { code = ERROR_FLASH_WRITE | ERROR_FLASH_WRITE_FSLGSSERR; FSL_Close(); goto error; } FSL_Close(); } Figure 4-9 flash_update() Function (3/5) <1> While the data record includes information about boot cluster 0, write data to boot cluster 1 repeatedly. <2> After writing to the current boot cluster (boot cluster 1) is finished, invert the boot flag value. During boot cluster switching, only inverting the boot flag value is performed by the flash self-programming library (FSL_InvertBootFlag()). (At this time, boot swapping is not executed.) R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 28 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. /* Flash block write */ if ( (ret=flashrom_write(&flash_buf)) != 0 ) { code = ERROR_FLASH_WRITE | ERROR_FLASH_WRITE_BBERR2; goto error; } /* Boot swap area2 write */ while (flash_block < 8) { ・・・① /* swap area calc */ flash_buf.block = flash_block - 4; flash_block = recv_block(); if ( (ret=flashrom_write(&flash_buf)) != 0 ) { code = ERROR_FLASH_WRITE | ERROR_FLASH_WRITE_BBER R3; goto error; } } if (first_addr == 0) { if ( (ret=write_apstart()) != 0 ) { ・・・② code = ERROR_FLASH_WRITE | ERROR_FLASH_WRITE_APSERR; goto error; } } } /* Write user apl ROM area */ while (flash_block <= WRITE_MAX_BLOCK) { ・・・③ flash_buf.block = flash_block; flash_block = recv_block(); if ( (ret=flashrom_write(&flash_buf)) != 0 ) { code = ERROR_FLASH_WRITE | ERROR_FLASH_WRITE_NOMLERR; goto error; } } Figure 4-10 flash_update() Function (4/5) <1> Write data to boot cluster 0. <2> Write the reset vector of the user-created program, which has been saved in the RAM, to the flash memory address to be written. <3> Write data to addresses other than boot clusters repeatedly. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 29 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. if (flash_block != RECEIVE_END_RECORD) { code = ERROR_INVALID_DATA; goto error; } end: EI(); ret = inrec.type; while (1) { if (ret == RECORD_TYPE_END) { /* ACK End response record */ send_endres(RESPONSE_ACK); /* LCD output -> FW update complete */ usb_cpu_LcdDisp(8, (uint8_t *)"Complete"); } else if (ret == RECORD_TYPE_DATA) { send_datares(RESPONSE_ACK); } else if (ret == RECORD_TYPE_START) { send_startres(RESPONSE_ACK); } else { send_datares(RESPONSE_NAK); } ret = recv_record(); } error: /* LCD output -> FW update error(not complete) */ usb_cpu_LcdDisp(8, (uint8_t *)"Error"); EI(); while (1) { /* ACK Error response record */ send_errorres(code); ret = recv_record(); } } /* eof flash_update */ ・・・① ・・・② ・・・③ Figure 4-11 flash_update() Function (5/5) <1> The process branches to this loop after writing is finished and does not exit from the loop. <2> This is the execution path for the normal completion of writing. After this code, a reset is expected to occur. <3> This results in abnormal processing. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 30 of 76 RL78 microcontroller 4.4.3 USB Peripheral Firmware Updater GNU/IAR Ver. Firmware update program internal functions This section describes the functions called from the flash_update() function. (1) recv_record() The recv_record() function analyzes whether the received record is valid. static int16_t recv_record( void ) { int16_t ret; int16_t i; uint16_t chk; /* Read record */ usbserial_clear_buffer(); ret = usbserial_recv(&inrec.type, 1); ret = usbserial_recv(&inrec.len, 1); if (inrec.len == 0) { ret = -1; goto end; } chk = inrec.len; if (inrec.len > 1) { ・・・① ret = usbserial_recv(inrec.data, inrec.len - 1); for (i = inrec.len - 2; i >= 0; i--) { chk += inrec.data[i]; } } ret = usbserial_recv(&inrec.sum, 1); /* Check sum */ chk ^= 0xffff; chk &= 0x00ff; if (chk != inrec.sum) { ret = -1; goto end; } ret = inrec.type; end: return ret; } /* eof recv_record */ Figure 4-12 recv_record() <1> Transfer data whose length is equivalent to the record length to the buffer for the firmware update program. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 31 of 76 RL78 microcontroller (2) USB Peripheral Firmware Updater GNU/IAR Ver. usbserial_recv() The usbserial_recv() function is used to poll the usb_psmpl_cdc_exec() function that controls Bulk-Out transfer triggered by a USB event (interrupt source flag). This function receives the USB packet data whose length is equivalent to the number of bytes passed by using the parameter. static int16_t usbserial_recv( uint8_t *data , int16_t len ) { int16_t num = 0; } while (num < len) { /* Interrupt & receive exec loop */ usb_psmpl_cdc_exec(); data[num] = recv_buf[recv_idx]; recv_idx++; if (recv_idx >= recv_buf_size) { recv_idx -= recv_buf_size; } comm_len--; num++; } return num; /* eof usbserial_recv */ ・・・① ・・・② Figure 4-13 usbserial_recv() <1> Process the USB event. Perform processing for the control transfer including enumeration data and bulk transfer. <2> Transfer the received data to the buffer memory for the firmware update program. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 32 of 76 RL78 microcontroller (3) USB Peripheral Firmware Updater GNU/IAR Ver. copy_block() The copy_block() function saves all the information in the specified flash memory block to the RAM area. static void { uint16_t uint16_t int16_t copy_block( int16_t block ) *in; *out; i; in = (uint16_t *)(block * FLASH_BLOCK_SIZE); out = (uint16_t *)flash_buf.data; for ( i=FLASH_BLOCK_SIZE / 2 - 1 ; i >= 0 ; i-- ) { out[i] = in[i]; } } /* eof copy_block */ Figure 4-14 copy_block() (4) replace_apstart() The replace_apstart() function saves the reset vector and option byte of the user-created program to a RAM space. static void replace_apstart( void ) { uint16_t *in = (uint16_t *)0; uint16_t *out; /* Reset vector copy */ out = (uint16_t *)flash_buf.data; start_inst = out[0]; out[0] = in[0]; out[1] = in[1]; /* Option byte copy */ out[96] = in[96]; out[97] = in[97]; } /* eof replace_apstart */ Figure 4-15 replace_apstart() R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 33 of 76 RL78 microcontroller (5) USB Peripheral Firmware Updater GNU/IAR Ver. write_apstart() The write_apstart() function writes the reset vector of the user-created program, which has been saved in the RAM, to the address from which the user-created program starts (00 5C00H). static int16_t write_apstart( void ) { uint16_t *out; int16_t num = 0; } out = (uint16_t *)flash_buf.data; flash_buf.block = APSTART_ADDR / FLASH_BLOCK_SIZE; copy_block((int16_t)flash_buf.block); flash_buf.data_length = FLASH_BLOCK_SIZE; ・・・① out[0] out[0] out[1] num return /* eof ・・・② ・・・③ = (uint16_t)start_inst; = 0xEC | (uint16_t)((start_inst << 8) & 0xFF00); = ((uint16_t)((start_inst >> 8) & 0xFF)); = flashrom_write(&flash_buf); num; write_apstart */ ・・・④ Figure 4-16 write_apstart() <1> Copy the user-created program start block. <2> Read the reset vector of the user-created program to the RAM area. <3> Add a branch instruction (BR) to the read information. <4> Rewrite the user-created program start block. Remark In 78K0R, the reset vector table does not require the branch instruction. Therefore, to rewriting the user-created block start block, a branch instruction (to ECH, in the above code) is added. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 34 of 76 RL78 microcontroller (6) USB Peripheral Firmware Updater GNU/IAR Ver. send_startres() The send_startres() function sends a response for the start record to the host. static void send_startres( uint8_t kbn ) { uint16_t sum; /* make response record */ outrec[0] = RECORD_TYPE_START; outrec[1] = 3; outrec[2] = kbn; outrec[3] = inrec.data[0]; sum = outrec[1] + outrec[2] + outrec[3]; sum ^= 0xffff; sum &= 0x00ff; outrec[4] = (uint8_t)sum; } /* Send response */ R_usb_pcdc_SendData( &outrec[0], 5, (usb_cbinfo_t)&usb_psmpl_TxCB ); usb_psmpl_cdc_exec(); /* eof send_startres */ Figure 4-17 send_startres() (7) send_datares() The send_datares() function sends a response for the data records to the host. static void send_datares( uint8_t kbn ) { int16_t i; uint16_t sum = 0; /* make response record */ outrec[0] = RECORD_TYPE_DATA; outrec[1] = 6; outrec[2] = kbn; outrec[3] = inrec.data[0]; outrec[4] = inrec.data[1]; outrec[5] = inrec.data[2]; outrec[6] = inrec.data[3]; for (i = 6; i > 0; i--) { sum += outrec[i]; } sum ^= 0xffff; sum &= 0x00ff; outrec[7] = (uint8_t)sum; } /* Send response */ R_usb_pcdc_SendData( &outrec[0], 8, (usb_cbinfo_t)&usb_psmpl_TxCB ); usb_psmpl_cdc_exec(); /* eof send_datares */ Figure 4-18 send_datares() R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 35 of 76 RL78 microcontroller (8) USB Peripheral Firmware Updater GNU/IAR Ver. send_endres() The send_endres() function sends a response for the end record to the host. static void send_endres( uint8_t kbn ) { uint16_t sum; /* make response record */ outrec[0] = RECORD_TYPE_END; outrec[1] = 3; outrec[2] = kbn; outrec[3] = inrec.data[0]; sum = outrec[1] + outrec[2] + outrec[3]; sum ^= 0xffff; sum &= 0x00ff; outrec[4] = (uint8_t)sum; } /* Send response */ R_usb_pcdc_SendData( &outrec[0], 5, (usb_cbinfo_t)&usb_psmpl_TxCB ); usb_psmpl_cdc_exec(); /* eof send_endres */ Figure 4-19 send_endres() (9) send_errorres() The send_errorres() function sends an error record to the host. static void send_errorres( uint8_t code ) { uint16_t sum; /* make response record */ outrec[0] = inrec.type; outrec[1] = 3; outrec[2] = RESPONSE_ERROR; outrec[3] = code; sum = outrec[1] + outrec[2] + outrec[3]; sum ^= 0xffff; sum &= 0x00ff; outrec[4] = (uint8_t)sum; } /* Send response */ R_usb_pcdc_SendData( &outrec[0], 5, (usb_cbinfo_t)&usb_psmpl_TxCB ); usb_psmpl_cdc_exec(); /* eof send_errorres */ Figure 4-20 send_errorres() R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 36 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. (10) recv_block() The recv_block() function stores the data for rewriting one block to the RAM space used by the self-update program. static int16_t recv_block( void ) { int16_t ret; uint16_t in_addr; uint16_t out_addr; int16_t in_len; int16_t in_idx; int16_t out_idx; copy_block(flash_block); flash_buf.data_length = FLASH_BLOCK_SIZE; out_addr = flash_block * FLASH_BLOCK_SIZE; do { if (out_addr == flash_addr) { out_idx = 0; in_idx = 4; } else if (out_addr > flash_addr) { in_idx = out_addr - flash_addr + 4; out_idx = 0; } else { out_idx = flash_addr - out_addr; in_idx = 4; } in_len = inrec.len - 1; while (in_idx < in_len) { if (out_idx >= FLASH_BLOCK_SIZE) { ret = flash_block + 1; goto end; } flash_buf.data[out_idx] = inrec.data[in_idx]; out_idx++; in_idx++; } Figure 4-21 recv_block() (1/2) R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 37 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. send_datares(RESPONSE_ACK); ret = recv_record(); while (1) { if (ret == RECORD_TYPE_DATA) { in_addr = get_addr(); if (in_addr > flash_addr) { break; } send_datares(RESPONSE_ACK); } else if (ret == RECORD_TYPE_END) { ret = RECEIVE_END_RECORD; goto end; } else if (ret == RECORD_TYPE_START) { send_startres(RESPONSE_ACK); } else { send_datares(RESPONSE_NAK); } ret = recv_record(); } flash_addr = in_addr; ret = flash_addr / FLASH_BLOCK_SIZE; } while (ret == flash_block); end: return ret; } /* eof recv_block */ Figure 4-22 recv_block() (2/2) R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 38 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. (11) flashrom_write() The flashrom_write() function writes data to the target flash memory block in block units. static fsl_u08 flashrom_write( struct flash_data *fd ) { fsl_u08 fslRetCode = 0; uint16_t wAdr; fsl_write_t __near dtyWriteBuff; /* for FSL_Write */ fd->pDataBuffer = fsl_data_buffer; do { if ( (fd->block>=0x08) && (fd->block<0x15) ) { fslRetCode = 1; break; } if ( (fslRetCode=FSL_Init( &fsl_descriptor_pstr )) != FSL_OK ) { break; } FSL_Open(); FSL_PrepareFunctions(); FSL_PrepareExtFunctions(); if ( (fslRetCode=(fsl_u08)FSL_BlankCheck((fsl_u16)fd->block)) == FSL_ERR_BLANKCHECK ) { if ( (fslRetCode=FSL_Erase( (fsl_u16)fd->block )) != FSL_OK ) { break; } } wAdr = (fd->block * FLASH_BLOCK_SIZE); Figure 4-23 flashrom_write() (1/2) R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 39 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. memcpy( fd->pDataBuffer , fd->data , 256 ); dtyWriteBuff.fsl_data_buffer_p_u08 = fd->pDataBuffer; dtyWriteBuff.fsl_destination_address_u32 = wAdr; dtyWriteBuff.fsl_word_count_u08 = (fsl_u08)(64); if ( (fslRetCode=FSL_Write( &dtyWriteBuff )) != FSL_OK ) { break; } wAdr = wAdr + 256; memcpy( fd->pDataBuffer , fd->data + 256 , 256 ); dtyWriteBuff.fsl_data_buffer_p_u08 = fd->pDataBuffer; dtyWriteBuff.fsl_destination_address_u32 = wAdr; dtyWriteBuff.fsl_word_count_u08 = (fsl_u08)(64); if ( (fslRetCode=FSL_Write( &dtyWriteBuff )) != FSL_OK ) { break; } wAdr = wAdr + 256; memcpy( fd->pDataBuffer , fd->data + 256 + 256 , 256 ); dtyWriteBuff.fsl_data_buffer_p_u08 = fd->pDataBuffer; dtyWriteBuff.fsl_destination_address_u32 = wAdr; dtyWriteBuff.fsl_word_count_u08 = (fsl_u08)(64); if ( (fslRetCode=FSL_Write( &dtyWriteBuff )) != FSL_OK ) { break; } wAdr = wAdr + 256; memcpy( fd->pDataBuffer , fd->data + 256 + 256 + 256 , 256 ); dtyWriteBuff.fsl_data_buffer_p_u08 = fd->pDataBuffer; dtyWriteBuff.fsl_destination_address_u32 = wAdr; dtyWriteBuff.fsl_word_count_u08 = (fsl_u08)(64); if ( (fslRetCode=FSL_Write( &dtyWriteBuff )) != FSL_OK ) { break; } } if ( (fslRetCode=FSL_IVerify( (fsl_u16)fd->block )) != FSL_OK ) { break; } } while(0); FSL_Close(); return fslRetCode; /* eof flashrom_write */ Figure 4-24 flashrom_write() (2/2) R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 40 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. The following describes the operation flow when writing to flash memory blocks. Start FSL_Init() FSL_Open() FSL_GetSecurityFlags() FSL_BlankCheck() Initialize the entry RAM. Save and specify the interrupt setting and then pull up FLMD0. Check the Security Flags. Check whether the specified 1 KB block is blank. If not blank FSL_Erase() FSL_Write() FSL_IVerify() FSL_Close() Erase the specified 1 KB block. Write 1- to 64-word data to the specified address. Verify the specified 1 KB block (internal verify). Exit from the interrupt processing and pull down FLMD0. End Figure 4-25 Flash Memory Writing Flow R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 41 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. (12) Data type The types of data used by the firmware update program are shown below. Table 4-6 Data Types Data Type Specifier Data Range Valid in RL78 int8_t signed char Signed 8-bit integer. int16_t signed short Signed 16-bit integers. int32_t signed long Signed 32-bit integers. uint8_t unsigned char Unsigned 8-bit integers. uint16_t unsigned short Unsigned 16-bit integers. uint32_t unsigned long Unsigned 32-bit integers. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 42 of 76 RL78 microcontroller 4.5 USB Peripheral Firmware Updater GNU/IAR Ver. Writing to the On-Chip Flash Memory The firmware update program updates the firmware and specified memory areas by overwriting the contents of the onchip flash memory. The firmware update program uses the flash self-programming library to write data to the on-chip flash memory. This evaluation board requires the Type 01 flash self-programming library which corresponds with the type of flash memory used. For details about the flash self-programming library, see the RL78 microcontrollers Flash Memory Self-Programming Library Type 01 User’s Manual. 4.5.1 Writing to the flash memory The on-chip flash memory of each product used with the evaluation board consists of the following blocks: - RL78/G1C : Blocks 0 to 31 - RL78/L1C : Blocks 0 to 255 The flash memory can be erased and written in block units. The flashrom_write() function defined in the r_usb_fwupdate_apl.c file executes the processing to write to the specified block in the flash memory. The block to be written to and the data to be written are specified using the flash_data structure, which is declared in the r_usb_fwupdate_apl.c file. #define FLASH_BLOCK_SIZE ( 1024 ) · · · struct flash_data { fsl_u08* pDataBuffer; UINT32 block; UINT32 data_length; UINT8 data[FLASH_BLOCK_SIZE]; }; Number of bytes in one block Structure used to pass data to the flashrom_write function Figure 4-26 flash_data Structure The pDataBuffer member specifies a buffer for flash self-programming library. The block member in the flash_data structure specifies the number of the block to be written to and the data member specifies the data to be written. The data_length member specifies the number of bytes of data to be written. The flashrom_write function writes the data to the on-chip flash memory using the flash functions provided by the flash self-programming library. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 43 of 76 RL78 microcontroller 4.5.2 USB Peripheral Firmware Updater GNU/IAR Ver. Boot swapping The target products provide a boot swapping feature to protect the boot area and enable boot processing to be executed normally if the power supply is cut while the boot area is being overwritten during programming of the user-created program. By using this feature, blocks 0 to 3 can be swapped with blocks 4 to 7 in the target product. Blocks Blocks Blocks 4 to 7 4 to 7 4 to 7 Blocks Blocks Blocks 0 to 3 0 to 3 0 to 3 Memory Memory Memory <1> Data is written to the swap area (blocks 4 to 7). <2> Data has been written. <3> The blocks are swapped. Figure 4-27 Boot Swapping During Programming of the User-Created Program 4.5.3 Processing to update the firmware The on-chip flash memory is overwritten in block units. The firmware update program copies one of the blocks in the area to be overwritten to a buffer, overwrites the data in the block, and writes the block back to the on-chip flash memory. This means that the memory can be overwritten in 1-byte units. <1> The block is copied (using copy_block()).  flash_buf  Block in area to be overwritten  <2> Data is written to the copied block.   <3> The block is written back (using flashrom_write()). Memory Figure 4-28 Diagram of Overwriting Blocks Data is received from the host, responses are transmitted to the host, and data is overwritten using the flash_update function in the r_usb_fwupdate_apl.c file. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 44 of 76 RL78 microcontroller 4.5.4 USB Peripheral Firmware Updater GNU/IAR Ver. Updating the user-created program When writing the user-created program, change the apstart section as follows so that the user-created program runs when the system starts up. Remove the boot processing in the user-created program (the reset section) and write this as the branch destination of the firmware update program’s boot processing. (The code to jump to the user-created program is in the apstart section.) By doing this, the boot processing of the user-created program is changed to the boot processing of the firmware update program. This means that the boot processing area can be preserved and the firmware update program can be manipulated again later. 00 5C00H 00 2000H apstart <2> Remove the boot processing of the user-created program. replace_apstart() <1> Data is received. recv_block() Firmware update program <4> Write the apstart section. frashrom_write() 00 0000H Memory flash_buf <3> Write this area as the boot processing of the user-created program. Figure 4-29 Overwriting the Boot Processing When Updating the User-Created Program When the system starts up, the program moves to the main function processing, checks the startup conditions in that processing (that is, the status of the SW1 switch), moves to apstart as appropriate, and then moves to the start of the user-created program. 00 5C00H 00 2000H apstart Firmware update program <2> The conditions for branching to the user-created program are checked, and, if the conditions are met, the program moves to apstart. <3> The user-created program runs. User program <1> After startup, the program moves to the self-update processing 00 0000H Memory Figure 4-30 Branching to the User-Created Program R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 45 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. static void replace_apstart( void ) { uint16_t *in = (uint16_t *)0; uint16_t *out; } Indicates the start of the memory /* Reset vector copy */ out = (uint16_t *)flash_buf.data; start_inst = out[0]; out[0] = in[0]; out[1] = in[1]; Removes the processing of received data /* Option byte copy */ out[96] = in[96]; out[97] = in[97]; to that of the firmware update boot the Switches the boot processing program. Copy the option byte. /* eof replace_apstart */ Figure 4-31 Switching the Boot Processing Next, editing the processing for writing to apstart is described. static int16_t write_apstart( void ) { uint16_t *out; int16_t num = 0; out = (uint16_t *)flash_buf.data; flash_buf.block = APSTART_ADDR / FLASH_BLOCK_SIZE; copy_block((int16_t)flash_buf.block); flash_buf.data_length = FLASH_BLOCK_SIZE; Inserts the code to be written to apstart into start_inst. out[0] = (uint16_t)start_inst; out[0] = 0xEC | (uint16_t)((start_inst << 8) & 0xFF00); Call write processing. out[1] = ((uint16_t)((start_inst >> 8) & 0xFF)); num = flashrom_write(&flash_buf); return num; } /* eof write_apstart */ Figure 4-32 Overwriting the Boot Processing R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 46 of 76 RL78 microcontroller 4.5.5 USB Peripheral Firmware Updater GNU/IAR Ver. Receiving data The firmware update program is used to initiate serial communication with the host and receive the new firmware data. For details about the communication interface specifications, see 7.1 Specifications of the Communication Interface for Updating the Firmware. static int16_t recv_block( void ) { int16_t ret; uint16_t in_addr; uint16_t out_addr; int16_t in_len; int16_t in_idx; int16_t out_idx; copy_block(flash_block); flash_buf.data_length = FLASH_BLOCK_SIZE; out_addr = flash_block * FLASH_BLOCK_SIZE; do { if (out_addr == flash_addr) { out_idx = 0; in_idx = 4; } else if (out_addr > flash_addr) { in_idx = out_addr - flash_addr + 4; out_idx = 0; } else { out_idx = flash_addr - out_addr; in_idx = 4; } in_len = inrec.len - 1; while (in_idx < in_len) { if (out_idx >= FLASH_BLOCK_SIZE) { ret = flash_block + 1; goto end; } flash_buf.data[out_idx] = inrec.data[in_idx]; out_idx++; in_idx++; } send_datares(RESPONSE_ACK); ret = recv_record(); while (1) { if (ret == RECORD_TYPE_DATA) { in_addr = get_addr(); if (in_addr > flash_addr) { break; } send_datares(RESPONSE_ACK); } else if (ret == RECORD_TYPE_END) { ret = RECEIVE_END_RECORD; goto end; } else if (ret == RECORD_TYPE_START) { send_startres(RESPONSE_ACK); } else { send_datares(RESPONSE_NAK); } ret = recv_record(); } flash_addr = in_addr; ret = flash_addr / FLASH_BLOCK_SIZE; } while (ret == flash_block); end: return ret; } /* eof recv_block */ Copies the specified block. One record of data is received. Either all the data is received, or, if the block is full, the processing leaves the loop. ACK is returned and a new record is received. Identifies the record received. When the block changes, the processing leaves the loop. Figure 4-33 Receiving One Block of Data R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 47 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. The processing for receiving one record is shown below. static int16_t recv_record( void ) { int16_t ret; int16_t i; uint16_t chk; /* Read record */ usbserial_clear_buffer(); ret = usbserial_recv(&inrec.type, 1); ret = usbserial_recv(&inrec.len, 1); if (inrec.len == 0) { ret = -1; goto end; } chk = inrec.len; if (inrec.len > 1) { ret = usbserial_recv(inrec.data, inrec.len - 1); for (i = inrec.len - 2; i >= 0; i--) { chk += inrec.data[i]; } } ret = usbserial_recv(&inrec.sum, 1); /* Check sum */ chk ^= 0xffff; chk &= 0x00ff; if (chk != inrec.sum) { ret = -1; goto end; } ret = inrec.type; end: return ret; } /* eof recv_record */ Inform action on the record type and length is received. The processing loops until the record reaches the specified length. the received data is accrued for checksum calculation. Checksum Figure 4-34 Receiving One Record R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 48 of 76 RL78 microcontroller 4.6 USB Peripheral Firmware Updater GNU/IAR Ver. CDC (Communication Device Class) This section describes the processing of the CDC (communications device class) used by the firmware update program. For details about the USB communications device class (USB CDC), see the USB Peripheral Communications Device Class Driver (PCDC) for Basic Mini Firmware application note. For details about the USB communications device class, see the Universal Serial Bus Class Definitions for Communication Devices” Revision 1.2 on the official USB-IF website (www.usb.org). 4.6.1 Monitoring endpoints by polling Endpoints are monitored by polling rather than by using interrupt vectors. The presence of data in the endpoint for control transfers and the endpoint for bulk-out transfers FIFOs can be checked by monitoring the endpoint interrupt flags. The processing for monitoring the endpoints when receiving data is shown below. static void usb_psmpl_cdc_exec(void) { while (comm_len == 0) { Wait to execute the interrupt until data is received. usb_cpu_usb_interrupt(); /* Task schedule request check. */ if( USB_FLGSET == R_usb_cstd_Scheduler() ) { R_usb_pstd_PcdTask(); R_usb_pcdc_Task(); /* PCD Task */ /* Peripheral PCDC Task */ usb_psmpl_FWUpdateCommTask(); /* FWUpdate main task */ } } } /* eof usb_psmpl_cdc_exec */ The received data is copied from a buffer and execute USB ack. Figure 4-35 Monitoring Endpoints R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 49 of 76 RL78 microcontroller 5. USB Peripheral Firmware Updater GNU/IAR Ver. FILE TRANSFER APPLICATION This chapter describes the file transfer application that runs on the host. 5.1 Development Environment The file transfer application must be set up in the following environment. OS: Development software: 5.2 Windows 7 Microsoft Visual C++ 6.0 (MFC) Operation Overview When the file transfer application is run with the target file to use to update the firmware specified as a parameter (option), the application immediately begins updating the firmware. If no file is specified, the configuration dialog box is displayed. File Start Start Dialog box class used when dragging and dropping a file Application dialog box class GUI display Various settings Thread class for communication processing for updating the firmware Communication Figure 5-1 File Transfer Application Operation Overview R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 50 of 76 RL78 microcontroller 5.3 USB Peripheral Firmware Updater GNU/IAR Ver. Organization of Files The main files included in the file transfer application are as follows. Table 5-1 Main Files Included in the File Transfer Application File Name Description FlashSelfRewriteGUI.dsw Workspace file FlashSelfRewriteGUI.dsp Project file FlashSelfRewriteGUI.clw File for the class wizard FlashSelfRewriteGUI.rc Resource file FlashSelfRewriteGUI.cpp Source file containing the application class FlashSelfRewriteGUI.h Header file defining the application class FlashSelfRewriteGUIDlg.cpp Source file containing the dialog box class for the application FlashSelfRewriteGUIDlg.h Header file defining the dialog box class for the application FlashSelfRewriteGUIDrop.cpp Source file containing the dialog box class used when dragging and dropping a file FlashSelfRewriteGUIDrop.h Header file defining the dialog box class used when dragging and dropping a file CommandThread.cpp Source file containing the thread class that performs communication processing to update the firmware CommandThread.h Header file defining the thread class that performs communication processing to update the firmware 5.3.1 CommonProc.cpp Source file containing the class for common processing CommonProc.h Header file defining the class for common processing SerialPort.cpp Source file containing the class for serial communication with the COM port SerialPort.h Header file defining the class for serial communication with the COM port Resource.h Header file defining resources UsbfUpdate.ini Configuration file for using the application Application class (FlashSelfRewriteGUI) Upon being executed for the first time, this class checks the parameters (options) and then calls the dialog box class used when dragging and dropping a file if a file has been specified or calls the normal dialog box class if no file has been specified. The execution options that can be specified for this class are as follows. Table 5-2 Application Class Execution Options Option Description /M [chip|address] Specify either the chip or address operating mode. /S nnnnnn Specify the hexadecimal address at which to begin updating the firmware. /C nn Specify the number of the connected COM port. filename Specify the path of the file used to update the firmware. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 51 of 76 RL78 microcontroller 5.3.2 USB Peripheral Firmware Updater GNU/IAR Ver. Application dialog box class (FlashSelfRewriteGUIDlg) This class is used to display the dialog box in which settings for updating the firmware are specified. (For details, see 3.EXECUTING THE SAMPLE PROGRAM FOR UPDATING THE USB PERIPHERAL FIRMWARE) This dialog box is used to specify the operating mode, address, file, and COM port to use for updating the firmware. Note that, when this dialog box is displayed, the configuration file for using the application is read, and, if the file contains any settings, these are used as the default display settings. If you click the Update button, the thread class that performs communication processing to update the firmware is called. The application dialog box class includes the following member variables. Table 5-3 Member Variables in the Application Dialog Box Class Member Variables Data Type Description Member Name int m_nCOM Number of the COM port to which to connect TCHAR m_tcAppDir[_MAX_PATH] Directory from which the application is run int m_nCurTargetID Current target ID CString m_strCurTarget Current target name CString m_strCurDevice Current device CStringArray m_arDeviceVal List of devices CStringArray m_arDeviceText List of device names int m_nDevSize Current device ROM size CWinThrread* m_pCommandThread Pointer to the thread class BOOL m_bExistThread Indicates whether the thread exists BOOL m_bStartUp Indicates initial startup CArray m_arBlockStart Array containing starting block numbers CArray m_arBlockEnd Array containing ending block numbers CArray m_arBlockUnit Array containing the number of bytes for each block COleDateTime m_dtStart Date and time when updating the firmware started COleDateTime m_dtEnd Date and time when updating the firmware finished The member functions are as follows. Table 5-4 Read_DeviceInfo Function Function name Read_DeviceInfo Specification format BOOL Read_DeviceInfo ( VOID ) Description Acquires information from the configuration file for using the application. Input/output Input None Output TRUE (success) or FALSE (failure) R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 52 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. Table 5-5 Write_DeviceInfo Function Function name Write_DeviceInfo Specification format BOOL Write_DeviceInfo ( VOID ) Description Updates the configuration file for using the application. Input/output Input None Output TRUE (success) or FALSE (failure) Table 5-6 Update_Message Function Function name Update_Message Specification format VOID Update_Message ( LPCTSTR ) Description Displays a message in the message display field. Input/output Input A pointer to the message string Output None Table 5-7 Get_BlockAddress Function Function name Get_BlockAddress Specification format DWORD Get_BlockAddress( int nBlk, EnBlockAddress opt ) Description Returns the memory address of the specified block number. Input/output Input nBlk: A block number opt: START or END (for the starting or ending block, respectively) Output A memory address Table 5-8 Get_AddressBlock Function Function name Get_AddressBlock Specification format int Get_AddressBlock( DWORD dwAddress ) Description Returns the block number that has the specified address. Input/output Input dwAddress: A memory address Output A block number Table 5-9 Initialize_Device Function Function name Initialize_Device Specification format VOID Initialize_Device( VOID ) Description Performs initialization processing. Input/output Input None Output None Table 5-10 AppStatus Function Function name AppStatus Specification format VOID AppStatus( BOOL stu ) Description Specifies the status when the firmware is updated. Input/output Input stu: TRUE (The dialog box can be used.) FALSE (The dialog box cannot be used.) Output R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 None Page 53 of 76 RL78 microcontroller 5.3.3 USB Peripheral Firmware Updater GNU/IAR Ver. Dialog box class used when a file is dragged and dropped (FlashSelfRewriteGUIDrop) Immediately after the dialog box for this class is displayed, the thread class that performs communication processing to update the firmware is called, and the update begins. Only a progress bar is displayed in this dialog box. The member variables are shown below. (Member variables included in the dialog box class for the application have been omitted.) Table 5-11 Member Variables in the Dialog Box Class Used When a File Is Dragged and Dropped Member Variables Data Type Description Member Name CString m_strFileName Target file path EnMode m_enMode Updating mode DWORD m_dwStartAddress Address at which to start the update The member functions are as follows. Table 5-12 Execute Function Function name Execute Specification format VOID Execute( VOID ) Description Performs update processing. Input/output 5.3.4 Input None Output None Thread class that performs communication processing to update the firmware (CommandThread) This class uses the class for serial communication with the COM port to connect to the target evaluation board and transmit or receive the specified file in accordance with the interface specifications. If a HEX file is specified, this class analyzes the file. The member variables are shown below. (Member variables included in the dialog box class for the application have been omitted.) Table 5-13 Member Variables in the Thread Class That Performs Processing to Update the Firmware Member Variables Data Type Description Member Name CDialog* m_pAppDlg Pointer to the dialog box class, which calls the thread class CString m_strAppDir Directory in which the application resides BOOL* m_pbExistThread Pointer to a flag indicating whether the thread exists CSerialPort m_Serial Instance of the class for serial communication with the COM port int m_nCOM Number of the COM port to which to connect CString m_strFileName Target file path EnMode m_enMode Updating mode DWORD m_dwStartAddress Address at which to start updating the firmware DWORD m_dwROMStartAddress First ROM address DWORD m_dwROMEndAddress Last ROM address R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 54 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. The member functions are as follows. Table 5-14 Cal_CheckSum Function Function name Cal_CheckSum Specification format BYTE Cal_CheckSum( LPBYTE bytes, LONG size ) Description Calculates the checksum. Input/output Input bytes: A pointer to a data string size: The length of the data string Output The calculated checksum Table 5-15 Change_strHex2Binary Function Function name Change_strHex2Binary Specification format VOID Change_strHex2Binary( LPCSTR strHex, LPBYTE pbytes, LONG size ) Description Converts a hexadecimal character string into a binary data string. Input/output Input strHex: A pointer to a hexadecimal character string pbytes: A pointer to the beginning of a data string size: The size of the data to convert Output None Table 5-16 Upsets_DWORD Function Function name Upsets_DWORD Specification format DWORD Upsets_DWORD( DWORD dwVal ) Description Reverses a DWORD value in byte units as follows: 0xaabbccdd is converted to 0xddccbbaa. Input/output Input dwVal: The DWORD value to reverse Output The reversed value Table 5-17 SET_StartRecord Function Function name SET_StartRecord Specification format VOID SET_StartRecord ( LPVOID lpRecord ) Description Creates the start record for updating the firmware. Input/output Input lpRecord: A pointer to a stored record Output None Table 5-18 SET_EndRecord Function Function name SET_EndRecord Specification format VOID SET_EndRecord ( LPVOID lpRecord ) Description Creates the end record for updating the firmware. Input/output Input lpRecord: A pointer to a stored record Output None R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 55 of 76 RL78 microcontroller 5.3.5 USB Peripheral Firmware Updater GNU/IAR Ver. Common Processing Class (CommonProc) This class defines commonly used processing. The member functions are as follows. Table 5-19 GetAppDir Function Function name GetAppDir Specification format static VOID GetAppDir( LPTSTR path, int sw = 0 ) Description Acquires the execution address for the application. Input/output Input path: A pointer to the character string to acquire sw: 0 Acquires the path without conversion. 1 Converts the path to a short path during acquisition. Output None Table 5-20 Change_Hex2Val Function Function name Change_Hex2Val Specification format static DWORD Change_Hex2Val( LPCSTR pHex ) Description Converts a 1-byte (2-digit hexadecimal) character string to a number. Input/output Input pHex: A pointer to a 2-digit hexadecimal character string Output The converted value Table 5-21 IsNumeric Function Function name IsNumeric Specification format static BOOL IsNumeric( LPCTSTR lpNum, LONG size, int type = 10 ) Description Checks whether the parameter is a number. Input/output Input lpNum: A pointer to a character string representing a number size: The number of digits in the parameter to check type: 10 Checks whether the parameter is a decimal number. 16 Checks whether the parameter is a hexadecimal number. Output TRUE (which indicates that the parameter is a number) or FALSE (which indicates that the parameter is not a number) Table 5-22 IsExistFile Function Function name IsExistFile Specification format static BOOL IsExistFile( LPCTSTR lpszFileName, BOOL bDirectory = FALSE ) Description Checks whether a file exists. Input/output Input lpszFileName: The file path to check bDirectory: FALSE (checking for a file) TRUE (checking for a directory) Output TRUE (which indicates that the file exists) or FALSE (which indicates that the file does not exist) R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 56 of 76 RL78 microcontroller 5.3.6 USB Peripheral Firmware Updater GNU/IAR Ver. Class for serial communication with the COM port (SerialPort) This class is used to perform serial communication with the COM port. The communication settings, which are fixed, are as follows. Table 5-23 Serial Communication Settings Setting Value Baud rate 115,200 bps Data size 8 bits Parity None Stop bit 1 bit Start bit LSB Flow control None The member variables are as follows. Table 5-24 Member Variables in the Class for Serial Communication with the COM Port Member Variables Data Type Description Member Name HANDLE m_hCom Handle acquired when a connection is established DCB m_Dcb Device control block structure COMMTIMEOUTS m_TimeoutSts Structure for specifying timeout settings INT m_nCOM Port number for connecting The member functions are as follows. Table 5-25 Port_Open Function Function name Port_Open Specification format LONG Port_Open(INT com ) Description Connects to the specified COM port. Input/output Input Output com: The COM port number 0 Connection success 1 Connection failure Table 5-26 Port_Close Function Function name Port_Close Specification format VOID Port_Close( VOID ) Description Closes a connected port. Input/output Input None Output None R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 57 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. Table 5-27 Port_Write Function Function name Port_Write Specification format LONG Port_Write(LPCVOID buf, LONG cnt ) Description Transmits data by performing serial communication. Input/output Input buf: A pointer to the string of data to transmit cnt: The length of the data to transmit (in bytes) Output The number of transmitted bytes. 1 is returned if data could not be transmitted. Table 5-28 Port_Read Function Function name Port_Read Specification format LONG Port_Read(LPVOID buf, LONG cnt ) Description Receives data by performing serial communication. Input/output Input buf: A pointer to the string of data in which to store the received data cnt: The length of the received data (in bytes) Output The number of received bytes. -1 is returned if data could not be received. Table 5-29 Get_PortNumber Function Function name Get_PortNumber Specification format INT Get_PortNumber( VOID ) Description Acquires the number of the currently connected port. Input/output Input None Output The number of the currently connected port Table 5-30 AutoScanCom Function Function name AutoScanCom Specification format INT AutoScanCom ( LPCTSTR pszService, LPCTSTR pszInterface, INT nNo = 0) Description Input/output Detects the number of a COM port that can be connected. Input pszService: The name of the service for which the COM port is running pszInterface: The interface name nNo: Specify whether to search for numbers later than this number. Output R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 The detected COM port number. 0 is returned if no number is found. Page 58 of 76 RL78 microcontroller 5.3.7 USB Peripheral Firmware Updater GNU/IAR Ver. Configuration file for using the application (UsbfUpdate.ini) This ini file is used to retain settings or device information. This file is located in the same folder as the exe file. The definitions in this ini file are as follows. Table 5-31 Sections in the Configuration File for Using the Application Section Description Application Indicates the currently specified values for the application. Tartget1 Indicates the target ID. Device.XXXXXXXX Indicates the device information. Multiple settings can be specified. Table 5-32 Items in the Configuration File for Using the Application Section Application Key Value Description Target 1 or greater The currently specified ID number COM 1 to 20 The number of the connected COM port or COM port to connect Mode chip or address Indicates the currently specified operating mode. chip: Updates the firmware with a usercreated program using boot swapping address: Updates the firmware using a specified address. Tartget1 Device.R5F10JGC Address FFFFFFFF The first address to write to (in hexadecimal) Name XXX Indicates the name of this target. Device XXX The device specified for this target Target 1 or greater The ID of the target to which this device belongs Name XXX The name of this device Size 1~999 The ROM size of this target Block0 XXX|XXX|XXX|XXX Block information delimited using vertical bars (|) First block number|last block number|size of each block (in KB)|whether this is a booting area Mutiple blocks can be specified by using Block1, Block2, …, Blockn. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 59 of 76 RL78 microcontroller [Application] Target=1 Mode=chip Address=00000000 COM=6 [Target1] Name=RL78/G1C Device=R5F10JGC [Device.R5F10JGC] Target=1 Name=R5F10JGC Size=32 Block0=0|7|1|true Block1=8|23|1|true Block2=24|31|1|false [Device.R5F110PJ] Target=1 Name=R5F110PJ Size=256 Block0=0|7|1|true Block1=8|23|1|true Block2=24|255|1|false USB Peripheral Firmware Updater GNU/IAR Ver. Target ID:1 COM Port:6(unspecified) Operating mode:chip First write address:00000000 Target name:RL78/G1C Current device:R5F10JGC Induction target :1 Device name:R5F10JGC Size:32KB Block information 0:Blocks 0 to 7 are 1KB blocks used as a boot area Block information 1:Blocks 8 to 23 are 1KB blocks used as a boot area. (firmware update program area) Block information 2:Blocks 24 to 31 are 1KB blocks that are not used as a boot area. after this Induction target : 2 ~ Figure 5-2 ini Configuration File for Using the Application R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 60 of 76 RL78 microcontroller 5.4 USB Peripheral Firmware Updater GNU/IAR Ver. Operating Mode This section describes the operating modes. (1) Chip The specified HEX file must be in the Motorola S-record format or Intel extended format. If a file that has any other format is specified, an error occurs during analysis. Because the file is written to the first memory address, any specified address is ignored. (2) Address A file image is transferred, and then writing is performed starting at the specified address. 5.5 Display of Messages The following table describes the messages displayed in the message display field and when they are displayed. Table 5-33 Displayed Messages Message When Displayed Updating the firmware will now start. This message is displayed when the processing to update the firmware starts Updating has finished successfully. This message is displayed when the processing to update the firmware finishes successfully Specify the file. This message is displayed if no file is specified for updating the firmware or the specified file does not exist. Specify the mode. This message is displayed if no mode is specified for updating the firmware. Specify the correct address. This message is displayed if the correct address is not specified while updating the firmware in the address mode. Specify the COM port. This message is displayed if the COM port is not correctly specified. ERR: An error occurred while opening the file. This message is displayed if an error occurred while opening the file. ERR: A file format error occurred. This message is displayed if a file other than a Motorola S-record format file or Intel extended format file is specified when mode=chip is specified. ERR: COM port n could not be connected. This message is displayed if COM port n could not be connected. ERR: A data transmission error occurred. This message is displayed if data transmission failed. ERR: A data reception error occurred. This message is displayed if data reception failed (for all three retry attempts). ERR: Processing to update the firmware stopped. This message is displayed if an NAK error was received from the evaluation board. ERR: A file size error occurred. This message is displayed if the data is found to exceed the ROM area during the file size check. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 61 of 76 RL78 microcontroller 6. USB Peripheral Firmware Updater GNU/IAR Ver. CREATING A PROGRAM This chapter provides notes to keep in mind when creating a program. 6.1 Setting Up CS+ (Specifying the HEX File Format) Only HEX files in the Motorola S-record format (32 bits) or Intel extended format can be used for the USB Peripheral firmware update program (the file transfer application) when updating a user-created program. Specify the format in the Object Converter Options menu. In the following example, Motorola S type Format(standard)[-km] is selected from the Select HEX Format. Figure 6-1 Example of Specifying the HEX File Format R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 62 of 76 RL78 microcontroller 6.2 USB Peripheral Firmware Updater GNU/IAR Ver. Boot Processing (Reset Vector Section) Because the firmware update program assumes that vector processing is performed at the start of memory (starting at the address 00000000) following a reset, use the start of memory for the reset section in user-created programs. 6.3 Linker Directives (Restriction on Allocating User-Created Programs) User-created programs cannot be allocated where the firmware update program resides. Therefore, when specifying the segments in the linker directive file, specify an address such that user-created programs are not allocated where the self-update program resides. (For details, see 4.2 Memory Map.) The position of the firmware update program in each product is as follows: Table 6-1 Firmware Update Program Location Address Target CPU 6.4 Address RL78/G1C 00 2000H – 0x00 5FFFH RL78/L1C 00 2000H – 0x00 5FFFH Re-defining the Segments The linker directive file included in the user-created sample program re-defines the internal flash memory spaces as shown below. MEMORY MEMORY MEMORY MEMORY MEMORY MEMORY BCL0 BCL1 ROM ROM_DATA STACK RAM : : : : : : ( ( ( ( ( ( 000000H, 001000H, 006000H, 006800H, 0FE900H, 0FEA00H, 001000H 001000H 000800H 000400H 000100H 001420H ) ) ) ) ) ) Figure 6-2 Re-defining the Segments R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 63 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. 0F FF00 H RAM Area User-Allocated Segment:RAM RAM 0F EA00H Segment:STACK 0F E900H 00 8000 H User-created Application 00 6C00 H Segment:ROM_DATA 00 6800 H Segment:ROM ROM Area 00 6000 H Address 0 save Firmware Use prohibited Update Program 00 2000 H User-created 00 1000 H Segment:Undefined Application Segment:Undefined Branch to 2000H 00 0000 H プログラム Figure 6-3 Mapping the User-Created Sample Program R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 64 of 76 RL78 microcontroller 6.5 USB Peripheral Firmware Updater GNU/IAR Ver. Allocating the Segments The linker directive file included in the user-created sample program re-defines the ROM spaces by using a memory directive and defines the segments in which to allocate the user-created sample program as shown below. MERGE @@LCODE := ROM MERGE @@LCODEL := ROM MERGE @@CNST := ROM_DATA MERGE @@CNSTL := ROM_DATA Figure 6-4 Allocating the Segments R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 65 of 76 RL78 microcontroller 6.6 USB Peripheral Firmware Updater GNU/IAR Ver. Notes on Using the User-Created Program When writing the user-created program, if a new reset vector (address at which the user-created program startup routine is stored) is written, the firmware update program will no longer start, as shown below. Firmware Update Program All reset vectors include code for branching to 2000H. 00 2000H 00 0000H User-created Program 00 0000H If a new user-created program is written as is Firmware Update The reset vector indicates the branch to the user-created program. Execution cannot branch to 00 2000H and only the user-created program can be executed. Program 00 2000H User-created Program 00 0000H Figure 6-5 Overwriting the Reset Vector In the firmware update program, the reset vector is fixed to 00 2000H and the reset vector of the user-created program is saved to a dedicated flash memory area. Even after firmware updating is executed, the user-program or self-update program can therefore be re-executed by restoring the reset vector saved when executing the userprogram. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 66 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. The processing for saving the reset vector is shown below. 00 5C00H Save the reset vector to address 00 5C00H. Data corresponding to each address is written to the other addresses. Firmware Update Program 00 2000H User-created Program User-created Program 00 0000H 00 0000H Firmware update executed 00 5C00H Firmware Update During execution of the user-created program, execution branches to 00 5C00H via the self-update program. Program 00 2000H User-created Program Execution branches again to the reset vector of the user-created program, which has been saved at 00 5C00H. 00 0000H Figure 6-6 Saving the Reset Vector The vector code consists of 2 bytes as shown above, so interrupts branch to an address in the 64 KB area from 00 0000H to 00FFFFH. Therefore, the firmware update program can only be stored in the 64 KB address space when executing a normal branch. Because the vector code consists of 2 bytes, only the branch destination address can be allocated. (Of a 16-bit address, the lower 8 bits are stored at the even address, and the higher 8 bits are stored at the odd address.) Saving the reset vector of the user-created program during self-updating refers to saving the branch address pointed to by the reset vector to which the branch instruction is appended. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 67 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. The figure below shows the memory contents before and after executing self-updating when the reset vector of the user-created program is 5C00H. Reset vector of self-update program Reset vector of user-created program +0 +1 +2 +3 +4 ··· +0 +1 +2 +3 +4 ··· 00 0000H 00 20 ## ## ## ··· 00 0000H 00 5C $$ $$ $$ ··· 00 0010H ## ## ## ## ## ··· 00 0010H $$ $$ $$ $$ $$ ··· The reset vector of the self-update program points to 2000H as the branch address. After the memory is updated to the user-created program whose reset vector is 5C00H, the memory contents are overwritten as shown below. Self-updating executed Reset vector after updating +0 +1 +2 +3 +4 ··· 00 0000H 00 20 $$ $$ $$ ··· 00 0010H $$ $$ $$ $$ $$ ··· The reset vector remains as is. The other areas are overwritten by the user-created program. Address at which the reset vector of the user-created program is stored +0 +1 +2 +3 +4 ··· 00 5C00H EC 00 5C 00 ## ··· 00 5410H ## ## ## ## ## ··· The BR quasi directive that is used to branch to 5C00H is added to the saved address. The process fetches this data (BR 5C00) and branches to 00 5C00H, the user-created program start address. Figure 6-7 Saving the Reset Vector R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 68 of 76 RL78 microcontroller 7. USB Peripheral Firmware Updater GNU/IAR Ver. DATA COMMUNICATION SPECIFICATIONS 7.1 Specifications of the Communication Interface for Updating the Firmware This section describes the communication between the host on which the firmware update program runs and the evaluation board. 7.1.1 Communication data sequence The host transmits a start record at the beginning of communication and an end record at the end. Data loaded into the flash memory is transmitted as a series of data records. Host Start record   Response record Evaluation board Data record   Response record ... End record   Response record Figure 7-1 Communication Data Sequence R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 69 of 76 RL78 microcontroller 7.1.2 USB Peripheral Firmware Updater GNU/IAR Ver. Data transmitted by the host The host transmits a start record, data records, and an end record. Records are transmitted one by one, and the next record is not transmitted until a response record is received. Checksum (<6>) Time (<5>) Date (<4>) Device type (<3>) Record length (<2>) Start record This record is transmitted first when updating the firmware. Record type (<1>) (1) Figure 7-2 Start Record Format <1> Record type : 1byte The type of record The record type of the start record is 0x00. <2> Record length : 1byte The number of bytes for the device type and later <3> Device type : 1byte The type of device <4> Date : 3bytes The current date The year, month, and day require 1 byte each. The last two digits of the year are specified (based on the Western calendar). <5> Time : 3bytes The current time The hour, minute, and second require 1 byte each. <6> Checksum : 1byte The record checksum This is the checksum for the record length, device type, date, and time. The checksum is the lower 8 bits of the one’s complement of the sum of each byte value. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 70 of 76 RL78 microcontroller Checksum (<5>) Load address (<3>) Record length (<2>) Data records These records contain the data to be loaded into the flash memory. Record type (<1>) (2) USB Peripheral Firmware Updater GNU/IAR Ver. Data . . . (<4>) Figure 7-3 Data Record Format <1> Record type : 1byte The type of record The record type of a data record is 0x0f. <2> Record length : 1byte The number of bytes for the load address and later <3> Load address : 4bytes A flash memory address Data is loaded into the flash memory starting at this address. The load address is a 32-bit number in little endian format. <4> Data : 1-256bytes The data to load into the flash memory Each record can contain up to 256 bytes. <5> Checksum : 1byte The record checksum This is the checksum for the record length, load address, and data. The checksum is the lower 8 bits of the one’s complement of the sum of each byte value. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 71 of 76 RL78 microcontroller Checksum (<4>) Device type (<3>) Record length (<2>) End record This record is transmitted after all other records. Record type (<1>) (3) USB Peripheral Firmware Updater GNU/IAR Ver. Figure 7-4 End Record Format <1> Record type : 1byte The type of record The record type of the end record is 0xf0. <2> Record length : 1byte The number of bytes for the device type and later <3> Device type : 1byte The type of device <4> Checksum : 1byte The record checksum This is the checksum for the record length and device type. The checksum is the lower 8 bits of the one’s complement of the sum of each byte value. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 72 of 76 RL78 microcontroller 7.1.3 USB Peripheral Firmware Updater GNU/IAR Ver. Data transmitted by the evaluation board The evaluation board transmits records in response to records from the host. Field . . . (<4>) Checksum (<5>) Response type (<3>) Record length (<2>) Response records Record type (<1>) (1) Figure 7-5 Response Record Format <1> Record type : 1byte The type of record This is the type of record for which this response record is returned. <2> Record length : 1byte The number of bytes for the response type and later <3> Response type : 1byte The response type The following three types are available: 0x00: ACK 0x0f: NAK (a request to transmit the record again) 0xf0: NAK (an error termination) <4> Field : 1-4bytes If an error occurs, the field is a 1-byte error code. If no error occurs, the contents vary depending on the record type as follows. Start record: Device type Data record: Load address End record: Device type <5> Checksum : 1byte The record checksum This is the checksum for the record length, response type, and field. The checksum is the lower 8 bits of the one’s complement of the sum of each byte value. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 73 of 76 RL78 microcontroller 8. USB Peripheral Firmware Updater GNU/IAR Ver. Setup for the e2 studio project (1). Start up e2 studio. * If starting up e2 studio for the first time, the Workspace Launcher dialog box will appear first. Specify the folder which will store the project. (2). Select [File]  [Import]; the import dialog box will appear. (3). In the Import dialog box, select [Existing Projects into Workspace]. Figure 8-1 Select Import Source (4). Press [Browse] for [Select root directory]. Select the folder in which [.cproject ] (project file) is stored. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 74 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. Figure 8-2 Project Import Dialog Box (5). Click [Finish]. This completes the step for importing a project to the project workspace. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 75 of 76 RL78 microcontroller USB Peripheral Firmware Updater GNU/IAR Ver. Website and Support Renesas Electronics Website http://www.renesas.com/ Inquiries http://www.renesas.com/contact/ All trademarks and registered trademarks are the property of their respective owners. R01AN2179EJ0103 Rev.1.03 Mar 28, 2016 Page 76 of 76 Revision Record Rev. 1.00 1.01 1.02 Date Aug. 31, 2014 Mar. 16. 2015 Jan. 18. 2016 1.03 Mar. 28. 2016 Description Page - Summary First edition issued. The documents in “reference” folder are updated. Supported Technical Update (Document No. TN-RL*-A055A/E and TN-RL*-A033B/E) Upgrading of this USB driver by upgrading of "USB Basic Mini Firmware (R01AN0326)". A-1 General Precautions in the Handling of MPU/MCU Products The following usage notes are applicable to all MPU/MCU products from Renesas. For detailed usage notes on the products covered by this document, refer to the relevant sections of the document as well as any technical updates that have been issued for the products. 1. Handling of Unused Pins Handle unused pins in accordance with the directions given under Handling of Unused Pins in the manual.  The input pins of CMOS products are generally in the high-impedance state. In operation with an unused pin in the open-circuit state, extra electromagnetic noise is induced in the vicinity of LSI, an associated shoot-through current flows internally, and malfunctions occur due to the false recognition of the pin state as an input signal become possible. Unused pins should be handled as described under Handling of Unused Pins in the manual. 2. Processing at Power-on The state of the product is undefined at the moment when power is supplied.  The states of internal circuits in the LSI are indeterminate and the states of register settings and pins are undefined at the moment when power is supplied. In a finished product where the reset signal is applied to the external reset pin, the states of pins are not guaranteed from the moment when power is supplied until the reset process is completed. In a similar way, the states of pins in a product that is reset by an on-chip power-on reset function are not guaranteed from the moment when power is supplied until the power reaches the level at which resetting has been specified. 3. Prohibition of Access to Reserved Addresses Access to reserved addresses is prohibited.  The reserved addresses are provided for the possible future expansion of functions. Do not access these addresses; the correct operation of LSI is not guaranteed if they are accessed. 4. Clock Signals After applying a reset, only release the reset line after the operating clock signal has become stable. When switching the clock signal during program execution, wait until the target clock signal has stabilized.  When the clock signal is generated with an external resonator (or from an external oscillator) during a reset, ensure that the reset line is only released after full stabilization of the clock signal. Moreover, when switching to a clock signal produced with an external resonator (or by an external oscillator) while program execution is in progress, wait until the target clock signal is stable. 5. Differences between Products Before changing from one product to another, i.e. to a product with a different part number, confirm that the change will not lead to problems.  The characteristics of an MPU or MCU in the same group but having a different part number may differ in terms of the internal memory capacity, layout pattern, and other factors, which can affect the ranges of electrical characteristics, such as characteristic values, operating margins, immunity to noise, and amount of radiated noise. When changing to a product with a different part number, implement a system-evaluation test for the given product. Notice 1. Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples. You are fully responsible for the incorporation of these circuits, software, and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits, software, or information. 2. Renesas Electronics has used reasonable care in preparing the information included in this document, but Renesas Electronics does not warrant that such information is error free. Renesas Electronics assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein. 3. Renesas Electronics does not assume any liability for infringement of patents, copyrights, or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or technical information described in this document. No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights of Renesas Electronics or others. 4. You should not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from such alteration, modification, copy or otherwise misappropriation of Renesas Electronics product. 5. Renesas Electronics products are classified according to the following two quality grades: "Standard" and "High Quality". The recommended applications for each Renesas Electronics product depends on the product's quality grade, as indicated below. "Standard": Computers; office equipment; communications equipment; test and measurement equipment; audio and visual equipment; home electronic appliances; machine tools; personal electronic equipment; and industrial robots etc. "High Quality": Transportation equipment (automobiles, trains, ships, etc.); traffic control systems; anti-disaster systems; anti-crime systems; and safety equipment etc. Renesas Electronics products are neither intended nor authorized for use in products or systems that may pose a direct threat to human life or bodily injury (artificial life support devices or systems, surgical implantations etc.), or may cause serious property damages (nuclear reactor control systems, military equipment etc.). You must check the quality grade of each Renesas Electronics product before using it in a particular application. You may not use any Renesas Electronics product for any application for which it is not intended. Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for which the product is not intended by Renesas Electronics. 6. You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics, especially with respect to the maximum rating, operating supply voltage range, movement power voltage range, heat radiation characteristics, installation and other product characteristics. Renesas Electronics shall have no liability for malfunctions or damages arising out of the use of Renesas Electronics products beyond such specified ranges. 7. Although Renesas Electronics endeavors to improve the quality and reliability of its products, semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use conditions. Further, Renesas Electronics products are not subject to radiation resistance design. Please be sure to implement safety measures to guard them against the possibility of physical injury, and injury or damage caused by fire in the event of the failure of a Renesas Electronics product, such as safety design for hardware and software including but not limited to redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures. Because the evaluation of microcomputer software alone is very difficult, please evaluate the safety of the final products or systems manufactured by you. 8. Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product. Please use Renesas Electronics products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances, including without limitation, the EU RoHS Directive. Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations. 9. Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations. You should not use Renesas Electronics products or technology described in this document for any purpose relating to military applications or use by the military, including but not limited to the development of weapons of mass destruction. When exporting the Renesas Electronics products or technology described in this document, you should comply with the applicable export control laws and regulations and follow the procedures required by such laws and regulations. 10. It is the responsibility of the buyer or distributor of Renesas Electronics products, who distributes, disposes of, or otherwise places the product with a third party, to notify such third party in advance of the contents and conditions set forth in this document, Renesas Electronics assumes no responsibility for any losses incurred by you or third parties as a result of unauthorized use of Renesas Electronics products. 11. This document may not be reproduced or duplicated in any form, in whole or in part, without prior written consent of Renesas Electronics. 12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electronics products, or if you have any other inquiries. (Note 1) "Renesas Electronics" as used in this document means Renesas Electronics Corporation and also includes its majority-owned subsidiaries. (Note 2) "Renesas Electronics product(s)" means any product developed or manufactured by or for Renesas Electronics. http://www.renesas.com SALES OFFICES Refer to "http://www.renesas.com/" for the latest and detailed information. Renesas Electronics America Inc. 2801 Scott Boulevard Santa Clara, CA 95050-2549, U.S.A. Tel: +1-408-588-6000, Fax: +1-408-588-6130 Renesas Electronics Canada Limited 9251 Yonge Street, Suite 8309 Richmond Hill, Ontario Canada L4C 9T3 Tel: +1-905-237-2004 Renesas Electronics Europe Limited Dukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, U.K Tel: +44-1628-585-100, Fax: +44-1628-585-900 Renesas Electronics Europe GmbH Arcadiastrasse 10, 40472 Düsseldorf, Germany Tel: +49-211-6503-0, Fax: +49-211-6503-1327 Renesas Electronics (China) Co., Ltd. Room 1709, Quantum Plaza, No.27 ZhiChunLu Haidian District, Beijing 100191, P.R.China Tel: +86-10-8235-1155, Fax: +86-10-8235-7679 Renesas Electronics (Shanghai) Co., Ltd. Unit 301, Tower A, Central Towers, 555 Langao Road, Putuo District, Shanghai, P. R. China 200333 Tel: +86-21-2226-0888, Fax: +86-21-2226-0999 Renesas Electronics Hong Kong Limited Unit 1601-1611, 16/F., Tower 2, Grand Century Place, 193 Prince Edward Road West, Mongkok, Kowloon, Hong Kong Tel: +852-2265-6688, Fax: +852 2886-9022 Renesas Electronics Taiwan Co., Ltd. 13F, No. 363, Fu Shing North Road, Taipei 10543, Taiwan Tel: +886-2-8175-9600, Fax: +886 2-8175-9670 Renesas Electronics Singapore Pte. Ltd. 80 Bendemeer Road, Unit #06-02 Hyflux Innovation Centre, Singapore 339949 Tel: +65-6213-0200, Fax: +65-6213-0300 Renesas Electronics Malaysia Sdn.Bhd. Unit 1207, Block B, Menara Amcorp, Amcorp Trade Centre, No. 18, Jln Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, Malaysia Tel: +60-3-7955-9390, Fax: +60-3-7955-9510 Renesas Electronics India Pvt. Ltd. No.777C, 100 Feet Road, HAL II Stage, Indiranagar, Bangalore, India Tel: +91-80-67208700, Fax: +91-80-67208777 Renesas Electronics Korea Co., Ltd. 12F., 234 Teheran-ro, Gangnam-Gu, Seoul, 135-080, Korea Tel: +82-2-558-3737, Fax: +82-2-558-5141 © 2016 Renesas Electronics Corporation. All rights reserved. Colophon 5.0