RENESAS SH7216

APPLICATION NOTE
SH7216 Group
USB Function Module: USB Mass Storage Class
Introduction
This application note describes how to use the USB function module of the SH7216 and examples of creation of
firmware conforming to USB Mass Storage Class.
The contents of this application note and the software are provided for describing application examples of the USB
function module, but not for ensuring the contents.
Target Device
SH7216
Contents
1.
Preface .............................................................................................................................................. 2
2.
Overview ........................................................................................................................................... 3
3.
Overview of the USB Mass Storage Class (Bulk-Only Transport).................................................... 5
4.
Development Environment.............................................................................................................. 10
5.
Overview of the Sample Program ................................................................................................... 14
6.
Documents for Reference ............................................................................................................... 30
REJ06B0897-0100/Rev.1.00
July 2009
Page 1 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
1.
1.1
Preface
Specifications
This application note describes how to use the USB function module of the SH7216 and examples of creation of
firmware conforming to USB Mass Storage Class.
1.2
Modules Used
• Interrupt controller (INTC)
• Pin function controller (PFC)
• USB function module (USB)
1.3
Applicable Conditions
• MCU
• Operating frequency
SH7216
Internal clock: 200 MHz
Bus clock: 100 MHz
Peripheral clock: 50 MHz
• Integrated development environment
High-performance Embedded Workshop Ver.4.05.00
(from Renesas Technology Corp.)
• C compiler
SuperH RISC engine Family C/C++ Compiler Package Ver.9.02 Release00,
available from Renesas Technology
• Compiler options
Default settings of the High-performance Embedded Workshop
(-cpu=sh2afpu -pic=1 -object="$(CONFIGDIR)¥$(FILELEAF).obj"
-debug -gbr=auto -chgincpath -errorpath -global_volatile=0
-opt_range=all -infinite_loop=0 -del_vacant_loop=0
-struct_alloc=1 -nologo)
1.4
Related Application Note
• SH7216 Group Application Note: USB Function Module: USB HID Class (REJ06B0898)
REJ06B0897-0100/Rev.1.00
July 2009
Page 2 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
2.
Overview
This program performs control transfer, bulk transfer, and processing for Mass Storage Class commands that use the
USB function module (USB).
The features of the USB Function Module contained in the SH7216 are listed below.
• Automatic processing of USB protocol
• Automatic processing of USB standard commands for endpoint 0 (some commands need to be processed through
the firmware)
• Full-speed transfer supported
• Interrupt request: Various interrupt signals needed for USB transmission and reception are generated.
• Clock: External input clock generated by the USB oscillator (48 MHz)
• Low power consumption mode provided.
• Internal USB transceiver
• Endpoint configurations: The configurations are indicated in table 1.
Table 1
Endpoint Configurations
Endpoint Name
Endpoint 0
Endpoint 1
Endpoint 2
Endpoint 3
Endpoint 4
Endpoint 5
Endpoint 6
Endpoint 7
Endpoint 8
Endpoint 9
Name
EP0s
EP0i
EP0o
EP1
EP2
EP3
EP4
EP5
EP6
EP7
EP8
EP9
Transfer Type
Setup
Control In
Control Out
Bulk-in
Bulk-out
Interrupt In
Bulk-in
Bulk-out
Interrupt In
Bulk-in
Bulk-out
Interrupt In
Max. Packet Size
8 bytes
16 bytes
16 bytes
64 bytes
64 bytes
16 bytes
64 bytes
64 bytes
16 bytes
64 bytes
64 bytes
16 bytes
FIFO Buffer Capacity
8 bytes
16 bytes
16 bytes
64 × 2 (128) bytes
64 × 2 (128) bytes
16 bytes
64 × 2 (128) bytes
64 × 2 (128) bytes
16 bytes
64 bytes
64 bytes
16 bytes
DMA Transfer
—
—
—
Possible
Possible
—
Possible
Possible
—
—
—
—
Figure 1 shows an example of a system configuration.
USB cable
Host PC equipped with USB
Windows® 2000, Windows® XP,
Windows® Vista, Mac OS9
SH7216 CPU board
Figure 1 System Configuration Example
REJ06B0897-0100/Rev.1.00
July 2009
Page 3 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
This system is configured of the SH7216 CPU Board made by Renesas Technology Corp. and a PC containing
Windows® 2000/Windows® XP/Windows® Vista or Mac OS9 operating system.
By connecting the host PC and the SH7216 CPU Board through USB, the SDRAM in the SH7216 CPU Board can be
accessed as a RAM disk, enabling data in the SDRAM of the SH7216 CPU Board to be stored in and loaded from the
host PC.
It is also possible to use the USB Mass Storage Class (Bulk-Only Transport) device driver that comes as an accessory
with the operating systems listed above.
This system offers the following features.
1.
2.
3.
4.
The sample program can be used to evaluate the USB module of the SH7216.
The sample program supports USB control transfer and bulk transport.
This system can be debugged with the E10A (USB Emulator).
Additional programs can be created to support interrupt transfer.*
Note: * Interrupt transfer programs are not provided, and will need to be created by the user.
The SH7216 does not support isochronous transfer.
REJ06B0897-0100/Rev.1.00
July 2009
Page 4 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
3.
Overview of the USB Mass Storage Class (Bulk-Only Transport)
This section describes the USB Mass Storage Class (Bulk-Only Transport).
We hope that it will provide a convenient reference for use when developing USB storage-related systems. For more
detailed information on standards, please see (3) and (4) of the section 6 "Documents for Reference".
3.1
USB Mass Storage Class
USB Mass Storage Class is a class of standards that apply to large-scale memory (storage) devices that are connected to
a host PC and handle reading and writing of data.
In order to let the PC know that a function is in this class, a value of H'08 must be entered in the bInterface Class field
of the Interface Descriptor. Furthermore, USB Mass Storage Class must tell the host the serial number using the String
Descriptor. Unicode 000000000001 is returned in this sample program.
When transferring data between the host PC and the function, four transport methods defined by the USB are used
(control transfer, bulk transport, interrupt transfer, and isochronous transfer).
Protocol codes determine the transport method and how it is used.
In USB Mass Storage Class, there are two types of data transport protocols:
⎯ USB Mass Storage Class Bulk-Only Transport
⎯ USB Mass Storage Class Control/Bulk/Interrupt (CBI) Transport
As its name indicates, USB Mass Storage Class Bulk-Only Transport is a data transport protocol that only uses bulk
transport.
USB Mass Storage Class Control/Bulk/Interrupt (CBI) Transport is a data transport protocol that uses control transfer,
bulk transport, and interrupt transfer. CBI Transport is further subdivided into a data transport protocol that uses
interrupt transfer, and one that does not use interrupt transfer.
The sample programs provided here use USB Mass Storage Class Bulk-Only Transport as the data transport protocol.
When the host PC uses a device in order to load and save data, instructions (commands) are provided by the host PC to
the function. The function then executes those commands to load and save data. The commands sent by the host PC to
the function are defined in the form of sub-class code.
3.2
Sub-Class Code
Sub-class codes are values that indicate the command format sent from the host PC to a function by means of command
transport. There are seven types of command formats, described in table 2.
Table 2
Sub-Class Code
Sub-Class Code
H'01
H'02
H'03
H'04
H'05
H'06
Command Standards
Reduced Block Commands (RBC), T10/1240-D
Attachment Packet Interface (ATAPI) for CD-ROMs. SFF-8020i,
Multi-Media Command Set 2 (MMC-2)
Attachment Packet Interface (ATAPI) for Tape. QIC-157
USB Mass Storage Class UFI Command Specification
Attachment Packet Interface (ATAPI) for Floppies. SFF-8070i
SCSI Primary Commands –2 (SPC-2), Revision 3 or later
In order to tell the host PC the command format supported by the device, a sub-class code value must be entered in the
bINterface SubClass field of the Interface Descriptor.
The sample programs used here use a sub-class code value of H'06, which indicates the SCSI Primary Commands.
REJ06B0897-0100/Rev.1.00
July 2009
Page 5 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
3.3
Bulk-Only Transport
With Bulk-Only Transport, data is transferred between the host PC and a function using bulk data transport only.
Bulk transport can be divided into two types, depending on the direction in which the data is sent. If data is sent from
the host controller to the function, bulk-out transport is used. If data is being sent to the host controller from the function,
bulk-in transport is used.
With Bulk-Only Transport, a combination of bulk-out transport and bulk-in transport determined in advance is used to
transfer data between the host and the function. Bulk-Only Transport always uses the combination of bulk transports
shown in figure 2. These bulk transports have different meanings, but they are handled as stages (transports).
Start
Command transport (CBW)
Bulk-out transoprt
Data transport
Bulk-out transoprt
Bulk-in transoprt
Bulk-in transoprt
Status transport (CSW)
End
Figure 2 Relationship between Transfer Methods and Transports
In order to tell the host PC that the Bulk-Only Transport protocol is being used, a value of H'50 must be entered in the
bInterface Protocol field of the Interface Descriptor.
3.3.1
Command Transport
In command transport, commands are sent from the host PC to the function using bulk-out transport. This command
packet is defined as the Command Block Wrapper (CBW), and Bulk-Only Transport must always begin with the CBW.
The CBW is sent from the host PC as a 31-byte packet, using bulk-out transport.
It is sent using the format shown in table 3.
Table 3
Command Transport Formats
7
H'00-H'03
H'04-H'07
H'08-H'0B
H'0C
H'0D
H'0E
H'0F-H'1E
6
5
4
3
dCBWSignature
dCBWTag
dCBWDataTransferLength
bmCBWFlags
Reserved (0)
Reserved (0)
REJ06B0897-0100/Rev.1.00
2
1
0
bCBWLUN
bCBWCBLength
CBWCB
July 2009
Page 6 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
The fields are explained below.
• dCBWSignature:
This field identifies the data packet as a CBW. The value is 43425355h (Little Endian).
• dCBWTag:
This is the command block tag. It is used to connect the CSW with its corresponding CBW, and is specified by the
host PC.
• dCBWDataTransferLength:
This is the length of the data planned for transport. If this is 0, no data transport exists.
• bmCBWFlags:
If bit 7 of this field is 0, data is transported using bulk-out transport, and if it is 1, bulk-in transport is used. Bits 0 to
6 are fixed at 0.
• bCBWLUN:
This is the Logical Unit Number of the device sending the command block.
• bCBWCBLength:
This indicates the number of valid bytes for the next CBWCB field.
• CBWCB:
This field stores the command block to be executed by the function. The command that the host PC wants to execute
(the SCSI command in this sample program) is entered in this field.
3.3.2
Status Transport
Status transport is used to send the results of command execution from the function to the host PC, using bulk-in
transport.
This status packet is defined by the Command Status Wrapper (CSW). Bulk-Only Transport must always end with the
CSW.
The CSW is sent to the host as a 13-byte packet, using bulk-in transport.
It is sent in the format shown in table 4.
Table 4
Status Transport Formats
7
H'00-H'03
H'04-H'07
H'08-H'0B
H'0F-H'1E
6
5
4
3
dCSWSignature
dCSWTag
dCSWDataResidue
bCSWStatus
2
1
0
The fields are explained below.
• dCSWSignature:
This field identifies the data packet as the CSW. The value is H'53425355 (Little Endian).
• dCSWTag:
This is the command block tag. It ties the CBW to the CSW, and the same value is entered here as that of the
dCBWTag field of the CBW.
• dCSWDataResidue:
This reports any differences in the value of the CBW dCBWDataTransferLength and the actual amount of data
processed by the function.
• bCSWStatus:
This indicates whether or not a command has been successfully executed. If the command was executed
successfully, the function sets H'00 in this field.
Any value other than 0 indicates that the command was not executed successfully. Error values are as follows: H'01
indicates a failed command, and H'02 indicates a phase error.
REJ06B0897-0100/Rev.1.00
July 2009
Page 7 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
3.3.3
Data Transport
Data transport is used to transfer data between the host PC and the function. For example, with the Read/Write
command, the actual data of the various storage sectors is sent using data transport.
Data transport is configured of multiple bus transactions.
Data transfers carried out using data transport use either bulk-out or bulk-in transport. The bmCBWFlags field of the
CBW data determines which type of transport is used.
(1) Data transport (bulk-out transport)
This section explains how data is transferred when bulk-out data transport is used.
This status is set if bit 7 of the bmCBWFlags field of the CBW data is 0, and the dCBWDataTransferLength field of
the CBW data is not 0.
Here, the function receives the anticipated length of the data indicated by the dCBWDataTransferLength field of the
CBW data. The data transferred at this point is needed when the SCSI command specified by the CBWCB field of
the CBW data is executed.
(2) Data transport (bulk-in transport)
This section explains how data is transferred when bulk-in data transport is used.
This status is set if bit 7 of the bmCBWFlags field of the CBW data is 1, and the dCBWDataTransferLength field of
the CBW data is not 0.
Here, the anticipated length of the data indicated by the dCBWDataTransferLength field of the CBW data is sent to
the host PC. The data transferred at this point is the result produced when the SCSI command specified by the
CBWCB field of the CBW data was executed.
3.4
Class Commands
Class commands are commands that are defined by the various USB classes. They use control transfer.
When USB Mass Storage Class Bulk-Only Transport is used as the data transport protocol, there are two types of
commands that must be supported. The class commands are indicated in table 5.
Table 5
Class Commands
bRequest Field Value
255 (H'FF)
254 (H'FE)
Command
Bulk-Only Mass Storage Reset
Get Max LUN
Meaning of Command
Resets the interface
Checks the number of LUNs supported
When the Bulk-Only Mass Storage Reset command is received, the function resets all of the interfaces used in USB
Mass Storage Class Bulk-Only Transport.
When the Get Max LUN command is received, the function returns the largest logical unit number that can be used. In
the sample system used here, there is one logic unit, so a value of 0 will be returned to the host.
REJ06B0897-0100/Rev.1.00
July 2009
Page 8 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
3.5
Sub-Class Code (SCSI Transparent Command Set)
The various commands must be processed in response to the sub-class commands in the CBW sent to the function by
the host PC.
In this sample program, the eleven SCSI commands shown in table 6 are supported. If a command is not supported, the
CSW will be used to inform the host PC that the command failed.
Table 6 Supported Commands
Operation Code
H'00
Command Name
TEST UNIT READY
H'03
REQUEST SENSE
H'12
H'1A
H'1B
H'1E
INQUIRY
MODE SENSE (6)
STOP/START UNIT
PREVENT ALLOW MEDIUM REMOVAL
H'23
H'25
H'28
READ FORMAT CAPACITY
READ CAPACITY
READ (10)
H'2A
WRITE (10)
H'2F
VERIFY (10)
REJ06B0897-0100/Rev.1.00
July 2009
Command Operation
Checks whether or not a medium can be
used.
If an error occurred for the previous
command, this tells the host what kind of
error occurred.
Tells the host the drive information.
Tells the host the drive status.
Controls insertion/removal of media.
Inhibits/enables installing and removing
media.
Tells the host the media format information.
Tells the host the media sector information.
Reads the specified sector volume data from
a specified sector.
Writes the specified sector volume data to a
specified sector.
Confirms whether or not the data in a
medium can be accessed.
Page 9 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
4.
Development Environment
This chapter looks at the development environment used to develop this system. The devices (tools) listed below were
used when developing the system.
•
•
•
•
•
•
SH7216 CPU Board (part number: R0K572167) manufactured by Renesas Technology Corp.
E10A-USB Emulator manufactured by Renesas Technology Corp.
E10A PC (Windows® 2000, Windows® XP)
USB host PC (Windows® 2000/Windows® XP/Windows® Vista or Mac OS9)
USB cable
High-performance Embedded Workshop 4 (hereafter called the HEW4) manufactured by Renesas Technology Corp.
4.1
Hardware Environment
Figure 3 shows device connections.
E10A cable
E10A PC
Windows® 2000,
Windows® XP
USB cable
SH7216 CPU board
Host PC equipped with USB
Windows® 2000, Windows® XP,
Windows® Vista, Mac OS9
Figure 3 Device Connections
(1) SH7216 CPU Board
Because this system uses the on-chip ROM and SDRAM, the SH7216 CPU board must be operated in the MCU
expansion mode 2 (both on-chip ROM and SDRAM enabled). Therefore, DIP switch SW1 on the SH7216 CPU
board must be changed from the factory setting to the setting shown in table 7. Before turning on the power, ensure
that the switches are set as follows. There is no need to change any other DIP switches.
Table 7
DIP Switch Settings
At Time of Shipment (Mode 6)
SW1-1 (FWE) OFF
After Change (Mode 2)
SW1-1 (FWE) ON
SW1-2 (MD1) OFF
SW1-3 (MD0) ON
SW1-2 (MD1) OFF
SW1-3 (MD0) ON
DIP Switch Function
On-chip flash memory write/erase
protection
MD1 pin state
MD0 pin state
(2) USB host PC
A PC with Windows® 2000/Windows® XP/Windows® Vista or Mac OS9 installed, and with a USB port, is used
as the USB host. This system uses USB Mass Storage Class (Bulk-Only Transport) device drivers installed as a
standard part of the Windows® XP system, and so there is no need to install new drivers.
(3) E10A PC
A PC with Windows® 2000/Windows® XP installed, and with a USB port, is used as the E10A PC. Connect the
E10A-USB emulator to the USB connector on the E10A-USB PC, and then connect the E10A-USB emulator to the
CPU board with the cable. After connection, start the HEW4 and perform emulation.
REJ06B0897-0100/Rev.1.00
July 2009
Page 10 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
4.2
Software Environment
Compile, link, and debug the source code with HEW4. To start HEW4, double-click "MSC.hws" in this folder.
4.2.1
Sample Program
Files required for the sample program are all stored in the MSC folder. When this entire folder with its contents is
moved to a PC on which HEW4 have been installed, the sample program can be used immediately. Files included in the
folder are indicated in figure 4 below.
C_Source (folder)
DoBOT MSCClass.c
DoBulk.c
DoControl.c
DoRequest.c
DoSCSICommand.c
UsbMain.c
DoRequestBOT_StorangeClass.c
Startup.c
CatBOTTypedef.h
CatProType.h
CatSCSITypedef.h
CatTypedef.h
SetBOTInfo.h
SetMacro.h
SetSCSIInfo.h
SetSystemSwitch.h
iodef.ine.h
SetUsbInfo.h
SysMemMap.h
sct.src
MSClass (folder)
MSC.Hbp
MSC.hws
MSC.tws
Figure 4 Files Included in the Folder
4.2.2
Compiling and Linking
Compile the source code with HEW4.
REJ06B0897-0100/Rev.1.00
July 2009
Page 11 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
4.3
Loading and Executing the Program
Allocation of programs to respective areas is specified by "lnkSet.sub" in the sh7216_usb_msc folder. The allocation
result is output to "MSClass.map" in the sh7216_usb_msc \MSClass\Debug folder. When changing the layout of the
programs, change "lnkSet.sub".
4.3.1
Loading the Program
In order to load the sample program into the SDRAM of the SH7216 CPU Board, the following procedure is used.
•
•
•
•
•
•
•
•
•
•
Connect the E10A-USB to the E10A-USB PC with HEW4 installed.
Connect the E10A-USB to the SH7216 CPU board with the user cable.
Turn on the power to the SH7216 CPU Board.
Execute "MSC.hws" in the sh7216_usb_msc folder.
Select "Debug > Connection."
You are asked to select a mode of the emulator. Select "SH7216(R5F72167A)" or "E10A-USB Emulator."
Press the reset switch on the SH7216 CPU board, and then click on the OK button.
You are asked to enter an operating frequency. Enter the frequency (12.50 MHz) of the mounted crystal oscillator.
You are asked to enter an ID code. Enter E10A.
Select "Debug > Download > All Download Modules" to download the sample program.
4.3.2
Executing the Program
Select "Debug > Execute after Reset" to execute the sample program.
4.4
Using the RAM Disk
The following describes an example in which Windows® XP is used.
After the program has been run, the Series B connector of the USB cable is inserted into the SH7216 CPU Board, and
the Series A connector on the opposite side is connected to the USB host PC.
After the emulation used for control transfer and bulk transport has ended, USB Large-Size Storage Device is displayed
under USB Controller in the Device Manager, and RENESAS EX RAM Disk USB Device is displayed under Disk
Drive. As a result, the host PC recognizes the SH7216 CPU Board as the storage device, and the local disk is mounted
in the microcomputer.
Next, the local disk needs to be formatted.
Select Local Disk and click with the right button of the mouse to display a floating menu. Select Format. A format
selection window for the drive is displayed. Enter the necessary format settings. Check to make sure FAT has been
selected for the file system, and click on the Start button.
A format confirmation window is displayed. Click on the OK button.
When the formatting has been completed, a message window is displayed. Click on the OK button.
The screen returns to the drive format selection window. Click on the Close button to exit the procedure.
The SH7216 CPU Board can now be used as the RAM disk for USB connection.
REJ06B0897-0100/Rev.1.00
July 2009
Page 12 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
4.5
Changing RAM Disk Settings
This section describes how to change the settings of the RAM disk used in this sample program.
4.5.1
Removable/Hard Disk
The RAM disk is used as a removable disk in this sample program.
The RAM disk can be used as a hard disk by commenting out "#define REMOVABLE_DISK" in "SetSystemSwitch.h"
and enabling comment "#undef REMOVABLE_DISK."
4.5.2
Changing the RAM Disk Capacity
This sample program uses 16-Mbyte capacity of the SDRAM as a RAM disk. To change the RAM disk capacity,
change the content of "SysMemMap.h." Specify the entire byte count *1 to be used as a RAM disk by
DISK_ALL_BYTE. Then specify the start address and end address of the area to be used as a RAM disk by
RAM_DISK _S and RAM_ DISK _E *2, respectively.
Notes: 1. Specify a value of 1.5 Mbytes or more. The capacity viewed from the PC is slightly reduced because the
FAT information and other information use the capacity. This sample program configures the FAT
information with FAT12 (up to approx. 16 Mbytes) and FAT16 (up to approx. 2 Gbytes). Other FAT system
information need to be prepared by the user.
2. The area specified by RAM_ DISK _S and RAM_ DISK _E must be equal to or larger than the size
specified by DISK_ALL_BYTE.
REJ06B0897-0100/Rev.1.00
July 2009
Page 13 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
5.
Overview of the Sample Program
In this section, features of the sample program and its structure are explained. This sample program runs on the SH7216
CPU Board, which works as a RAM disk, and initiates USB transfers by means of interrupts from the USB function
module. Of the interrupts from modules in the SH7216, there are six interrupts related to the USB function module:
USI0, USI1, USBRXI0, USBTXI0, USBRXI1 and USBTXI1, but in this sample program, USI0 and USI1 are used.
5.1
State Transition Diagram
Figure 5 shows a state transition diagram for this sample program. In this sample program, as shown in figure 5, there
are transitions between three states.
Immediately after the power supply has been turned on,
the system is in reset state. After the initial settings have been
completed, it returns to the stationary state.
Reset state
Interrupt generated
(USBFI0)
Initial settings completed
USB communication state
Stationary state
Control transfer
Bulk transport
USB communication
completed
Figure 5 State Transition Diagram
• Reset state
Upon power-on reset and manual reset, this state is entered. In the reset state, the SH7216 mainly performs initial
settings.
• Stationary state
When initial settings are completed, a stationary state is entered in the main loop.
• USB communication state
In the stationary state, when an interrupt from the USB module occurs, this state is entered. In the USB
communication state, data transfer is performed by a transfer method according to the type of interrupt. The
interrupts used in this sample program are indicated by interrupt flag register 0, 1, 2, 3 and 4 (USBIFR0, 1, 2, 3 and
4). When an interrupt factor occurs, the corresponding bits in USBIFR0, 1, 2, 3 and 4 are set.
REJ06B0897-0100/Rev.1.00
July 2009
Page 14 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
5.2
USB Communication State
The USB communication state can be further divided into three states according to the transfer type (see figure 6).
When an interrupt occurs, first there is a transition to the USB communication state, and then there is further branching
to a transfer state according to the interrupt type.
USB communication state
Control transfer
Bulk transport
Ready
Ready
Setup stage
Command
transport (CBW)
Data stage
OUT direction
Data stage
IN direction
Data out
Status stage
Data in
Status transport (CSW)
Figure 6 USB Communication State
5.2.1
Control Transfer
Control transfer is used mainly for functions such as obtaining device information and specifying device operating
states. For this reason, when the function is connected to the host PC, control transfer is the first transport to be carried
out.
Transport processing for control transfer is carried out in a series of two or three stages. These stages are a setup stage, a
data stage, and a status stage.
5.2.2
Bulk Transport
Bulk transport has no time limitations, so it is used to send large volumes of data with no errors. The data transport
speed is not guaranteed, but the data contents are guaranteed. With USB Mass Storage Class (Bulk-Only Transport),
bulk transport is used to transfer storage data between the host PC and the function.
Transport processing for USB Mass Storage Class (Bulk-Only Transport) is carried out in a series of two or three stages.
These stages are command transport (CBW), data transport, and status transport (CSW).
REJ06B0897-0100/Rev.1.00
July 2009
Page 15 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
5.3
File Structure
This sample program consists of nine source files and eleven header files. The overall file structure is shown in table 8.
Each function is arranged in one file by transfer method or function type.
Table 8
File Structure
File Name
Startup.c
UsbMain.c
DoRequest.c
DoRequestBOT_StorageClass.c
DoControl.c
DoBulk.c
DoBOTMSClass.c
DoSCSICommand.c
sct.src
CatBOTTypedef.h
CatProType.h
CatSCSITypedef.h
CatTypedef.h
SetBOTInfo.h
SetMacro.h
SetSCSIInfo.h
SetSystemSwitch.h
SetUsbInfo.h
SysMemMap.h
iodefine.h
5.4
Principle Role
USB function default settings
Judging the causes of interrupts
Sending and receiving packets
Processing setup commands issued by the host
Processing USB Mass Storage Class (Bulk-Only Transport) class
commands
Executing control transfer
Executing bulk transport
Executing USB Mass Storage Class (Bulk-Only Transport) transport
Analyzing and processing SCSI commands
Transferring initial values of variables from the ROM to the RAM
Defining structures used for Bulk-Only Transport
Prototype declarations
Defining structures used for SCSI, and defining macro to configure FAT
information
Defining the basic structures used in USB firmware
Default settings of variables needed to support Bulk-Only Transport
Defining macros
Default settings of variables needed to support SCSI commands
System operation settings
Default settings of variables used in USB firmware
Defining memory map addresses
Defining SH7216 registers
Purposes of Functions
Table 9 to 16 shows functions contained in each file and their purposes.
• Startup.c
When a power-on reset or manual reset is carried out, the SetPowerOnSection of the Startup.c file is called. At this
point, the SH7216 default settings are entered and the RAM area used for bulk transport is cleared.
Table 9
Startup.c
File in which
Stored
Startup.c
Function Name
SetPowerOnSection
InitSDRAM
_INITSCT
InitMemory
InitSystem
Set_EPInfoR
REJ06B0897-0100/Rev.1.00
Purpose
Initializes module and memory, and shifts to the main loop
Makes initial settings for the SDRAM mounted on the SH7216 CPU
board
Copies variables that have default settings to the RAM work area
Clears the RAM area used in bulk communication
Pull-up control of the USB bus
Writes endpoint information
July 2009
Page 16 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
• UsbMain.c
In UsbMain.c, interrupt factors are discriminated by the USB interrupt flag register, and functions are called
according to the interrupt type. Also, packets are sent and received between the host controller and function modules.
Table 10 UsbMain.c
File in which
Stored
UsbMain.c
Function Name
BranchOfInt0
BranchOfInt1
GetPacket
GetPacket4
GetPacket4S
PutPacket
PutPacket4
PutPacket4S
SetControlOutContents
SetUsbModule
ActBusReset
ActBusVcc
ConvRealn
ConvReflexn
Purpose
Performs a bus reset, determines endpoint0 interrupt source,
and calls a function corresponding to the interrupt
Determines endpoint1 to endpoint9 interrupt sources, and calls
a function corresponding to each interrupt
Writes data transferred from the host controller to RAM
Writes data transferred from the host controller to RAM in
longwords (ring buffer supported) (not used by this sample
program)
Writes data transferred from the host controller to RAM in
longwords (ring buffer not supported, high-speed version)
Writes data for transfer to the host controller to the USB module
Writes data for transfer to the host controller to the USB module
in longwords (ring buffer supported) (not used by this sample
program)
Writes data for transfer to the host controller to the USB module
in longwords (ring buffer not supported, high-speed version)
Overwrites data with that sent from the host
Makes USB module initial settings
Clears FIFO on receiving bus reset
Generates a USB cable connection interrupt (not used by this
sample program)
Reads data of a specified byte length from a specified address
Reads data of a specified byte length from specified addresses,
in reverse order
• DoRequest.c
During control transfer, commands sent from the host controller are decoded and processed. In this sample program,
a vendor ID of H'045B (vendor: Renesas) is used. When the customer develops a product, the customer should
obtain a vendor ID at the USB Implementers' Forum. Because vendor commands are not used,
DecVenderCommands does not perform any action. In order to use a vendor command, the customer should
develop a program.
Table 11 DoRequest.c
File in which
Stored
DoRequest.c
Function Name
DecStandardCommands
DecVenderCommands
REJ06B0897-0100/Rev.1.00
Purpose
Decodes command issued by host controller, and processes
standard commands
Processes vendor commands
July 2009
Page 17 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
• DoRequestBOT_StorageClass.c
This function carries out processing according to the USB Mass Storage Class (Bulk-Only Transport) commands
(Bulk-Only Mass Storage Reset and Get Max LUN).
The Bulk-Only Mass Storage Reset command resets all of the interfaces used in Bulk-Only Transport.
The Get Max LUN command returns the largest logical unit number used by peripheral devices. In this sample
program, there is one logical unit, so a value of 0 is returned to the host.
Table 12 DoRequestBOT_StorageClass.c
File in which
Stored
DoRequestBOT_
StorageClass.c
Function Name
DecBOTClassCommands
Purpose
Processes USB Mass Storage Class (Bulk-Only Transport)
commands
• DoControl.c
When control transfer interrupt SETUP TS is generated, ActControl obtains the command, and decoding is carried
out by DecStandardCommands to determine the transfer direction. Next, when control transfer interrupt EP0o TS,
EP0i TR, or EP0i TS is generated, ActControlInOut calls either ActControlIn or ActControlOut depending on the
transfer direction, and the data stage and status stage are carried out by the called function.
Table 13 DoControl.c
File in which
Stored
DoControl.c
Function Name
ActControl
ActControlIn
ActControlOut
ActControlInOut
Purpose
Controls the setup stage of control transfer
Controls the data stage and status stage of control IN
transport (transport in which the data stage is in the IN
direction)
Controls the data stage and status stage of control OUT
transport (transport in which the data stage is in the OUT
direction)
Sorts the data stage and status stage of control transfers
and direct them to ActControlIn and ActControlOut.
• DoBulk.c
These functions carry out processing involving bulk transport. ActBulkInReady is not used in USB Mass Storage
Class (Bulk-Only Transport).
Table 14 DoBulk.c
File in which
Stored
DoBulk.c
Function Name
ActBulkOut
ActBulkIn
ActBulkInReady
REJ06B0897-0100/Rev.1.00
Purpose
Performs bulk-out transfer
Performs bulk-in transfer
Performs preparations for bulk-in transfer
July 2009
Page 18 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
• DoBOTMSClass.c
With DoBOTMSClass.c, control of the two or three stages of the USB Mass Storage Class (Bulk-Only Transport) is
carried out, and operation is carried out in accordance with the specifications.
Table 15 DoBOTMSClass.c
File in which
Stored
DoBOTMSClass.c
Function Name
ActBulkOnly
ActBulkOnlyCommand
ActBulkOnlyIn
ActBulkOnlyOut
Purpose
Divides Bulk-Only Transport into separate stages
Controls CBW for Bulk-Only Transport
Controls data transport and status transport (when the data
stage is in the IN direction)
Controls data transport and status transport (when the data
stage is in the OUT direction)
• DoSCSICommand.c
The DoSCSICommand.c function is used to analyze SCSI commands sent from the host PC and prepare for the next
data transport or status transport.
Table 16 DoSCSICommand.c
File in which
Stored
DoSCSICommand.c
Function Name
DecBotCmd
SetBotCmdErr
5.5
Purpose
Processes SCSI commands sent from the host using BulkOnly Transport
Processes SCSI command errors
RAM Disk
In the sample program provided here, the SD-RAM in the SH7216 CPU Board is selected as the disk device, and the
host PC is notified that the SH7216 CPU Board (function) is the disk.
As shown in figure 7, the disk device of the function has a master boot block and a partition boot block. When the
system is booted, an initialization routine is used to write the master boot block and the partition boot block to the RAM
disk area on the SDRAM.
Sector 0
Master boot block
Sector 20
Partition boot block
Figure 7 Disk Construction
SCSI commands are used to allow function access from the host PC (saving and loading data). In order to work with
SCSI commands, the user needs to understand the construction shown in figure 7 and then write the operation.
REJ06B0897-0100/Rev.1.00
July 2009
Page 19 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
5.6
Operation of SCSI Commands That Are Supported
Table 17 shows the SCSI commands that are supported by the sample program.
Table 17 SCSI Command Operations
Command Name
INQUIRY
Transport
Name
CBW
Data
CSW
READ CAPACITY
CBW
Data
CSW
READ (10)
CBW
Data
CSW
REJ06B0897-0100/Rev.1.00
Operation Content
This decodes a command and recognizes it as an INQUIRY
command. It then prepares to send the INQUIRY information
(96 bytes) stored in the ROM.
This sends the INQUIRY information to the host PC using
bulk-in transport.
This sends the results of executing a command to the PC. If
the data being sent is 96 bytes or less, the transmission will
end successfully.
This decodes a command and recognizes it as a READ
CAPACITY command. It then prepares to send the 8-byte
READ CAPACITY information (consisting of byte count per
sector and total sector count) of the disk on the SDRAM. If
media access is disabled (LSB of unit_state[0] is 1), the
function treats this as no data transfer and follows (4) in
section 5.7, Processing If an Error Occurs. It also sets a value
to be returned in REQUEST SENSE for NOT READY (not
prepared).
This sends the READ CAPACITY information to the host PC
using bulk-in transport.
If media access is disabled, it returns data as much as data
requested by the host (H'00).
This sends the results of the command execution to the host
PC.
If media access is disabled, it returns a command fail (CSW
status H'01).
This decodes the command and recognizes it as the READ
(10) command. It then prepares to send the data for a
specified read sector volume from the Disk device open on
the SDRAM.
If media access is disabled (LSB of unit_state[0] is 1), the
function treats this as no data transfer and follows (4) in
section 5.7, Processing If an Error Occurs. It also sets a value
to be returned in REQUEST SENSE for NOT READY (not
prepared).
This sends the data from the read sectors to the host PC
using bulk-in transport.
If media access is disabled, it returns data as much as data
requested by the host (H'00).
This sends the results of executing the READ (10) command
to the host PC.
If media access is disabled, it returns a command fail (CSW
status H'01).
July 2009
Page 20 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
Command Name
WRITE (10)
Transport
Name
CBW
Data
CSW
REQUEST SENSE
CBW
Data
CSW
PREVENT ALLOW
MEDIUM REMOVAL
CBW
Data
CSW
TEST UNIT READY
CBW
Data
CSW
REJ06B0897-0100/Rev.1.00
Operation Content
This decodes the command and recognizes it as the WRITE
(10) command. It then prepares to receive the data of the
specified sector volume from the specified write sector in the
Disk device open on the SDRAM.
If media access is disabled (LSB of unit_state[0] is 1), the
function treats this as no data transfer and follows (9) in
section 5.7, Processing If an Error Occurs. It also sets a value
to be returned in REQUEST SENSE for NOT READY (not
prepared).
This receives the write sector data from the host PC using
bulk-out transport.
If media access is disabled, it reads and discards data from
the host.
This notifies the host PC that the operation has been
completed successfully.
If media access is disabled, it returns a command fail (CSW
status H'01).
This decodes the command and recognizes it as the
REQUEST SENSE command. It then prepares to send the
returned value (the results of executing the previous SCSI
command).
This sends the returned value to the host PC using bulk-in
transport.
This sends the results of the command execution to the host
PC. The transmission is completed successfully as long as
the data consists of 18 bytes or less.
This decodes the command and recognizes it as the
PREVENT ALLOW MEDIUM REMOVAL command. It then
prepares to notify the host PC that the operation has been
successfully completed.
If media access is disabled (LSB of unit_state[0] is 1), it sets
the command to "fail" and also sets a value to be returned in
REQUEST SENSE for NOT READY (not prepared).
Data transport does not exist for this command.
This notifies the host PC that the operation has been
completed successfully.
If media access is disabled, it returns a command fail (CSW
status H'01).
This decodes the command and recognizes it as the TEST
UNIT READY command. It then prepares to notify the host
PC that the operation has been successfully completed.
If media access is disabled (LSB of unit_state[0] is 1), it sets
the command to "fail" and also sets a value to be returned in
REQUEST SENSE for NOT READY (not prepared).
Data transport does not exist for this command.
This notifies the host PC that the operation has been
completed successfully.
If media access is disabled, it returns a command fail (CSW
status H'01).
July 2009
Page 21 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
Command Name
VERIFY (10)
Transport
Name
CBW
Data
CSW
STOP/START UNIT
CBW
Data
CSW
MODE SENSE (6)
CBW
Data
CSW
READ FORMAT
CAPACITY
CBW
Data
CSW
REJ06B0897-0100/Rev.1.00
Operation Content
This decodes the command and recognizes it as the VERIFY
(10) command. It then prepares to notify the host PC that the
operation has been successfully completed.
If media access is disabled (LSB of unit_state[0] is 1), it sets
the command to "fail" and also sets a value to be returned in
REQUEST SENSE for NOT READY (not prepared).
Data transport does not exist for this command.
This notifies the host PC that the operation has been
completed successfully.
If media access is disabled, it returns a command fail (CSW
status H'01).
This decodes a command and recognizes it as a
STOP/START UNIT command. It then sets the LSB of global
variable unit_state[0] to 1 when the command specifies media
ejection or stop, or clears the LSB of global variable
unit_state[0] to 0 in other cases.
When the user wants recovery from the inaccessible state,
clear the LSB of unit_state[0] to 0.
Data transport does not exist for this command.
This notifies the host PC that the operation has been
completed successfully.
This decodes a command and recognizes it as a MODE
SENSE (6) command. It then prepares to send the requested
MODE SENSE information.
This sends the MODE SENSE information to the host PC
using bulk-in transport.
This sends the results of the command execution to the host
PC.
This decodes a command and recognizes it as a READ
FORMAT CAPACITY command. Regarding that the disk on
the SDRAM has been formatted, it then prepares to send the
20-byte READ FORMAT CAPACITY information (consisting
of byte count per sector and total sector count of the disk). If
media access is disabled (LSB of unit_state[0] is 1), the
function treats this as no data transfer and follows (4) in
section 5.7, Processing If an Error Occurs. It also sets a value
to be returned in REQUEST SENSE for NOT READY (not
prepared).
This sends the READ FORMAT CAPACITY information to the
host PC using bulk-in transport.
If media access is disabled, it returns data as much as data
requested by the host (H'00).
This sends the results of the command execution to the host
PC. If media access is disabled, it returns a command fail
(CSW status H'01).
July 2009
Page 22 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
Command Name
Commands that
are not supported
Transport
Name
CBW
Data
CSW
REJ06B0897-0100/Rev.1.00
Operation Content
This decodes the command and, if it is an unsupported
command, specifies INVALID FIELD IN CDB for the returned
value of the REQUEST SENSE command. It then prepares to
transport the data.
If the host PC has requested data using bulk-in transport, this
sends the same volume of data (H'00) as that requested by
the host PC.
If the host PC has sent data using bulk-out transport, the
number of bytes received are counted.
If there is no data transport, no operation is carried out.
This sends a command fail (CSW status H'01) to the host PC.
July 2009
Page 23 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
5.7
Processing If an Error Occurs
The errors that may occur during a USB Mass Storage Class (Bulk-Only Transport) transmission between the host PC
and function, and how the function operates when an error occurs are described below.
The Bulk-Only Transport standard defines the following two types of errors:
⎯ Invalid CBW
⎯ Operation expected by the host PC and operation planned by the function (operation specified by the SCSI
command) do not match (10 cases)
The Bulk-Only Transport standard does not cover any other states.
There are 13 states for data transfer between the host PC and a function as shown in tables 18 and 19. Cases (1), (6) and
(12) are normal transport states.
Table 18 Data Transport States between Host PC and Function
What the
function plans
No data transport
Data send to host PC
Data reception from host PC
What the Host PC Expects
No Data
Data Reception
Transport
from Function
(1) Hn = Dn
(4) Hi > Dn
(2) Hn < Di
(5) Hi > Di
(6) Hi = Di
(7) Hi < Di
(3) Hn < Do
(8) Hi < > Do
Data Send
to Function
(9) Ho > Dn
(10) Ho < > Di
(11) Ho > Do
(12) Ho = Do
(13) Ho < Do
Table 19 Explanation of Data Transport States between Host PC and Function
Case No.
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
Relation between Host PC and Function
The host PC expects no data transport and the function plans no data transport.
The host PC expects no data transport but the function plans to send data to the host PC.
The host PC expects no data transport but the function plans to receive data from the host PC.
The host PC expects to receive data from the function but the function plans no data transport
to the host PC.
The amount of data the function sends to the host PC is less than the amount of data the host
PC expected to receive from the function.
The amount of data the function sends to the host PC is equal to the amount of data the host
PC expected to receive from the function.
The amount of data the function sends to the host PC is greater than the amount of data the
host PC expected to receive from the function.
The host PC expects to receive data from the function but the function plans to receive data
from the host PC.
The host PC expects to send data to the function but the function plans no data transport to the
host PC.
The host PC expects to send data to the function but the function plans to send data to the host
PC.
The amount of data the function receives from the host PC is less than the amount of data the
host PC expected to send to the function.
The amount of data the function receives from the host PC is equal to the amount of data the
host PC expected to the function.
The amount of data the function receives from the host PC is greater than the amount of data
the host PC expected to send to the function.
REJ06B0897-0100/Rev.1.00
July 2009
Page 24 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
Table 20 shows sample error conditions that may be generated.
Table 20 Sample Error Conditions
Case No.
(2)
(3)
(4)
(5)
(7)
(8)
(9)
(10)
(11)
(13)
Error Conditions
When a READ command is issued from the host PC, the amount of data to be transported in
the USB data transport is 0 while the amount of data specified by the SCSI command is a value
other than 0.
When a WRITE command is issued from the host PC, the amount of data to be transported in
the USB data transport is 0 while the amount of data specified by the SCSI command is a value
other than 0.
When a READ command is issued from the host PC, the amount of data to be transported in
the USB data transport is 0 while the amount of data specified by the SCSI command is 0.
When a READ command is issued from the host PC, the amount of data specified by the SCSI
command is less than the amount of data to be transported in the USB data transport.
When a READ command is issued from the host PC, the amount of data specified by the SCSI
command is greater than the amount of data to be transported in the USB data transport.
Even though a WRITE command has been issued from the host PC, the host PC requests for
data in the USB data transport.
When a WRITE command is issued from the host PC, the amount of data to be transported in
the USB data transport is a value other than 0 while the amount of data specified by the SCSI
command is 0.
Even though a READ command has been issued from the host PC, the host PC sends data in
the USB data transport.
When a WRITE command is issued from the host PC, the amount of data specified by the SCSI
command is less than the amount of data to be transported in the USB data transport.
When a WRITE command is issued from the host PC, the amount of data specified by the SCSI
command is greater than the amount of data to be transported in the USB data transport.
Table 21 shows how a function operates when each error condition occurs.
Table 21 Function Operation for Each Error Condition
Case No.
(2), (3)
(4), (5)
(7), (8)
(9), (11)
(10), (13)
Relation between Host PC and Function
• Set H'02 as the CSW status.
• The function adds data to become equal to the data length set in dCBWDataTransferLength
and then sends data to the host PC.
• Set the amount of data added in the data transport in dCBWDataResidue of CSW.
• Set H'00 as the CSW status.
• The function sends data to the host PC up to the data length set in
dCBWDataTransferLength.
• Set H'02 as the CSW status.
• The function receives data from the host PC up to the data length set in
dCBWDataTransferLength.
• Set the difference between the amount of data received in the data transport and the
amount of data processed by the function in dCBWDataResidue of CSW.
• Set H'01 as the CSW status.
• The function receives data from the host PC up to the data length set in
dCBWDataTransferLength.
• Set H'02 as the CSW status.
REJ06B0897-0100/Rev.1.00
July 2009
Page 25 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
Figures 8 to 10 show the processing when a data transport error occurs.
Start
CBW is received
Is CBW data valid?
Command
transport
NO
YES
Amount of data planned by
host=0 while
Amount of data planned by
function !=0
EP2 is stalled
YES
CASE: (2) (3)
NO
H'02 is set in
bCSWStatus
Data transport direction is
judged from CBW
Bulk-out
Bulk-in
Bulk-in operation in
data transport
Bulk-out operation in
data transport
Data
transport
CSW is sent
Status
transport
End
Figure 8 Error Processing Flow in Data Transport (1)
REJ06B0897-0100/Rev.1.00
July 2009
Page 26 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
Bulk-in operation
in data transport
Amount of data planned b host
=
Amount of data planned by function
NO
YES
Data us sent in
data transport
Amount of data planned b host
>
Amount of data planned by function
NO
YES
CASE: (6)
Set H'00 in
bCSWStatus
0 is added until data is equal to
the data length required by
the host and then data is output
Data is sent until the
amount of data planned
by the host has been sent
Set the additional
amount of data in
dCSWDataResidue
Set the amount of data
not yet sent in
dCSWDataResidue
CASE: (4) (5)
CASE: (7) (8)
Set H'00 in
bCSWStatus
Set H'02 in
bCSWStatus
Status transport operation
Figure 9 Error Processing Flow in Data Transport (2)
REJ06B0897-0100/Rev.1.00
July 2009
Page 27 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
Bulk-out operation
in data transport
Does the command to be executed
by the function match the transport
direction in data transport?
NO
YES
Amount of data planned by host
=
Amount of data planned by function
NO
YES
Data is received in
data transport
Amount of data planned by host
>
Amount of data planned by function
NO
YES
CASE: (1) (12)
Set H'00 in
bCSWStatus
Data is received in
data transport
Data is received until the
amount of data planned by
the host has been received
Set the overflowed
amount of data in
bCSWDataResidue
Set the amount of data
not yet sent in
bCSWDataResidue
CASE: (9) (11)
Set H'01 in
bCSWStatus
CASE: (13)
Set H'02 in
bCSWStatus
Dummy read is performed
for the amount of data
planned by the host
CASE: (10)
Set H'02 in
bCSWStatus
Status transport
operation
Figure 10 Error Processing Flow in Data Transport (3)
REJ06B0897-0100/Rev.1.00
July 2009
Page 28 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
When a USB Mass Storage Class (Bulk-Only Transport) transmission is carried out, transport of the CBW initiates a
series of data transfers, and when the CSW is transported to the host PC, a series of data transfers is processed. This
status contains two items: dCSWStatus that indicates the transport result, and dCSWDataResidue that indicates the
number of error bytes.
In this sample program, the following two fields are used to create these two items.
⎯ dCBWDataTransferLength field of CBW packet
⎯ dCSWDataTransferResidue field of CSW packet
The dCBWDataTransferLength field of the CBW packet is used as the variable in which the number of data bytes the
host PC specifies to be handled in the data transport is entered.
The dCSWDataTrasferResidue field of the CSW packet is used as the variable in which the number of data bytes the
function handles in the data transport is entered.
When the CBW transport has been completed, the number of data bytes planned to be handled in the data transport by
the host PC and the function are stored in the dCBWDataTransferLength and dCSWDataTransferResidue fields,
respectively.
Data is transferred in the data transport according to the flowcharts.
If data transport between the host PC and function has been processed without errors, the values in the
dCBWDataTransferLength and dCSWDataTransferResidue fields are both subtracted by the number of bytes that have
been transferred for every data transfer in the data transport. For other cases, the difference between the number of data
bytes the host PC requires to be handled in the data transport and the number of data bytes the function has handled in
the data transport is stored in the dCSWDataTransferResidue field of the CSW packet, and operation then moves to the
status transport.
Command
transport
CBW
dCBWDataTransferLength
dCSWDataResidue
dCBWDataTransferLength
dCSWDataResidue
dCBWDataTransferLength
dCSWDataResidue
Data
transport
IN/OUT
IN/OUT
Status
transport
…
IN/OUT
CSW
0 is returned because it is
equal to the amount of
data planned by the host
Amount of data planned by the host
Amount of data planned by the device
The amount of data
insufficient for that planned
by the host is returned
Amount of data planned by the host
Amount of data planned by the device
Insufficient
The amount of data
exceeding that planned
by the host is returned
Amount of data planned by the host
Amount of data planned by the device
Exceeding
Figure 11 Each Stage in Bulk-Only Transport
REJ06B0897-0100/Rev.1.00
July 2009
Page 29 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
6.
Documents for Reference
• Software Manual
(1) SH-2A, SH2A-FPU Software Manual (REJ09B0051)
The most up-to-date version of this document is available on the Renesas Technology Website.
• Hardware Manual
(2) SH7216 Group Hardware Manual (REJ09B0543)
The most up-to-date version of this document is available on the Renesas Technology Website.
• USB standard-related
(3) Universal Serial Bus Specification
(4) Universal Serial Bus Mass Storage Class Specification Overview
(5) Universal Serial Bus Mass Storage Class (Bulk-Only Transport)
⎯ Website for USB developers
http://www.usb.org/developers
REJ06B0897-0100/Rev.1.00
July 2009
Page 30 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
Website and Support
Renesas Technology Website
http://www.renesas.com/
Inquiries
http://www.renesas.com/inquiry
[email protected]
Revision Record
Rev.
1.00
Date
Jul.15.09
Description
Page
Summary
—
First edition issued
All trademarks and registered trademarks are the property of their respective owners.
REJ06B0897-0100/Rev.1.00
July 2009
Page 31 of 32
SH7216 Group
USB Function Module: USB Mass Storage Class
Notes regarding these materials
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
This document is provided for reference purposes only so that Renesas customers may select the appropriate
Renesas products for their use. Renesas neither makes warranties or representations with respect to the
accuracy or completeness of the information contained in this document nor grants any license to any intellectual
property rights or any other rights of Renesas or any third party with respect to the information in this document.
Renesas shall have no liability for damages or infringement of any intellectual property or other rights arising out
of the use of any information in this document, including, but not limited to, product data, diagrams, charts,
programs, algorithms, and application circuit examples.
You should not use the products or the technology described in this document for the purpose of military
applications such as the development of weapons of mass destruction or for the purpose of any other military
use. When exporting the products or technology described herein, you should follow the applicable export
control laws and regulations, and procedures required by such laws and regulations.
All information included in this document such as product data, diagrams, charts, programs, algorithms, and
application circuit examples, 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 products listed in this
document, please confirm the latest product information with a Renesas sales office. Also, please pay regular
and careful attention to additional and different information to be disclosed by Renesas such as that disclosed
through our website. (http://www.renesas.com)
Renesas has used reasonable care in compiling the information included in this document, but Renesas
assumes no liability whatsoever for any damages incurred as a result of errors or omissions in the information
included in this document.
When using or otherwise relying on the information in this document, you should evaluate the information in light
of the total system before deciding about the applicability of such information to the intended application.
Renesas makes no representations, warranties or guaranties regarding the suitability of its products for any
particular application and specifically disclaims any liability arising out of the application and use of the
information in this document or Renesas products.
With the exception of products specified by Renesas as suitable for automobile applications, Renesas products
are not designed, manufactured or tested for applications or otherwise in systems the failure or malfunction of
which may cause a direct threat to human life or create a risk of human injury or which require especially high
quality and reliability such as safety systems, or equipment or systems for transportation and traffic, healthcare,
combustion control, aerospace and aeronautics, nuclear power, or undersea communication transmission. If you
are considering the use of our products for such purposes, please contact a Renesas sales office beforehand.
Renesas shall have no liability for damages arising out of the uses set forth above.
Notwithstanding the preceding paragraph, you should not use Renesas products for the purposes listed below:
(1) artificial life support devices or systems
(2) surgical implantations
(3) healthcare intervention (e.g., excision, administration of medication, etc.)
(4) any other purposes that pose a direct threat to human life
Renesas shall have no liability for damages arising out of the uses set forth in the above and purchasers who
elect to use Renesas products in any of the foregoing applications shall indemnify and hold harmless Renesas
Technology Corp., its affiliated companies and their officers, directors, and employees against any and all
damages arising out of such applications.
You should use the products described herein within the range specified by Renesas, especially with respect to
the maximum rating, operating supply voltage range, movement power voltage range, heat radiation
characteristics, installation and other product characteristics. Renesas shall have no liability for malfunctions or
damages arising out of the use of Renesas products beyond such specified ranges.
Although Renesas endeavors to improve the quality and reliability of its products, IC products have specific
characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use conditions.
Please be sure to implement safety measures to guard against the possibility of physical injury, and injury or
damage caused by fire in the event of the failure of a Renesas 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 applicable measures. Among others, since the evaluation of microcomputer
software alone is very difficult, please evaluate the safety of the final products or system manufactured by you.
In case Renesas products listed in this document are detached from the products to which the Renesas products
are attached or affixed, the risk of accident such as swallowing by infants and small children is very high. You
should implement safety measures so that Renesas products may not be easily detached from your products.
Renesas shall have no liability for damages arising out of such detachment.
This document may not be reproduced or duplicated, in any form, in whole or in part, without prior written
approval from Renesas.
Please contact a Renesas sales office if you have any questions regarding the information contained in this
document, Renesas semiconductor products, or if you have any other inquiries.
© 2009. Renesas Technology Corp., All rights reserved.
REJ06B0897-0100/Rev.1.00
July 2009
Page 32 of 32