To our customers, Old Company Name in Catalogs and Other Documents On April 1st, 2010, NEC Electronics Corporation merged with Renesas Technology Corporation, and Renesas Electronics Corporation took over all the business of both companies. Therefore, although the old company name remains in this document, it is a valid Renesas Electronics document. We appreciate your understanding. Renesas Electronics website: http://www.renesas.
Notice 1. 2. 3. 4. 5. 6. 7. All information included in this document is current as of the date this document is issued. Such information, however, is subject to change without any prior notice. Before purchasing or using any Renesas Electronics products listed herein, please confirm the latest product information with a Renesas Electronics sales office.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note Preface This document describes how to implement USB to serial conversion system as an application example for the SH7285 and SH7286 MCU’s USB function module. This document and the sample program described are examples of the USB function module, and are therefore not guaranteed by Renesas. Target Devices SH7285 and SH7286 MCUs 1. 1.1 1.2 1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 1. 1.1 Introduction Specifications This document describes how to use the SH7285/SH7286 USB function module, and how to implement a USB to serial conversion system as an application example of the USB function module. 1.2 Functions • USB function module • Serial communication interface with FIFO (SCIF) 1.3 Applicable Conditions • MCUs • Operating frequency • C compiler • Compile options REJ05B1152-0100/Rev.1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 2. Applications This sample program uses the USB function module to execute the control IN, control OUT, bulk IN, and bulk OUT transfers. The sample program also converts USB to serial signals and vice versa. 2.1 Features The USB function module has an embedded USB 1.1 compliant USB Device Controller (UDC) to automatically process USB protocols.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 2.3 Detecting a Connection to the USB Host A connection to the USB host is detected using the cable connect interrupt (the BRST bit in the USBIFR0 register). The cable connect interrupt occurs when a USB device cable is connected to the USB host. After the user configures the MCU, the sample program pulls up the USB data bus D+ pin using the general output port.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note Figure 2.2 REJ05B1152-0100/Rev.1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 2.4 Control Transfer A control transfer is a USB transfer that uses the endpoint 0 default pipe and must be supported by all USB devices. The USB host issues a USB standard request to the USB device and configures the device. A control transfer can be used to issue a class- or vendor-specific request. A control transfer is composed of a Setup stage, Data stage (not in all cases), and Status stage.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note The USB function module decodes the request, and automatically processes the Data stage and Status stage according to the USB standard request. However, some USB standard requests, class requests, and vendor requests should be executed by the software. The sample program executes the Get Descriptor command, which is the USB standard request to be processed by the software.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 2.4.1 Setup Stage The Setup stage is composed of one setup transaction. The USB host sends a setup token or data packet (USB command), then returns a handshake in response to the data packet (USB command) that the USB device received. Figure 2.5 shows the Setup Transaction Flowchart. The USB function module automatically executes the Setup stage, Data stage, and Status stage in response to the USB requests (with some exceptions).
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note Sample Program (Software) (USBIFR0 interrupt) USB Function (Hardware) Executes the ActControl function in the USBIFR0 interrupt handler. Receives the EP0 setup token Interrupt started ActControl started Receives a command in EP0S ActControl handles subsequently Hardware processes each Yes stage automatically.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 2.4.2 Data Stage The Data stage of the control IN transfer is composed of single or multiple data transactions. This is called “Data IN stage processing”. The Data stage of the control OUT transfer is composed of one data OUT transaction. This is called “Data OUT stage processing”. (1) Data IN Stage First, the USB host sends an IN token.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note Figure 2.8 REJ05B1152-0100/Rev.1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note (2) Data OUT Stage The USB host sends an OUT token and a data packet. The USB device receives the OUT token first, then receives the data packet, and then returns an ACK handshake. When the USB device cannot receive the data packet after it receives the OUT token, it ignores subsequent data packets, and returns a NAK handshake. When the USB host receives a NAK handshake, it tries to resend the OUT token and data packet. Figure 2.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note Figure 2.10 REJ05B1152-0100/Rev.1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 2.4.3 Status Stage The direction of the data transaction in the Status stage differs from that of the Data stage; the data OUT transaction is executed during the Status stage of the control IN transfer, and the data OUT transaction is executed during the Status stage of the control OUT transfer. (1) Status Stage of the Control IN Transfer The USB host sends an OUT token and a 0-byte data packet.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note (2) Status Stage of the Control OUT Transfer The USB host sends an IN token. The USB device sends a 0-byte data packet to the USB host after it receives the IN token. Then, the USB device waits for an ACK handshake from the USB host. When the USB function module receives the IN token, it generates the IN token receive interrupt using the EP0iTR bit in the USBIFR0 register.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 2.5 Bulk Transfer A bulk transfer is used to communicate large amounts of data between the USB host and the USB device. Bulk transfers are supported via bi-directional communication flow, according to the data direction. A bulk OUT transfer is the data flow from the USB host to the USB device, and a bulk IN transfer is the data flow from the USB device to the USB host. Figure 2.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 2.5.1 Bulk OUT Transfer A bulk OUT transfer is composed of single or multiple OUT transactions. The USB host sends an OUT token and a data packet in the OUT transaction. The USB device receives the out token first, then receives the data packet, and then returns an ACK handshake. When the USB device receives the OUT token although it is unable to receive data packets, it ignores subsequent data packets and returns a NAK handshake.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note Figure 2.15 REJ05B1152-0100/Rev.1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 2.5.2 Bulk IN Transfer A bulk IN transfer consists of single or multiple transactions. The USB host sends an IN token in the IN transaction. When the USB device receives the IN token, it sends a data packet to the USB host and waits for an ACK handshake from the USB host. When the USB device receives the IN token although it is unable to send data packets, it returns a NAK handshake to the USB host. Figure 2.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note Figure 2.17 REJ05B1152-0100/Rev.1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 3. 3.1 USB to Serial Conversion System Using the USB Function Module Overview The sample program converts USB to serial using the USB function module and the serial communication interface embedded in the SH7285 MCU. To transfer keyboard-input characters, text files, or binary files, activate the terminal software both on the USB host (a computer in this case), and on the serial device.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note Table 3.1 Specifications Features Description Detect a connection to the USB host After the hardware detects a connection, the port pulls up the D+ pin. • Decode requests, processes the Data stage and Status stage of the USB request transmitted from the USB host in the control transfer. • Sends the descriptor information shown in Figure 3.2 through Figure 3.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note /* Configuration Descriptor */ /* Configuration Descriptor informations , Data length = 67Byte */ unsigned char configurationItem[] = { /* Configuration Descriptor */ 0x09, /* 0:bLength */ 0x02, /* 1:bDescriptorType */ 0x43, /* 2:wTotalLength(L) */ /* 43'h (=67) */ 0x00, /* 3:wTotalLength(H) */ 0x02, /* 4:bNumInterfaces */ 0x01, /* 5:bConfigurationValue */ 0x00, /* 6:iConfiguration */ 0xC0, /* 7:bmAttributes */ /* self powered */ 0
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note /* Interface Descriptor 1-1-0 [Data Class Interface] */ 0x09, /* 0:bLength */ 0x04, /* 1:bDescriptor */ 0x01, /* 2:bInterfaceNumber */ 0x00, /* 3:bAlternateSetting */ 0x02, /* 4:bNumEndpoints */ /* support Bulk OUT (= EP1) and Bulk IN (= EP2) */ 0x0A, /* 5:bInterfaceClass */ /* Data Interface Class */ 0x00, /* 6:bInterfaceSubClass */ /* unuse */ 0x00, /* 7:bInterfaceProtocol */ /* USB */ 0x00, /* 8:iInterface */ /* Endpoint Descrip
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 3.2 Operation Flowchart The sample program enters the main loop after initial settings are completed. When the sample program receives a data packet from the serial device in serial IN communication, it stores the received packet in the bulk IN transfer RAM. The stored data is transmitted to the USB host in a bulk IN transfer. For details on bulk IN transfer, refer to 2.5.2 Bulk IN Transfer.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note M3A-HS85 sample program USB host Serial device Serial I/F USB I/F Serial OUT communication Bulk OUT transfer RAM 256 bytes Bulk OUT transfer Serial I/F USB I/F Bulk IN transfer Bulk IN transfer RAM 256 bytes Figure 3.6 REJ05B1152-0100/Rev.1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 3.3 Serial Communication The sample program uses a SCIF module 1 for serial communication. Serial OUT communication is executed only when there is data in the bulk OUT transfer RAM, and serial IN communication is executed only by the serial receive interrupt. 3.3.1 Serial OUT Communication The sample program uses the ActSerialout function to execute serial OUT communication.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 3.3.2 Serial IN Communication Serial IN communication is activated by the serial receive interrupt and executed by the ActSerialIn function. The sample program stores serially-received data in the RAM for the bulk IN transfer. When the RAM is full, the sample program transmits Xoff in serial communication to disable the serial IN communication. Figure 3.8 shows an operation flowchart of the Serial IN Communication. Figure 3.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 3.4 Setting Environment Use an RS-232C serial cable to connect the M3A-HS85 (SH7285 CPU board) to the computer (cross-connect). Then, use a USB cable to connect the M3A-HS19 to the computer. Figure 3.9 shows the Setting Environment. Terminal 1 Terminal 2 ABC DEF USB to serial conversion SH7285 Serial communication USB communication USB host computer SH7285 CPU board Figure 3.9 3.4.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note [PortsClass.AddReg] HKR,,,,%PortsClassName% [ClassInstall32.NT] AddReg=PortsClass.NT.AddReg [PortsClass.NT.AddReg] HKR,,,,%PortsClassName% HKR,,Icon,,"-23" HKR,,Installer32,,"MsPorts.Dll,PortsClassInstaller" [ControlFlags] ExcludeFromSelect=* ;********************************************** ; Please change to your company's VID and PID * ;********************************************** [Models] %USB.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note [Serial_EventLog_AddReg] HKR,,EventMessageFile,0x00020000,"%%SystemRoot%%¥System32¥IoLogMsg.dll;% %SystemRoot%%¥System32¥drivers¥usbser.sys" HKR,,TypesSupported,0x00010001,7 ; COM sections ;---------------------------------------------------------[ComPort.Copy] usbser.sys,,,0x20 [ComPort.AddReg] HKR,,PortSubClass,1,01 [ComPort.NT.Copy] CopyFiles=ComPort.Copy [ComPort.NT.AddReg] HKR,,EnumPropPages32,,"MsPorts.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 3.4.2 PC-PC Communication Settings The table below lists the settings for the terminal software. Table 3.4 Items Terminal Software Settings bps (B) Description Select the number of ports connected to an RS-232C serial cable or a USB cable 115200 bps Data bits (D) Parity (P) Stop bit (S) Flow control(F) 8 None 1 Xon/Xoff Connection REJ05B1152-0100/Rev.1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note 4. References Software Manual SH-1/SH-2/SH-DSP Software Manual Rev. 7.00 Download the latest version from Renesas Technology website. REJ05B1152-0100/Rev.1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note Website and Support Renesas Technology Website http://www.renesas.com/ Inquiries http://renesas.com/inquiry csc@renesas.com Revision History Rev. 1.00 Date 2008.05.13 Page - Description Summary First edition issued All trademarks and registered trademarks are the property of their respective owners. REJ05B1152-0100/Rev.1.
SH7285/SH7286 USB Function Module USB to Serial Conversion Application Note © 2008. Renesas Technology Corp., All rights reserved. REJ05B1152-0100/Rev.1.