USB Peripheral Communications Device Class Driver for USB Mini Firmware Using Firmware Integration Technology

Similar documents
This document describes the guidelines for Hi-Speed USB 2.0 board design. 1. Introduction USB Transmission Line... 3

USB Peripheral Communications Device Class Driver (PCDC) using USB Basic Mini Firmware

File driver for FTP server and Web server Module Firmware Integration Technology Contents

Source. Gate N+ N+ N+ Drain. Figure 1 Structure of D Series (Vertical type) (N channel) Channel. Source. Drain. Gate N N+ N+ P+ Substrate

Silicon Planar Zener Diode for Surge Absorption and Stabilizer

Old Company Name in Catalogs and Other Documents

Old Company Name in Catalogs and Other Documents

The application example described in this document applies to the following microcomputers (MCUs): MCUs: M16C Family, R8C Family

Old Company Name in Catalogs and Other Documents

(hereafter T4) File system M3S-TFAT-Tiny SPI mode MultiMediaCard Driver* 2 M3S-T4-Tiny

Old Company Name in Catalogs and Other Documents

PoNET kbd48cnc. User s manual

DPDT SWITCH FOR 2.4 GHz AND 6 GHz DUAL-BAND WIRELESS LAN

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

V850E2/ML4 APPLICATION NOTE. Performance Evaluation Software. Abstract. Products. R01AN1228EJ0100 Rev Aug. 24, 2012

RJH60D7DPK. Preliminary Datasheet. 600V - 50A - IGBT Application: Inverter. Features. Outline. Absolute Maximum Ratings. R07DS0165EJ0400 Rev.4.

AN3998 Application note

Old Company Name in Catalogs and Other Documents

AN4128 Application note

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

Old Company Name in Catalogs and Other Documents

Old Company Name in Catalogs and Other Documents

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

Freescale MQX USB Device User Guide

HG2 Series Product Brief

Software Real Time Clock Implementation on MC9S08LG32

V850. Application Note. 32-Bit Single-Chip Microcontrollers AES 128 Encryption/Decryption. Document No. U19668EE1V0AN00 Date Published January 2009

AN3265 Application note

Application Note. 8-bit Microcontrollers. AVR280: USB Host CDC Demonstration. 1. Introduction

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB

Old Company Name in Catalogs and Other Documents

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

Old Company Name in Catalogs and Other Documents

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

Quectel Cellular Engine

AN3354 Application note

TivaWare USB Library USER S GUIDE SW-TM4C-USBL-UG Copyright Texas Instruments Incorporated

HANDLING SUSPEND MODE ON A USB MOUSE

USER GUIDE EDBG. Description

UM1734 User manual. STM32Cube USB device library. Introduction

Atmel AVR4950: ASF - USB Host Stack. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

Old Company Name in Catalogs and Other Documents

Software User Guide UG-461

Using WinUSB in a Visual Studio Project with Freescale USB device controller

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

AN3332 Application note

MSP430 USB Communications Device Class (CDC) API User s Guide, v0.7

Part Number Decoder for Toshiba NAND Flash

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

ELAN DIGITAL SYSTEMS LTD. SL232 PC- CARD USER S GUIDE

AT91 ARM Thumb Microcontrollers. Application Note. AT91 USB CDC Driver Implementation. 1. Introduction. 2. Related Documents

Single channel data transceiver module WIZ2-434

Pulse Output Forced Cutoff Using the Clock Alarm Function and ELC CC-RL

TOSHIBA Bipolar Linear Integrated Circuit Silicon Monolithic TAR5SB15~TAR5SB50

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

etpu Host Interface by:

Universal Serial Bus Class Definitions for Communication Devices

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

UM0834 User manual. Developing and debugging your STM8S-DISCOVERY application code. Introduction. Reference documents

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

CP2110-EK CP2110 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup

Serial Communications

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

AN1754 APPLICATION NOTE

10-/100-Mbps Ethernet Media Access Controller (MAC) Core

SSM3K335R SSM3K335R. 1. Applications. 2. Features. 3. Packaging and Pin Configuration Rev.3.0. Silicon N-Channel MOS (U-MOS -H)

Learning USB by Doing.

DK40 Datasheet & Hardware manual Version 2

WA Manager Alarming System Management Software Windows 98, NT, XP, 2000 User Guide

Freescale Semiconductor, I

TOSHIBA Transistor Silicon PNP Epitaxial Type (PCT Process) 2SA1020

USB TO SERIAL ADAPTER

Initializing the TSEC Controller

Rev.F 1/3 c 2013 ROHM Co., Ltd. All rights reserved.

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

MCB3101 (Class I) WiRobot Serial Bluetooth Wireless Module User Manual

This application note describes how to use CAN controllers of various Rensas microcontroller products.

AN2680 Application note

Using XGATE to Implement LIN Communication on HCS12X Daniel Malik 8/16-Bit Products Division East Kilbride, Scotland

Application Note AN_209. AN_209 PDIUSBD12 to FT120 Migration Guide

Application Note. AN_136_Hi-Speed Mini Module EEPROM Disaster Recovery

M72. Quectel Cellular Engine. EVB User Guide M72_EVB_UGD_V1.0

AND8336. Design Examples of On Board Dual Supply Voltage Logic Translators. Prepared by: Jim Lepkowski ON Semiconductor.

AN141 SMBUS COMMUNICATION FOR SMALL FORM FACTOR DEVICE FAMILIES. 1. Introduction. 2. Overview of the SMBus Specification. 2.1.

Programming Audio Applications in the i.mx21 MC9328MX21

AT89C5131A Starter Kit... Software User Guide

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Future Technology Devices International Ltd

How To Write To An Eeprom Memory On A Flash Memory On An Iphone Or Ipro Memory On Microsoft Flash Memory (Eeprom) On A Microsoft Microsoft Powerbook (Ai) 2.2.2

Design Considerations in Adding USB Communications to Embedded Applications

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

AN249 HUMAN INTERFACE DEVICE TUTORIAL. Relevant Devices This application note applies to all Silicon Labs USB MCUs. 1.

OfficeServ Link. User Guide. Version 2.1 June 2005

AN220 USB DRIVER CUSTOMIZATION

RZ/T1 Group. User's Manual. Renesas Starter Kit+ User s Manual For e 2 studio. RENESAS MCU Family / RZ/T1 Series. Rev. 1.

HT1632C 32 8 &24 16 LED Driver

AN1164. USB CDC Class on an Embedded Device INTRODUCTION ASSUMPTIONS FEATURES LIMITATIONS

LC898300XA. Functions Automatic adjustment to the individual resonance frequency Automatic brake function Initial drive frequency adjustment function

Transcription:

APPLICATION NOTE USB Peripheral Communications Device Class Driver for USB Mini Firmware Using Firmware Integration Technology Introduction This application note describes USB Peripheral Communication Device Class Driver (PCDC), which utilizes Firmware Integration Technology (FIT). This module performs hardware control of USB communication. It is referred to below as the USB-BASIC-F/W FIT module. Target Device RX111, RX113, RX231 When using this application note with other Renesas MCUs, careful evaluation is recommended after making modifications to comply with the alternate MCU. Related Documents 1. USB Basic Host and Peripheral firmware using Firmware Integration Technology Application Note (Document No. R01AN2166EJ) 2. Universal Serial Bus Revision 2.0 specification 3. USB Class Definitions for Communications Devices Revision 1.2 4. USB Communications Class Subclass Specification for PSTN Devices Revision 1.2 http://www.usb.org/developers/docs/ 5. RX111 User s Manual: Hardware (Document number No. R01UH0365EJ) 6. RX113 User s Manual: Hardware (Document number No. R01UH0448EJ) 7. RX231 User s Manual: Hardware (Document number No. R01UH0496EJ) R01AN2170EJ0102 Rev.1.02 Renesas Electronics Website http://www.renesas.com USB Devices Page http://www.renesas.com/prod/usb/ R01AN2170EJ0102 Rev.1.02 Page 1 of 22

Contents 1. Overview... 3 2. Software Configuration... 4 3. How to Register Class Driver... 7 4. System Resources... 7 5. Task ID and Priority Setting... 7 6. CDC, PSTN, and ACM (Abstract Control Model)... 8 7. USB Peripheral Communication Device Class Driver (PCDC)... 12 8. Creating an Application... 18 R01AN2170EJ0102 Rev.1.02 Page 2 of 22

1. Overview The USB PCDC FIT module, when used in combination with the USB-BASIC-F/W FIT module, operates as a USB peripheral communications device class driver (PCDC). The PCDC conforms to the abstract control model of the USB communication device class specification (CDC) and enables communication with a USB host. This module supports the following functions. Data transfer to and from a USB host Response to CDC class requests Provision of communication device class notification transmit service Terms and Abbreviations Terms and abbreviations used in this document are listed below. ACM : Abstract Control Model. This is the USB interface subclass used for virtual COM ports, based in the old V.250 (AT) command standard. See PSTN below. APL : Application program API : Application Program Interface CDC : Communications Devices Class CDCC : Communications Devices Class Communications Interface Class CDCD : Communications Devices Class Data Class Interface CPD : Serial Communication Port Driver cstd : Prefix of function and file for Host & Peripheral USB-BASIC-FW Data Transfer : Generic name of Control transfer, Bulk transfer and Interrupt transfer H/W : Renesas USB device PCD : Peripheral control driver of USB-BASIC-F/W PCDC : Communications Devices Class for peripheral PCDCD : Peripheral Communications Devices Class Driver PDCD : Peripheral device class driver (device driver and USB class driver) PP : Pre-processed definition pstd : Prefix of function and file for Peripheral USB-BASIC-FW PSTN : Public Switched Telephone Network, contains the ACM (above) standard. Scheduler : Used to schedule functions, like a simplified OS. Scheduler Macro : Used to call a scheduler function SCI : Serial Communication Interface Task : Processing unit USB : Universal Serial Bus USB-BASIC-FW : USB Host and Peripheral Basic Mini Firmware USB-BASIC-FW FIT : USB Host and Peripheral Basic Mini Firmware using Firmware Integration Technology 1.1 USB PCDC FIT Module User needs to integrate this module to the project using r_usb_basic_mini. User can control USB H/W by using this module API after integrating to the project. Please refer to the chapter How to add the module about how to add the module. R01AN2170EJ0102 Rev.1.02 Page 3 of 22

2. Software Configuration Figure 2-1 shows the configuration of the modules related to PCDC. User application (APL) USB peripheral communications device driver (PCDC) Serial Communication port driver (CPD) USB peripheral control driver (PCD) Serial communication interface (hardware) USB peripheral controller (hardware) Figure 2-1 Source Code Block Diagram Table 2.1 Modules Module PCDC PCD CPD Description Sends requests from the APL for requests and data communication involving the CDC to the PCD. USB peripheral hardware control driver. (Basic USB FW.) Serial port control driver R01AN2170EJ0102 Rev.1.02 Page 4 of 22

2.1 API Information This Driver API follows the Renesas API naming standards. 2.1.1 Hardware Requirements This driver requires your MCU support the following features: USB 2.1.2 Software Requirements This driver is dependent upon the following packages: r_bsp r_usb_basic_mini 2.1.3 Supported Toolchains This driver is tested and working with the following toolchains: Renesas RX Toolchain v.2.03.00 2.1.4 Header Files All API calls and their supporting interface definitions are located in r_usb_pcdc_mini_if.h. 2.1.5 Integer Types This project uses ANSI C99 Exact width integer types in order to make the code clearer and more portable. These types are defined in stdint.h. 2.1.6 Compile Setting In order to use this module, it is necessary to set the USB-BASIC-F/W FIT module as a peripheral. Refer to USB- BASIC-F/W FIT module application note (Document No. R01AN2166EJ) for information on USB-BASIC-F/W FIT module settings. 2.1.7 Argument The structure for the arguments of the API functions is shown below. For details, please refer to USB-BASIC-F/W FIT module application note (Document No. R01AN2166EJ). struct usb_utr_t usb_strct_t msginfo; /* Message information */ usb_strct_t pipenum ; /* Sub information(port No/Pipe No etc) */ usb_strct_t status; /* USB status */ usb_strct_t flag; /* Flag */ usb_cb_t complete; /* Pointer to the callback function */ usb8_t *tranadr; /* Pointer to USB transfer buffer */ uint16_t *setup; /* Pointer to Setup packet data */ uint16_t pipectr; /* PIPECTR register */ usb_leng_t tranlen; /* USB data length*/ uint8_t dummy; /* Adjustment of the byte border */ R01AN2170EJ0102 Rev.1.02 Page 5 of 22

2.1.8 How to add the module This module must be added to an existing e 2 studio project. By using the e 2 studio plug-in, it is possible to update the include file path automatically. It is therefore recommended that this plug-in be used to add the project. For instructions when using e 2 studio, refer to RX Family: Adding Firmware Integration Technology Modules to Projects (document No. R01AN1723EU). For instructions when using CS+, refer to RX Family: Integration into CS+, Firmware Integration Technology (document No. R01AN1826EJ). R01AN2170EJ0102 Rev.1.02 Page 6 of 22

3. How to Register Class Driver The class driver which the user created functions as a class driver by registering with a USB driver. For details, please refer to the chapter "How to register peripheral Class Driver" of USB-BASIC-F/W FIT module application note (Document No. R01AN2166EJ). 4. System Resources The resource which PCDC uses is showed in Table 4-1 -Table 4-2. Table 4-1 Task Information Function Task ID Priority Description usb_pcdc_task USB_PCDC_TSK USB_PRI_1 PCDC Task Table 4-2 Mailbox Information Mailbox Mailbox ID Queue Description USB_PCDC_MBX USB_PCDC_TSK FIFO order for PCDC 5. Task ID and Priority Setting Define the setting value for User task ID within the following range. The task priority level is the same as the task ID. The highest priority level becomes 0. [Note] Task ID : 2 to (USB_IDMAX - 1) Mailbox ID : Set the same value as Task ID 1. USB_IDMAX is the defined by User in r_usb_basic_mini_config.h file. 2. Task IDs 0 and 1 are already defined. When setting task IDs, use values other than 0 and 1. 3. Define ID numbers for user tasks, etc., in the application files. R01AN2170EJ0102 Rev.1.02 Page 7 of 22

6. CDC, PSTN, and ACM (Abstract Control Model) 6.1 Basic Functions This software conforms to the Abstract Control of the CDC PSTN Subclass. See.6.2 below. The main functions of the PCDC firmware: 1. Respond to functional inquiries from the USB Host 2. Respond to class requests from the USB Host 3. Data communication with the USB Host 4. Notify the USB Host of serial communication errors 6.2 Abstract Control Model Overview The Abstract Control Model subclass of CDC is a technology that bridges the gap between USB devices and earlier modems (employing RS-232C connections), enabling use of application programs designed for older modems. The class requests and class notifications supported are listed below. 6.2.1 Class Requests (Host to Peripheral) Table 6.1 shows CDC class requests, and whether they are supported. Table 6.1 CDC class requests Request Code Description Supported SendEncapsulatedCommand 0x00 Transmits AT commands, etc., defined by the No protocol. GetEncapsulatedResponse 0x01 Requests a response to a command transmitted No by SendEncapsulatedCommand. SetCommFeature 0x02 Enables or disables features such as devicespecific No 2-byte code and country setting. GetCommFeature 0x03 Acquires the enabled/disabled state of features No such as device-specific 2-byte code and country setting. ClearCommFeature 0x04 Restores the default enabled/disabled settings of No features such as device-specific 2-byte code and country setting. SetLineCoding 0x20 Makes communication line settings Yes (communication speed, data length, parity bit, and stop bit length). GetLineCoding 0x21 Acquires the communication line setting state. Yes SetControlLineState 0x22 Makes communication line control signal (RTS, Yes DTR) settings. SendBreak 0x23 Transmits a break signal. No For details concerning the Abstract Control Model requests, refer to Table 11, Requests - Abstract Control Model in USB Communications Class Subclass Specification for PSTN Devices, Revision 1.2. R01AN2170EJ0102 Rev.1.02 Page 8 of 22

6.2.2 Data Format of Class Requests The data format of the class requests supported by the class driver software is described below. (1). SetLineCoding This is the class request the host transmits to perform the UART line setting. The SetLineCoding data format is shown below. Table 6.2 SetLineCoding Format bmrequesttype brequest wvalue windex wlength Data 0x21 SET_LINE_CODING (0x20) 0x00 0x00 0x07 Line Coding Structure See Table 6.3 Line Coding Format Table 6.3 Line Coding Format Offset Field Size Value Description 0 DwDTERate 4 Number Data terminal speed (bps) 1200bps/2400bps/4800bps/9600bps/14400bps 19200bps/38400bps/57600bps/115200bps 4 BcharFormat 1 Number Stop bits 0-1 stop bit 1-1.5 stop bits 2-2 stop bits 5 BparityType 1 Number Parity 0 - None 1 - Odd 2 - Even 6 BdataBits 1 Number Data bits (5, 6, 7, 8) (2). GetLineCoding This is the class request the host transmits to request the UART line state. The GetLineCoding data format is shown below. Table 6.4 SetLineCoding Format bmrequesttype brequest wvalue WIndex wlength Data 0xA1 GET_LINE_CODING (0x21) 0x00 0x00 0x07 Line Coding Structure See Table 6.3, Line Coding Structure Format R01AN2170EJ0102 Rev.1.02 Page 9 of 22

(3). SetControlLineState This is a class request that the host sends to set up the signal for flow controls of UART. This software does not support RTS/DTR control. The SET_CONTROL_LINE_STATE data format is shown below. Table 6.5 SET_CONTROL_LINE_STATE Format bmrequesttype brequest WValue windex wlength Data 0x21 SET_CONTROL_ LINE_STATE (0x22) Control Signal Bitmap See Table 6.6, Control Signal Bitmap Format 0x00 0x00 None Table 6.6 Control Signal Bitmap Bit Position Description D15 to D2 Reserved (reset to 0) D1 DCE transmit function control 0 - RTS Off 1 - RTS On D0 Notification of DTE ready state 0 - DTR Off 1 - DTR On 6.2.3 Class Notifications (Peripheral to Host) Whether or not a class notification is supported is shown in Table 6.7. Table 6.7 CDC Class Notifications Notification Code Description Supported NETWORK_CONNECTION 0x00 Notification of network connection state No RESPONSE_AVAILABLE 0x01 Response to GET_ENCAPSLATED_RESPONSE No SERIAL_STATE 0x20 Notification of serial line state Yes (1). Serial State The host is notified of the serial state when a change in the UART port state is detected. This software supports the detection of overrun, parity and framing errors. A state notification is performed when a change from normal state to error is detected. However, notification is not continually transmitted when an error is continually detected. The Serial State data format is shown below. Table 6.8 Serial State Format bmrequesttype brequest wvalue windex wlength Data 0xA1 SERIAL_STATE (0x20) 0x00 0x00 0x02 UART State bitmap See Table 6.9 UART state bitmap format R01AN2170EJ0102 Rev.1.02 Page 10 of 22

Table 6.9 UART state bitmap format Bits Field Description Supported D15~D7 Reserved - D6 boverrun Overrun error detected Yes D5 bparity Parity error detected Yes D4 bframing Framing error detected Yes D3 bringsignal INCOMING signal (ring signal) detected No D2 bbreak Break signal detected No D1 btxcarrier Data Set Ready: Line connected and ready for communication No D0 brxcarrier Data Carrier Detect: Carrier detected on line No 6.3 PC Virtual COM-port Usage The CDC device can be used as a virtual COM port when operating in Windows OS. Use a PC running Windows OS, and connect an RSK board. After USB enumeration, the CDC class requests GetLineCoding and SetControlLineState are executed by the target, and the CDC device is registered in Windows Device Manager as a virtual COM device. Registering the CDC device as a virtual COM-port in Windows Device Manager enables data communication with the CDC device via a terminal app such as HyperTerminal which comes standard with Windows. When changing settings of the serial port in the Windows terminal application, the UART setting is propagated to the firmware via the class request SetLineCoding. Data input (or file transmission) from the terminal app window is transmitted to the RSK board using endpoint 2 (EP2); data from the RSK board side is transmitted to the PC using EP1. When the last packet of data received is the maximum packet size, and the terminal determines that there is continuous data, the received data may not be displayed in the terminal. If the received data is smaller than the maximum packet size, the data received up to that point is displayed in the terminal. (The maximum packet size for Full-Speed is 64 bytes.) The received data is outputted on the terminal when the data less than Maximum packet size is received. R01AN2170EJ0102 Rev.1.02 Page 11 of 22

7. USB Peripheral Communication Device Class Driver (PCDC) 7.1 Basic Functions The basic functions of PCDC are as follows. 1. Provides data transmission and reception services to the USB host. 2. Responds to CDC class requests. 3. Provides a CDC notification transmission service. 7.2 PCDC API Functions Table 7.1 shows all the PCDC API functions. Function R_usb_pcdc_LineCodingInitial R_usb_pcdc_SendData R_usb_pcdc_ReceiveData R_usb_pcdc_ClassRequest R_usb_pcdc_Task Table 7.1 PCDC API Functions Description Line Coding initialization. Sends a data transmit request message to PCDC task. Sends a data reception request message to PCDC task. Callback function called at the time of a USB Set Interface reception PCDC task R01AN2170EJ0102 Rev.1.02 Page 12 of 22

7.2.1 R_usb_pcdc_LineCodingInitial LineCoding Initialize Format usb_er_t Argument *linecoding Return Value USB_E_OK Description Note R_usb_pcdc_LineCodingInitial( usb_pcdc_linecoding_t *linecoding) LineCoding setting data address Success This function initialize a LineCoding - Example void usb_smp_initial( void ) usb_pcdc_linecoding_t linecoding; : linecoding.dwdterate = USB_PCDC_SPEED_19200; linecoding.bcharformat = USB_PCDC_STOP_BIT_1; : R_usb_pcdc_LineCodingInitial( &linecoding ); R01AN2170EJ0102 Rev.1.02 Page 13 of 22

7.2.2 R_usb_pcdc_SendData Transfer USB data Format void R_usb_pcdc_SendData( uint8_t *buf, usb_leng_t size, usb_cb_t complete) Argument buf size complete Return Value - Description Note Pointer to buffer containing data to transmit Transfer size Process completion callback function - This function transfers the specified USB data of the specified size from the address specified in the Transmit Data Address "buf". Example When the transmission is done, the call-back function complete is called. 1. The USB transmit process results are found via the usb_utr_t pointer in the call-back function s arguments. 2. Specify the area other than the auto variable (stack) area to the 1st argument. 3. See USB Communication Structure (usb_utr_t) in the USB-BASIC F/W FIT module application note. void usb_apl_task( void ) usb_leng_t size = 5; /* Data size */ R_usb_pcdc_SendData( send_data, size, (usb_cb_t)&usb_complete ); /* Callback function */ void usb_complete(usb_utr_t *mess, uint16_t data1, uint16_t data2) /* Processing at the time of the completion of USB transmitting */ R01AN2170EJ0102 Rev.1.02 Page 14 of 22

7.2.3 R_usb_pcdc_ReceiveData Issue a data receive request to USB driver Format void Argument buf size complete R_usb_pcdc_ReceiveData (uint8_t *buf, usb_leng_t size, usb_cb_t complete) Pointer to transmit data buffer address Transfer size Process completion callback function Return Value - Description Note - This function requests USB data reception of the USB driver. When the data of the size specified by 3rd argument is received or the data of less than max packet size is received from USB, callback function is called. Example The received data is stored in the area that is specified by the second argument. 1. The USB transmit process results are found via the usb_utr_t pointer in the call-back function s arguments. 2. Specify the area other than the auto variable (stack) area to the 1st argument. 3. When the received data is n times of the maximum packet size and less than the specified size in the argument (size), it is considered that the data transfer is not ended and a callback function (complete) is not generated. 4. See "USB Communication Structure" (usb_utr_t) in the USB Basic Firmware application note. void usb_smp_task(void) usb_leng_t size = 64; /* Data size */ R_usb_pcdc_ReceiveData(receive_data, size, (usb_cb_t)&usb_complete); /* Callback function */ void usb_complete( usb_utr_t *mess, uint16_t data1, uint16_t data2 ) /* Processing at the time of the completion of USB reception */ R01AN2170EJ0102 Rev.1.02 Page 15 of 22

7.2.4 R_usb_pcdc_ClassRequest Control transfer processing for CDC Format void R_usb_pcdc_ClassRequest( usb_request_t *request, uint16_t data ) Argument * request Class request message pointer. data Control transfer stage information USB_CS_IDST (0x00) Idle or setup stage USB_CS_RDDS (0x01) Control read data stage USB_CS_WRDS (0x02) Control write data stage USB_CS_WRND (0x03) Control write no data status stage USB_CS_RDSS (0x04) Control read status stage USB_CS_WRSS (0x05) Control write status stage USB_CS_SQER (0x06) Sequence error Return Value - Description - When the request type is a CDC class request, this function calls the processing that corresponds to the control transmit stage. Register this API as the callback function called when a control transfer occurs during device class driver registration. Note - Example void usb_apl_task( void ) usb_pcdreg_t driver; : /* Control Transfer */ driver.ctrltrans = &R_usb_pcdc_ClassRequest; R_usb_pcdc_Registration(&driver); : R01AN2170EJ0102 Rev.1.02 Page 16 of 22

7.2.5 R_usb_pcdc_Task The PCDC task Format void R_usb_pcdc_Task(void) Argument - - Return Value - - Description This is the PCDC task which processes requests by the application and notifies the application of the results. Note 1. Call this API from the user application program or the class driver. 2. Register this API so that it is scheduled by the task switching processing. Example void usb_apl_task_switch(void) while( 1 ) if( USB_FLGSET == R_usb_cstd_Scheduler()) /* PCD Task */ R_usb_pstd_PcdTask(); /* Peripheral Communications Devices Class Task */ R_usb_pcdc_Task(); /* Peripheral Communications Class Application Task */ usb_pcdc_main_task(); R01AN2170EJ0102 Rev.1.02 Page 17 of 22

8. Creating an Application This section describes the initial settings necessary for using the USB PCDC FIT module and USB-BASIC-F/W FIT module in combination as a USB driver and presents an example of data transfer by means of processing by the main routine and the use of API functions. 8.1 Initial Settings of USB Driver The following settings are required in order to use the USB driver. MCU pin settings USB controller startup and settings USB driver settings Sample settings are shown below. /* USB Transfer Structure for PCDC */ usb_utr_t usb_gpcdc_utr void usb_pcdc_apl(void) usb_er_t err; /* USB module starting and setting (Refer to 8.1.1 USB Module Startup and Settings ) */ err = R_USB_Open(); if(err!= USB_SUCCESS) /* Error processing */ /* MCU Pin Setting (Refer to 8.1.2 MCU Pin Settings ) */ usb_mcu_setting(); /* USB Driver Setting (Refer to 8.1.3 USB Driver Settings ) */ R_usb_pstd_ChangeDeviceState( USB_DO_INITHWFUNCTION ); R_usb_pstd_PcdOpen(); usb_psmpl_driver_registration(); R_usb_pstd_ChangeDeviceState( USB_DO_SETHWFUNCTION ); usb_smpl_set_suspend_flag( USB_NO ); usb_psmpl_linecodinginitial(); /* Main routine */ usb_papl_mainloop(); 8.1.1 USB Module Startup and Settings The USB module startup and setting procedure is described below. 1. Call R_USB_Open() to launch the USB module. This API function should only be called once, when making initial settings. R01AN2170EJ0102 Rev.1.02 Page 18 of 22

8.1.2 MCU Pin Settings It is necessary to make USB I/O pin settings in order to use the USB controller. Sample USB I/O pin settings are shown below. Pin Name I/O Description USB_VBUS Input USB VBUS pin [Note] Table8-1 USB I/O Pin Settings for Peripheral Operation The USB PCDC FIT module and USB-BASIC-F/W FIT module do not make microcontroller pin settings. If pin settings are necessary, refer to the user s manual of the specific microcontroller and make pin settings to match the specifications of the evaluation board to be used. 8.1.3 USB Driver Settings The USB driver settings consist of registering a task with the scheduler and registering class driver information for the USB-BASIC-F/W FIT module. The procedure for registering the class driver information and registering the task with the scheduler is described below. 1. Call the USB-BASIC-FW FIT module s API function (R_usb_pstd_ChangeDeviceState()) to reset the USB-IP.* 1 2. Call the USB-BASIC-F/W FIT module s API functions (R_usb_pstd_PcdOpen()) to register the PCD task with the scheduler. 3. After setting the information for the members of the class driver registration structure (usb_pcdreg_t) with the usb_psmpl_driver_registration() function, call R_usb_pcdc_Registration() to register the class driver information for the USB-BASIC-FW FIT module. 4. Call the USB-BASIC-FW FIT module s API function (R_usb_pstd_ChangeDeviceState) to set the USB-IP functionality to peripheral.* 1 5. Enable the suspend state. 6. Initialize the class request LineCoding.* 2 [Note] 1. Run USB_DO_INITHWFUNCTION before starting USB-BASIC-F/W, and run USB_DO_SETHWFUNCTION after registering the UPL. 2. Refer to Table 6.3, Line Coding Format, for the content to be initialized. A sample of information specified in the structure declared by usb_pcdreg_t is shown below. void usb_psmpl_driver_registration() usb_pcdreg_t driver; /* Structure for the class driver registration */ /* Pipe information table setting */ driver.pipetbl = &usb_gpcdc_eptbl1[0]; // Note 1 /* Set the Device Descriptor table */ driver.devicetbl = (uint8_t*)&usb_gpcdc_devicedescriptor[0]; // Note 2 /* Set the Configuration Descriptor table */ driver.configtbl = &usb_gpcdc_configrationf1[0]; // Note 2, 3 /* Set the String Descriptor */ driver.stringtbl = (uint8_t**)&usb_gpcdc_strptr[0]; // Note 2, 4 /* Set the function which is called when a USB state transition occurs */ driver.statediagram = (usb_cbinfo_t)&usb_psmpl_change_device_state; /* Set the function which is called when processing the control transfer other than the standard request */ driver.ctrltrans = &R_usb_pcdc_ClassRequest; /* Register the class driver information to PCD */ R_usb_pcdc_Registration(&driver); /* Register the CDC class request callback */ usb_gpcdc_aplcb = (usb_cb_t) usb_psmpl_dummyfunc; R01AN2170EJ0102 Rev.1.02 Page 19 of 22

[Note] 1. The pipe information table need to be defined in the application program. Refer to USB-BASIC-F/W FIT module application note (Document No.R01AN2166EJ) about the pipe information table. = Example of Pipe Information Table = uint16_t usb_gpcdc_eptbl1 [] = /* PIPE4 Definition */ USB_PIPE4, USB_BULK USB_BFREOFF USB_DBLBON USB_SHTNAKON USB_DIR_P_IN USB_EP1, USB_MAX_PACKET(64), USB_NULL, /* PIPE5 Definition */ USB_PIPE5, USB_BULK USB_BFREOFF USB_DBLBON USB_SHTNAKON USB_DIR_P_OUT USB_EP2, USB_MAX_PACKET(64), USB_NULL, /* PIPE6 Definition */ USB_PIPE6, USB_INT USB_DIR_P_IN USB_EP3, USB_MAX_PACKET(16), USB_NULL, /* Pipe end */ USB_PDTBLEND ; 2. Create each descriptor based on USB specification. 3. Set the start address of array (Refer to the following) which is set the configuration descriptor start address in this member. uint8_t usb_gpcdc_configrationf1 [] = usb_gpcdc_configration ; 4. Set the start address of array (Refer to the following) which is set the string descriptor start address in this member. uint8_t *usb_gpcdc_strptr[] = usb_gpcdc_stringdescriptor0, usb_gpcdc_stringdescriptor1, usb_gpcdc_stringdescriptor2, R01AN2170EJ0102 Rev.1.02 Page 20 of 22

8.2 Processing by Main Routine After the USB driver initial settings, call the scheduler (R_usb_cstd_Scheduler()) from the main routine of the application. Calling R_usb_cstd_Scheduler() from the main routine causes a check for events. If there is an event, a flag is set to inform the scheduler that an event has occurred. Also, it is necessary to run processing at regular intervals to get events and perform the appropriate processing. (Note1) void usb_papl_mainloop(void) while(1) // Main routine if(usb_flgset == R_usb_cstd_Scheduler();) // Judgment whether the event is or not (Note1) R_usb_pstd_PcdTask(); // HCD task R_usb_pcdc_task(); // CDC task pcdc_application(); // User application program (Note2) [Note] 1. If, after getting an event with R_usb_cstd_Scheduler() and before running the corresponding processing, R_usb_cstd_Scheduler() is called again and gets another event, the first event is discarded. After getting an event, always call the corresponding task to perform the appropriate processing. 2. Be sure to describe these processes in the main loop for the application program. 8.3 Data Transfer From the application, call the PCDC class API function (R_usb_pcdc_SendData () or R_usb_pcdc_ReceiveData ()) to transmit data to or receive data from the connected USB device (bulk out or bulk in transfer). R_usb_pcdc_SendData () and R_usb_pcdc_ReceiveData () have the following arguments. = Data Transmission = R_usb_pcdc_SendData ( uint8_t *Table, // Pointer to the transferred data buffer area (Note) usb_leng_t size, // Transferred data size usb_cbinfo_t complete // Callback function (Note) ) [Note] The data buffering area and the callback function need to be defined in the application program. = Data Reception = R_usb_pcdc_ReceiveData ( uint8_t *Table, // Pointer to the transferred data buffer area (Note) usb_leng_t size, // Transferred data size usb_cbinfo_t complete // Callback function (Note) ) [Note] The data buffering area and the callback function need to be defined in the application program. 8.4 Vendor ID Please be sure to use your vendor ID. R01AN2170EJ0102 Rev.1.02 Page 21 of 22

Website and Support Renesas Electronics Website http://www.renesas.com/ Inquiries http://www.renesas.com/inquiry All trademarks and registered trademarks are the property of their respective owners. R01AN2170EJ0102 Rev.1.02 Page 22 of 22

Revision Record Rev. Date Description Page Summary 1.00 Dec 1, 2014 First edition issued 1.01 Jun 1, 2015 RX231 is added in the target device. The baud rate value which this driver supports is added in Table 6.3. 1.02 Checked the operation with Windows 10. 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. 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, HALII 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 http://www.renesas.com 2015 Renesas Electronics Corporation. All rights reserved. Colophon 5.0