Renesas USB MCU USB Peripheral Mass Storage Class Driver (PMSC) using Basic Mini Firmware

Renesas USB MCU USB Peripheral Mass Storage Class Driver (PMSC) using Basic Mini Firmware
APPLICATION NOTE
Renesas USB MCU
R01AN0710EJ0215
Rev.2.15
Mar 28, 2016
USB Peripheral Mass Storage Class Driver (PMSC) using Basic Mini Firmware
Introduction
This document is an application note for the USB Peripheral Mass Storage Class Driver (PMSC) built using the USB
Basic Mini Firmware.
Target Device
RL78/G1C, RL78/L1C, R8C/3MU, R8C/34U, R8C/3MK, R8C/34K
This program can be used with other microcontrollers that have the same USB module as the above target devices.
When using this code in an end product or other application, its operation must be tested and evaluated thoroughly.
This program has been evaluated using the corresponding MCU’s Renesas Starter Kit board.
Contents
1.
Overview ........................................................................................................................................... 2
2.
Operating Confirmation Environment ................................................................................................ 4
3.
Software Configuration ...................................................................................................................... 4
4.
Peripheral MSC Sample Application (APL) ....................................................................................... 9
5.
Peripheral Device Class Driver (PDCD).......................................................................................... 14
6.
USB Peripheral Mass Storage Class Driver (PMSCD) ................................................................... 21
7.
Peripheral Mass Storage Device Driver (PMSDD) ......................................................................... 27
8.
Media Driver Interface ..................................................................................................................... 31
9.
The EEPROM Media Driver ............................................................................................................ 33
10.
Resource Registration in Scheduler................................................................................................ 36
11.
Limitations ....................................................................................................................................... 37
12.
Setup for the e2 studio project ......................................................................................................... 38
13.
Using the e2 studio project with CS+ ............................................................................................... 40
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 1 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
1. Overview
This document is a manual describing use of the USB Peripheral Mass Storage Class Driver (PMSC) for Renesas USB
MCU.
1.1
Functions and Features
The USB Peripheral Mass Storage class driver comprises a USB Mass Storage class bulk-only transport (BOT) protocol.
When combined with a USB peripheral control driver and storage device driver, it enables communication with a USB
host as a BOT-compatible storage device.
The PMSC software cannot itself read/write the storage media. See 11.
1.2
Related Documents
1. Universal Serial Bus Revision 2.0 specification
2. USB Mass Storage Class Specification Overview Revision 1.1
3. USB Mass Storage Class Bulk-Only Transport Revision 1.0, “BOT” protocol
[http://www.usb.org/developers/docs/]
4. User’s Manual: Hardware
5. USB-BASIC-F/W Application Note
6. Block Access Media Driver API.
Available from Renesas Electronics Website
Renesas Electronics Website
http:// www.renesas.com/
USB Devices Page
http://www.renesas.com/prod/usb/
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 2 of 41
Renesas USB MCU
1.3
USB Peripheral Mass Storage Class Driver (PMSC)
Terms and Abbreviations
API
APL
BOT
:
:
:
Application Program Interface
Application program
Universal Serial Bus Mass Storage Class Bulk-Only Transport (Available
at USB Implementers Forum)
cstd
DDI
H/W
PCD
PDCD
PCI
PMSCD
PMSCF
PMSDD
PP
pstd
RSK
Scheduler
Scheduler Macro
SW1/SW2/SW3
Task
USB
USB-BASIC-FW
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
:
Prefix of Function and File for Host & Peripheral USB-BASIC-FW
Device driver interface, or PMSDD API.
Renesas USB MCU
Peripheral control driver of USB-BASIC-FW
Peripheral device class driver (device driver and USB class driver)
PCD interface
Peripheral mass storage USB class driver (PMSCF + PCI + DDI)
Peripheral mass storage class function
Peripheral mass storage device driver (sample ATAPI driver)
Pre-processed definition
Prefix of Function and File for Peripheral USB-Basic-F/W
Renesas Starter Kits
Used to schedule functions, like a simplified OS.
Used to call a scheduler function (non-OS)
User switches on the RSK Board
Processing unit
Universal Serial Bus
USB Basic Firmware mini for Renesas USB device (non-OS)
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 3 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
2.
Operating Confirmation Environment
2.1
Compiler
The compilers which is used for the operating confirmation are follows.
a.
CA78K0R Compiler
b.
CC-RL Compiler V.1.01
c.
IAR C/C++ Compiler for RL78 version 2.10.4
d.
KPIT GNURL78-ELF v15.02
e.
C/C++ Compiler Package for M16C Series and R8C Family V.6.00 Release 00
2.2
V.1.71
Evaluation Board
The evaluation boards which is used for the operating confirmation are follows.
a.
Renesas Starter Kit for RL78/G1C (Product No: R0K5010JGC001BR)
b.
Renesas Starter Kit for RL78/L1C (Product No: R0K50110PC010BR)
c.
R8C/34K Group USB Peripheral Evaluation Board (Product No: R0K5R8C34DK2PBR)
3.
Software Configuration
3.1
Module Configuration
As shown in Figure 3-1, PDCD comprises two layers: The class driver PMSCD and the device driver PMSDD.
PMSCD comprises three layers: PCD API (PCI) closest to the USB HW layer, on top of that the PMSDD API (DDI),
with the BOT protocol control and data transmission/reception (PMSCF) layer in-between.
PMSCD uses the BOT protocol to communicate with the host via PCD.
PMSDD analyzes and executes storage commands received from PMSCD. PMSDD accesses media data via the media
driver.
Figure 3-1 shows a block diagram of the SW modules.
Mass Storage Device Driver (PMSDD)
Device Driver Interface (DDI)
Peripheral
Device Class
Driver
(PDCD)
Peripheral
Mass Storage
Class Driver
(PMSCD)
Peripheral Mass Storage Class Function (PMSCF)
PCD Interface (PCI)
(Media driver)
USB Peripheral Control Driver (PCD)
Media
USB Peripheral Hardware
Figure 3-1 Software Block Diagram
3.1.1
PDCD
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 4 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
As shown in Figure 3-1, PDCD incorporates PMSDD and PMSCD. It takes care of class requests from the USB host,
and responds to USB host storage commands.
Table 3-1 provides an overview of the parts of PDCD, as well as PCD and the media driver. The media driver is
implemented as an interchangeable block media type storage driver.
3.1.2
PMSCD
PMSCD itself in turn comprises three layers: PMSCF, which performs BOT protocol control and data
transmission/reception; DDI for interfacing with PMSDD; and a group of functions (PCI) for interfacing with PCD. The
main functions of these layers are as follows.
1.
PMSCF:
USB mass storage class BOT protocol control
CBW analysis, data transmission/reception, and CSW creation in coordination with PMSDD/PCD
Responding to class requests (MassStorageReset, GetMaxLUN)
2.
PCI :
Processing of tasks, message boxes, and memory pools during configuration and detach
Receiving class requests
Clearing STALL states and setting related callback functions
Setting structures and callback functions for PCD transmit/receive data
3.
DDI:
Driver registration.
Data transfer information and execution results of PMSDD execution. PMSCD is notified via the ATAPI
command result callback function .
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 5 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
Table 3-1
Overview of Modules
Chapter
this doc
USB
Basic
FW
Module
Description
Reference folder/file
Note
PCD
USB peripheral hardware
control driver.
src/USBSTDFW
See “Renesas USB
MCU USB Basic
Firmware mini
Application note
Ch. 6
PCI
PMSCF-PCD interface
functions.
Core component of PMSCD.
Controls BOT protocol data
and responds to USB class
requests. Also transfers
storage commands and data to
and from storage (PMSDD).
PMSDD-PMSCF interface :
Driver registration and
ATAPI result callback.
Peripheral mass storage media
driver. It processes storage
commands from PMSCD and
accesses the media via the
block media driver below.
(To be modified to match the
memory device.)
Block media storage driver.
src/MSCFW/PMSC/r_usb_
pmsc_pci.c
src/MSCFW/PMSC/
r_usb_pmsc_request.c
r_usb_pmsc_driver.c
PMSCF
DDI
Ch. 7
PMSDD
Ch. 8
Block
Media
Driver
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
src/MSCFW/PMSC/r_usb_
pmsc_ddi.c
src/MSCFW/MEDIA/r_usb_
atapi_driver.c
src/MSCFW/MEDIA/r_usb_
atapi_memory.c
See Block Media API
application note
Page 6 of 41
Renesas USB MCU
3.2
USB Peripheral Mass Storage Class Driver (PMSC)
File Structure
The following shows the folder structure for the files provided in this device class.
The source codes unique to each device and evaluation board are stored in the corresponding hardware resource folder
(HwResource)*.
workspace
+ [ RL78 / R8C ]
+[ CCRL / CS+ / IAR / e2 studio / HEW ]
+[RL78G1C / RL78L1C / R8C3MK / R8C3MU / R8C34K / R8C34U ]
+ PERI
Build result
+ src
+――― media_driver [Media driver for Mass Storage Class ]
|
+――― eeprom
EEPROM driver
+――― MSCFW [Mass Storage Class driver ]
|
+――― inc
Common header file of MSC driver
|
+――― MEDIA
Media driver
|
+――― PMSC
MSC driver
+―――SmplMain [ Sample Application ]
|
+――― APL
Sample application
+―――USBSTDFW [Common USB code that is used by all USB firmware ]
|
+――― inc
Common header file of USB driver
|
+――― src
USB driver
+――― HwResource [Hardware access layer; to initialize the MCU ]
+――― inc
Common header file of hardware resource
+―――src
Hardware resource
[Note]
a.
The project for CA78K0R compiler is stored under the CS+ folder.
b.
The project for KPIT GNU compiler is stored under the e2 studio folder.
c.
Refer to 13 Using the e2 studio project with CS+ section when using CC-RL compiler on CS+.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 7 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
Table 3-2 shows the file structure for PDCD.
Table 3-2
File Structure
File Name
include/r_usb_catapi_define.h
include/r_usb_cmsc_define.h
include/r_usb_pmsc_api.h
include/r_usb_pmsc_define.h
include/r_usb_pmsc_extern.h
MEDIA/r_usb_atapi_driver_config.h
MEDIA/r_usb_atapi_driver.c
Description
Device driver header file
PDCD(PMSCD+PMSDD) common header file
PMSC API functions header file
PMSCD header file
External reference header file
Device driver configuration header file
Device driver (PMSDD/media driver)
PMSC/r_usb_pmsc_ddi.c
PMSDD interface functions (DDI)
Driver registration, storage command callback.
USB class driver (PMSCF)
PCD interface functions (PCI)
PCD interface functions (class requests)
Mass storage class descriptor
PMSC/r_usb_pmsc_driver.c
PMSC/r_usb_pmsc_pci.c
PMSC/r_usb_pmsc_request.c
APL/r_usb_pmsc_descriptor.c
3.3
Note
Sample Code for
ATAPI
Need to change as
to user system
System Resources
There is a scheduler that invokes a “task” when it has message(s) pending in the task’s mailbox, and according to the
task’s priority. Table 3-3 lists the ID and priority used to register PMSC in the scheduler. These are defined in the
r_usb_ckernelid.h header file.
For details, refer to the Renesas USB MCU USB Basic Mini Firmware Application note.
Table 3-3
Object
Task
Task Name / ID / Mailbox
USB_PCD_TSK
/ USB_TID_0
USB_PMSC_TSK
/ USB_TID_2
USB_PFLSH_TSK
/ USB_TID_1
Mailbox ID
USB_PMSC_MBX
/ USB_PMSC_TSK
USB_PFLSH_MBX
/ USB_PFLSH_TSK
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
‘Tasks’ (Mailboxes)
Module
usb_pstd_pcd_task
(r_usb_pdriver.c)
Priority: USB_TID_0 (default=0)
PMSCD, or usb_pmsc_Task
( r_usb_pmsc_driver.c)
Priority: USB_TID_2 (default=2)
PMSDD, or usb _pmsc_SmpAtapiTask
(r_usb_atapi_driver.c)
Priority: USB_TID_1 (default=1)
PDCD => PMSCD / PMSDD => PMSCD
(r_usb_pmsc_pci.c,
r_usb_pmsc_driver.c,
r_usb_pmsc_ddi.c)
PMSCD => PMSDD mailbox ID
( r_usb_atapi_driver.c)
Page 8 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
4. Peripheral MSC Sample Application (APL)
PMSC’s main function is to enable file read/write operations for the connected USB mass storage host. The USB
peripheral is to be recognized by the host (e.g. a PC) as a removable disk, so that it can perform operations such as read
and write files. The Mass Storage Class specification defines the transport protocol (BOT), however, various command
sets could be used to control a storage device. The following are examples of command sets which can be used over
USB:
SFF-8070i, (ATAPI) * – Command set used in this sample code.
SFF-8020i, MMC-2 (ATAPI)
QIC-157
UFI
SCSI transparent command set
This sample mass storage device driver supports the storage command set SFF-8070i (ATAPI)*.
* As listed in “Mass Storage Specification Overview v1.2”, command block specification SFF-8070i is used
(bInterfaceSubClass = 05h) together with protocol code “USB Mass Storage Class Bulk-Only” (BBB;
bInterfaceProtocol = 050h).
4.1
Operating Environment
The storage media driver uses a 512K EEPROM in the default RSK cnfiguration. This EEPROM is controlled by
SPI/CSI.
The EEPROM may not be mounted on your RSK board. In order to operate this PMSC sample firmware, prepare the
EEPROM and any connection needed.
[Note]
CSI(Communication Serial Interface) is the interface function that RL78 series supports.
Figure 4-2 illustrates the operating environment, application operation s example.
Storage Media
512K EEPROM
(64Kword * 8-bit)
R1EX25512ATA00A
USB Communications
SPI/CSI
Communications
Enumeration
(PIPE0 Control transfer)
USB Host PC
USB
PORT
Bulk data communication
(PIPE4, 5 Bulk transfer)
USB
PORT
RSK Board
USB cable
Peripheral Mass Storage Class
Driver (PMSC)
+
OS : Windows XP, Windows 7, Windows8 etc
Renesas USB Device
USB Basic Mini Firmware
Figure 4-1 Operating Environment Example
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 9 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
Figure 4-2 Application Operations Example. These are the properties shown for an RSK storage drive,
when PMSC is connected to a PC.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 10 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
Table 4-1 shows EEPROM specifics per RSK type.
Table 4-1
EEPROM connection specification
RL78/G1C
Connection Signal
CSI01 Signal
Name
RSK Port/Junction Pin
EEPROM Pin/Number
Clock
SCK01
P75/J1-6
C/6
Data Transfer(RL78/G1C->EEPROM)
SI01
P74/J1-7
D/5
Data Transfer(RL78/G1C<-EEPROM)
SO01
P73/J1-8
Q/2
Chip Select
--
P30/J1-12
S/1
RL78/L1C
Connection Signal
CSI20 Signal
Name
RSK Port/Junction Pin
EEPROM Pin/Number
Clock
SCK20
P10/J4-2
C/6
Data Transfer(RL78/L1C->EEPROM)
SI20
P11/J4-1
D/5
Data Transfer(RL78/L1C<-EEPROM)
SO20
P12/J3-25
Q/2
Chip Select
--
P30/J2-12
S/1
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 11 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
4.1.1
Application Program Flow
In a sense, there is no “user application” The mass storage class driver and mass storage device driver solely executes
requests from the host.
Figure 4.1 shows the application processing flow overview.
Host
PCD
CBW transfer stage
PMSCD
PMSDD
CBW receive request
(callback function registration
called when CBW is
received)
Transmit CBW
Call-back
Ex.) READ(10)
(CBW transfer)
Verify CBW validity
Verify CBW meaning
usb_pmsc_
SmpAtapiAnalyzeCBWCB()
Analyze storage
command
13-case identification
usb_pmsc_
SmpAtapiCommandExecute()
Callback function registration
called when storage
command execution is
completed
Call-back
Data (IN) transfer stage
Data transfer
(transmit data information)
IN data
Execute storage
command
Call-back
(transmit status)
(transmit data
information transfer)
usb_pmsc_
SmpAtapiCommandExecute()
Execute storage
command
(final data)
Call-back
Data transfer
(transmit data information)
IN data
Call-back
(transmit status)
(transmit data
information transfer)
usb_pmsc_
SmpAtapiCommandExecute()
Callback function registration
called when storage
command execution is
completed
CSW transfer stage
Execute storage
command
Call-back
(execution result transfer)
CSW transfer
Create CSW
Transmit CSW
Figure 4.1
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Application Processing Sequence
Page 12 of 41
Renesas USB MCU
4.2
USB Peripheral Mass Storage Class Driver (PMSC)
API tasks
Table 4-2 shows lists the APL tasks.
Table 4-2
Function name
usb_cstd_task_start
usb_pmsc_task_start
usb_papl_task_start
usb_apl_task_switch
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Lists of APL tasks
Description
Task(PCD, MSCD, APL) start setting
Starts a variety of tasks for the peripheral USB
Start Application task
Switches Task
Page 13 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
5. Peripheral Device Class Driver (PDCD)
5.1
Basic Functions
The functions of PDCD are to:
1. Respond to mass storage class requests from USB host.
2 Respond to USB host storage commands which are encapsulated in the BOT protocol (Bulk Only Transport). See
below.
5.2
BOT Protocol Overview
BOT (USB MSC Bulk-Only Transport) is a transfer protocol that encapsulates command, data, and status (results of
commands) using only two endpoints, one bulk in and one bulk out.
The ATAPI storage commands are embedded in a “Command Block Wrapper” (CBW) and the response status in a
“Command Status Wrapper” (CSW).
Figure 5-1 shows an overview of how the BOT protocol progresses with command and status data flowing between
USB host and peripheral.
Ready
Command Block Wrapper
Command transfer
( Host → Device )
Data-Out
( Host → Device )
Data-In
( Device → Host )
Command Status Wrapper
Status transfer
( Device → Host )
CBW transfer stage
( Command packet )
Data transfer stage
( Data packet )
CSW transfer stage
( Status packet )
Figure 5-1 BOT protocol Overview.
Command and status flow between USB host and peripheral.
5.2.1
CBW processing
When PMSCD receives a command block wrapper (CBW) from the host, it first verifies the validity of the CBW. If the
CBW is valid, PMSCD notifies PMSDD of the storage command contained in the CBW and requests analysis of
PMSDD on the command. PMSCD finally performs processing based on this analysis (command validity, data transfer
direction and size) and the information contained in the wrapper (data communication direction and size).
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 14 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
5.2.2
Sequence for storage command with no data transmit/receive
Figure 5-2 shows the sequence of storage commands without data transfer.
(a).
CBW transfer stage
PMSCD issues a CBW receive request to PCD and registers a callback function. When PCD receives the CBW, it
executes the callback which starts the CBW transfer stage. PMSCD verifies the validity of the CBW and transfers the
storage command (CBWCB) to PMSDD which executes the storage command. PMSDD returns the result to PMSCD.
(b).
CSW transfer stage
Based on the execution result at the time of callback, PMSCD creates a command status wrapper (CSW) and transmits
it to the host via PCD.
For details on PCD operation refer to the USB Basic Mini Firmware Application note.
Host
PCD
CBW transfer stage
Transmit CBW
Ex.)TEST UNIT READY
PMSCD
PMSDD
CBW receive request
(callback function registration
called when CBW is
received)
(CBW reception preparation)
Call-back
(CBW transfer)
Verify CBW validity
Verify CBW meaning
usb_pmsc_
SmpAtapiAnalyzeCBWCB()
Analyze storage
command
13-case identification
usb_pmsc_
SmpAtapiCommandExecute()
Callback function registration
called when storage
command execution is
completed
CSW transfer stage
Execute storage
command
Call-back
(execution result transfer)
CSW transfer
Create CSW
Transmit CSW
Figure 5-2 Sequence of Storage Command for No Transmit/Receive Data
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 15 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
5.2.3
Sequence with storage command for transmit (IN) data
Figure 5-3 shows the sequence of storage command when there is transmit (IN) data from the peripheral side.
(a).
CBW transfer stage
PMSCD executes a CBW receive request to PCD, and sets up a callback. When PCD receives the CBW it executes the
callback. PMSCD verifies the validity of the CBW and transfers the storage command (CBWCB) to PMSDD which
analyzes the data transmit command and returns the result to PMSCD. PMSCD then reads the CBW and sends an
ATAPI storage command execution request to PMSDD together with a callback registration.
(b).
Data IN transfer stage
Based on the execution result at the time of callback, PMSCD notifies PCD of the data storage area and data size, and
data communication with the USB host takes place. When the peripheral PCD issues a transmit end notification (status),
PMSCD once again sends a continuation request to PMSDD, and data transmission is repeated.
(c).
CSW transfer stage
When PMSCD receives a command processing end result from PMSDD, PMSCD creates a command status wrapper
(CSW) and transmits it to the host via PCD.
For PCD operation details refer the USB Basic Mini Firmware Application note.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 16 of 41
Renesas USB MCU
Host
USB Peripheral Mass Storage Class Driver (PMSC)
PCD
CBW transfer stage
PMSCD
PMSDD
CBW receive request
(callback function registration
called when CBW is
received)
Transmit CBW
Ex.) READ(10)
Call-back
(CBW transfer)
Verify CBW validity
Verify CBW meaning
usb_pmsc_
SmpAtapiAnalyzeCBWCB()
Analyze storage
command
13-case identification
usb_pmsc_
SmpAtapiCommandExecute()
Callback function registration
called when storage
command execution is
completed
Call-back
Data (IN) transfer stage
Data transfer
IN data
Execute storage
command
(transmit data information)
Call-back
(transmit status)
(transmit data
information transfer)
usb_pmsc_
SmpAtapiCommandExecute()
Execute storage
command
(final data)
Call-back
Data transfer
IN data
(transmit data information)
Call-back
(transmit status)
(transmit data
information transfer)
usb_pmsc_
SmpAtapiCommandExecute()
Callback function registration
called when storage
command execution is
completed
CSW transfer stage
Execute storage
command
Call-back
(execution result transfer)
CSW transfer
Create CSW
Transmit CSW
Figure 5-3 Sequence of Storage Command for Transmit (IN) Data
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 17 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
5.2.4
Sequence for storage command with receive (OUT) data
Figure 5-4 shows the sequence of storage command when there is transmit (OUT) data from the peripheral.
(a).
CBW transfer stage
In the CBW transfer stage, PMSCD issues a CBW receive request to PCD and sets up a callback.. When PCD receives
the CBW it executes the callback. PMSCD verifies the validity of the CBW and transfers the storage command
(CBWCB) to PMSDD. PMSDD analyzes the data transmit command, and returns the result to PMSCD. PMSCD then
compares the analysis result from PMSDD with the information contained in the CBW and sends an ATAPI storage
command execution request to PMSDD together with a callback registration.
(b).
Data OUT transfer stage
Based on the callback execution result, PMSCD notifies PCD of the data storage area and data size, and data
communication with the host takes place. When it receives transmit end notification from PCD, PMSCD once again
sends a common continuation request to PMSDD, and data transmission is repeated.
(c).
CSW transfer stage
When it receives a command processing end result from PMSDD, PMSCD creates a command status wrapper (CSW)
and transmits it to the host via PCD.
For PCD operation details refer to the USB Basic Mini Firmware Application note.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 18 of 41
Renesas USB MCU
Host
USB Peripheral Mass Storage Class Driver (PMSC)
PCD
CBW transfer stage
PMSCD
PMSDD
CBW receive request
(callback function registration
called when CBW is
received)
Transmit CBW
Ex.) WRITE(10)
Call-back
(CBW transfer)
Verify CBW validity
Verify CBW meaning
usb_pmsc_
SmpAtapiAnalyzeCBWCB()
Analyze storage
command
13-case identification
usb_pmsc_
SmpAtapiCommandExecute()
Callback function registration
called when storage
command execution is
completed
Data (OUT) transfer stage
Execute storage
command
Call-back
Data transfer
(receive data information)
(receive data information
transfer)
OUT data
Call-back
(receive status)
usb_pmsc_
SmpAtapiCommandExecute()
Call-back
Data transfer
(receive data information)
(receive data information
transfer)
Execute storage
command
(final data)
OUT data
Call-back
(receive status)
usb_pmsc_
SmpAtapiCommandExecute()
Callback function registration
called when storage
command execution is
completed
CSW transfer stage
Execute storage
command
Call-back
(execution result transfer)
CSW transfer
Create CSW
Transmit CSW
Figure 5-4
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Sequence of Storage Command for Receive (OUT) Data
Page 19 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
5.2.5
Access sequence for class request
Figure 5-5 shows the sequence when a mass storage class request is received.
(a).
Setup Stage
When PCD receives a class request in the control transfer Setup Stage, it sends a request received notification to
PMSCD.
(b).
Data Stage
PMSCD executes the control transfer Data Stage and notifies PCD of data stage end by means of a callback function.
(c).
Status Stage
PCD executes the Status Stage and ends the control transfer.
Host
PCD
PMSCD
PMSDD
Setup stage
Ex.) GetMaxLUN
Request notification
Create MaxLUN
Data stage
Transmit MaxLUN
R_usb_pstd_ControlRead()
Call-back
Status stage
Status
Figure 5-5
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Sequence for Class Request
Page 20 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
6. USB Peripheral Mass Storage Class Driver (PMSCD)
6.1
Basic Functions
The basic interface functions of PMSCD register, open, and close the Peripheral Mass Storage Class Driver.
The rest of the functionality inside PMSCD was described in the sequence charts in chapter 5 Peripheral Device Class
Driver (PDCD).
6.2
List of API Functions
Table 6-1 List of API Functions
Function Name
R_usb_pmsc_Registration
R_usb_pmsc_Open
R_usb_pmsc_Close
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Description
Registers PMSC driver
Open PMSC driver
Close PMSC driver
Page 21 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
R_usb_pmsc_Registration
Registers PMSC driver
Format
void
R_usb_pmsc_Registration(void)
Arguments
-
Return Values
-
Description
Registers the USB Peripheral Mass Storage Class driver with PCD.
Make your changes to the registration function according to the application program.
Use the usb_pcdreg_t type structure when registering the class driver. The information registered is as follows. For
structure member details, refer to "USB Basic Mini Firmware mini Application note".
pipetbl
Pipe information table address
devicetbl
Device descriptor address
configtbl
Configuration descriptor address
stringtbl String descriptor address table
statediagram
Callback function to start at change usb state
ctrltrans Callback function to start at control transfer for the user
Notes
1.
If a callback is not needed, register a dummy function.
2.
For USB device state detail refer to "Universal Serial Bus Specification Revision 2.0 " Figure 9-1 Device State
Diagram.
3.
The string descriptor address table must be filled out. An example is as follows
uint8_t *usb_gpmsc_StrPtr[USB_STRINGNUM] =
{
usb_gpmsc_StringDescriptor0, /* Language ID String Descriptor Address */
usb_gpmsc_StringDescriptor1, /* iManufacturer String Descriptor Address */
usb_gpmsc_StringDescriptor2, /* iProduct String Descriptor Address */
usb_gpmsc_StringDescriptor3, /* iInterface String Descriptor Address */
usb_gpmsc_StringDescriptor4, /* iConfiguration String Descriptor Address */
usb_gpmsc_StringDescriptor5, /* iConfiguration String Descriptor Address */
usb_gpmsc_StringDescriptor6 /* iSerialNumber String Descriptor Address */
};
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 22 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
Example
void usb_pmsc_task_start( void )
{
R_usb_pmsc_Registration();
/* Peripheral Application Registration */
R_usb_pstd_PcdChangeDeviceState(USB_DO_SETHWFUNCTION); /* Initialize USB
HW */
R_usb_pmsc_driver_start(); /* Peripheral Class Driver Task Start Setting */
usb_pstd_usbdriver_start(); /* Peripheral USB Driver Start Setting */
usb_papl_task_start();
/* Peripheral Application Task Start Setting */
}
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 23 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
R_usb_pmsc_Open
Open PMSC driver
Format
usb_er_t R_usb_pmsc_Open(uint16_t data1, uint16_t data2)
Argument
uint16_t
data1
: Not used
uint16_t
data2
: Not used
Return Value
uint16_t
Processing result. 0 = USB_E_OK
Description
This function is to be called when the USB device has been connected, has enumerated and been configured by
the USB host .
The function sets the CBW reception setting.
Note
Call this function in the callback function which is registered in the structure(usb_pcdreg_t)
member (statediagram)
Example
void usb_pmsc_change_device_state( uint16_t data1, uint16_t device_state )
{
switch ( device_state )
{
case USB_STS_CONFIGURED:
R_usb_pmsc_Open(data1, device_state);
break;
}
}
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 24 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
R_usb_pmsc_Close
Close PMSC driver
Format
Usb_er_t R_usb_pmsc_Close(Usb_utr_t *ptr, uint16_t data1, uint16_t data2)
Argument
Usb_utr_t
*ptr
: Pointer to a USB Transfer Structure
uint16_t
data1
: Not used
uint16_t
data2
: Not used
Return Value
uint16_t
-
USB_E_OK
Description
This function is to be called when the USB device has been disconnected..
This function is called at transition to the detached state. There are no operations. Add if necessary.
Note
This function should be called when the callback function registered with API R_usb_pmsc_Registration() is triggered
for state change USB_STS_DETACH. See below.
Example
void usb_pmsc_change_device_state( uint16_t data1, uint16_t device_state )
{
switch ( device_state )
{
case USB_STS_DETACH:
R_usb_pmsc_Close(data1, device_state);
break;
}
}
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 25 of 41
Renesas USB MCU
6.3
USB Peripheral Mass Storage Class Driver (PMSC)
Class Driver Registration
The device class driver PMSCD must be registered with PCD to function. Use the R_usb_pmsc_Registration() function
to register PMSCD, using the sample code as reference. See 8.1, For details, refer to the Renesas USB MCU USB Basic
Firmware mini Application note.
6.4
User Definition Tables
It is necessary to create a descriptor table and Pipe Information Table for use by PCD. Refer to the sample file
r_usb_pmsc_descriptor.c when creating these tables. For details on the Pipe Information Table refer to the Renesas
USB MCU USB Basic Firmware mini Application note.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 26 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
7. Peripheral Mass Storage Device Driver (PMSDD)
The main function of PMSDD is to analyze and call for execution of storage commands received from the host via
PMSCD. Host enumeration is determined by the InterfaceSubClass as set in the descriptor source code and is set to
SFF-8070i (ATAPI). This command set is used by the host to control the storage media. These are the storage
commands:
READ10
INQUIRY
REQUEST_SENSE
MODE_SENSE6
MODE_SENSE10
READ_FORMAT_CAPACITY
READ_CAPACITY
WRITE10
WRITE_AND_VERIFY
MODE_SELECT6
MODE_SELECT10
FORMAT_UNIT
TEST_UNIT_READY
START_STOP_UNIT
SEEK
VERIFY10
PREVENT_ALLOW
PMSDD notifies PMSCD of communication data and execution results related to storage command execution.
PMSDD divides the data transfer intp0 pieces when the transfer data length exceeds the user-specified block count.
A master boot record (FAT12) sample table is provided.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 27 of 41
Renesas USB MCU
7.1
USB Peripheral Mass Storage Class Driver (PMSC)
PMSDD Storage Command Structure
The “storage command structure” is USB_PMSC_CDB_t. The format of a storage command (SFF-8070i) differs
depending on the command category, so a union is used for the command. Four patterns encompass ten command
categories as shown in Table 7-1.
Table 7-1 USB_PMSC_CDB_t Structure
Union Member
s_usb_ptn0
s_usb_ptn12
s_usb_ptn378
s_usb_ptn4569
Type
uint8_t
uint8_t
s_LUN
uint8_t
uint8_t
uint8_t
s_LUN
uint8_t
uint8_t
uint8_t
uint8_t
uint8_t
uint8_t
s_LUN
uint8_t
uint8_t
uint8_t
uint8_t
uint8_t
uint8_t
uint8_t
s_LUN
uint8_t
uint8_t
uint8_t
uint8_t
uint8_t
uint8_t
uint8_t
uint8_t
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Structure Member
uc_OpCode
b_LUN
b_reserved
uc_data
uc_OpCode
b_LUN
b_reserved4
b_immed
uc_rsv2[2]
uc_Allocation
uc_rsv1[1]
uc_rsv6[6]
uc_OpCode
b_LUN
b_FmtData
b_CmpList
b_Defect
ul_LBA0
ul_LBA1
ul_LBA2
ul_LBA3
uc_rsv6[6]
uc_OpCode
b_LUN
b_1
b_reserved2
b_ByteChk
b_SP
ul_LogicalBlock0
ul_LogicalBlock1
ul_LogicalBlock2
ul_LogicalBlock3
uc_rsv1[1]
us_Length_Hi
us_Length_Lo
uc_rsv3[3]
Bit Count
Command Category
Command determination (common)
3
5
3
4
1
INQUIRY /
REQUEST_SENSE
Not used (FORMAT UNIT)
3
1
1
3
3
1
2
1
1
READ10 /
WRITE10 /
WRITE _AND_VERIFY /
MODE_SENSE /
FORMAT CAPACITY /
MODE SELECT
Page 28 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
Table 7-2 shows storage commands analysis result.
Table 7-2 The USB_PMSC_CBM_t Structure
Contains “analysis” result of usb_pmsc_SmpAtapiAnalyzeCbwCb.
Type
Member
uint32_t
ar_rst
PMSDD storage command
analysis RESULT
Data direction.
uint32_t
ul_size
Data size
7.2
Remarks
Direction of data transported in last ATAPI
command.
Size of data in last ATAPI command.
List of PMSDD Functions
Table 7-3 lists the functions of PMSDD.
Table 7-3
Function Name
usb_pmsc_SmpAtapiAnalyzeCbwCb
usb_pmsc_SmpAtapiTask
usb_pmsc_SmpAtapiInitMedia
usb_pmsc_SmpAtapiCloseMedia
usb_pmsc_SmpAtapiCommandExecute
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
List of PMSDD Functions
Description
Analyzes storage command.
Main task of PMSDD
Initialization at PMSDD start
Processing at PMSDD end
Transmits message from PMSCD to PMSDD main task.
Page 29 of 41
Renesas USB MCU
7.3
USB Peripheral Mass Storage Class Driver (PMSC)
PMSDD Task Description
PMSDD receives storage commands from PMSCD and executes them. PMSDD also receives host data transfer results
from PMSCD. Table 7-4 lists PMSDD command processing. When the transfer data size exceeds
USB_ATAPI_BLOCK_UNIT, the data is divided into smaller units and transferred.
For commands that do not involve memory access, the transmitted data is created from the response data tables
g_pmsc_atapi_data_size[],
g_pmsc_atapi_rd_dat_idx[],
g_pmsc_atapi_req_idx[], and
g_pmsc_atapi_rd_dat_tbl[]. (*1)
(*1) These response data tables follow storage command set SFF-8070i. The index into the table is determined
by the command. Refer to uc_OpCode in Table 7-1 USB_PMSC_CDB_t Structure.
Table 7-4
Corresponding Function per Storage Command
Storage command
READ10
INQUIRY
Corresponding Function
pmsc_atapi_get_read_memory()
pmsc_atapi_get_read_data()
REQUEST_SENSE
pmsc_atapi_get_read_data ()
MODE_SENSE10
pmsc_atapi_get_read_data ()
READ_FORMAT_CAPACITY
pmsc_atapi_get_read_data ()
READ_CAPACITY
pmsc_atapi_get_read_data ()
WRITE10
WRITE_AND_VERIFY
MODE_SELECT10
FORMAT_UNIT
TEST_UNIT_READY
pmsc_atapi_get_write_memory()
pmsc_atapi_get_write_memory()
pmsc_atapi_get_write_memory()
pmsc_atapi_get_write_memory()
usb_pmsc_SmpAtapiTask()
START_STOP_UNIT
usb_pmsc_SmpAtapiTask()
SEEK
usb_pmsc_SmpAtapiTask()
VERIFY10
usb_pmsc_SmpAtapiTask()
PREVENT_ALLOW
usb_pmsc_SmpAtapiTask()
others
usb_pmsc_SmpAtapiTask()
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Description
Gets start address and size.
Selects response data from array
g_pmsc_atapi_rd_dat_tbl.
Selects response data from array
g_pmsc_atapi_rd_dat_tbl.
Selects response data from array
g_pmsc_atapi_rd_dat_tbl.
Selects response data from array
g_pmsc_atapi_rd_dat_tbl.
Selects response data from array
g_pmsc_atapi_rd_dat_tbl.
Gets start address and size.
Gets start address and size.
Gets start address and size.
Gets start address and size.
Status =
USB_PMSC_CMD_COMPLETE
Status =
USB_PMSC_CMD_COMPLETE
Status =
USB_PMSC_CMD_COMPLETE
Status =
USB_PMSC_CMD_COMPLETE
Status =
USB_PMSC_CMD_FAILED
Status =
USB_PMSC_CMD_ERROR
Page 30 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
Media Driver Interface
8.
This chapter is an introduction to the block USB Peripheral Mass Storage Class Driver (PMSC), and how it is used for
PMSC. For complete details on this API and how to create new media drivers that interface through it, see application
note no. r01an1443eu_rx.
PMSC is able to operate with a variety of devices as data storage media. It uses a block storage type driver API
described in the application note (Document No. r01an1443eu_rx). The storage media interface is an abstract set of
functions (R_MEDIA_Read, R_MEDIA_Write, etc) which are the same regardless of the underlying driver that will be
called behind the interface. PMSC can interface any media driver that supports this API.
8.1
Overview of Media Driver API Functions
The Block Access Media Driver API serves to interface the PMSC application to a specific media device driver. The
selection of media is made through configuration files that the user must customize. There is one configuration file for
the Block Access Media Driver API, r_media_driver_api_config.h, which has a list of media devices, and another
configuration file for PMSC, r_usb_atapi_driver_config.h, which assigns the selected media driver to be used for
PMSC.
The transport layer subtype in this application is SFF-8070i (ATAPI). This layer processes the storage commands that
are contained in the Command Blocks that are tunneled through the BOT transport layer. Most of the work done to
process the command set is accomplished by routines in the file r_usb_atapi_driver.c. This is where the ATAPI data
storage commands that write or read the storage media, that is, the block API calls, originate. Storage commands pass
through the Block Access Media Driver API layer where they are directed to drivers for the assigned storage device.
Table 8-1 The Block Access Media Driver API functions
Function Name
R_MEDIA_Initialize
R_MEDIA_Open
R_MEDIA_Close
R_MEDIA_Read
R_MEDIA_Write
R_MEDIA_Ioctl
8.2
Description
Registers the media driver
Open media driver
Close media driver
Read from a media device
Write to a media device
Perform control and query operations on a media device
Selecting Media Driver
A media driver has a structure that contains the pointers to its implementation of the API’s abstract functions shown in
Table 8-1. The name of this driver implementation structure must be assigned to a macro used by the ATAPI task:
ATAPI_MEDIA_DEVICE_DRIVER in r_media_driver_api_config.h.
The section, or block, size must match both what the host can handle (e.g. Windows FAT and what the bottom layer
driver can handle, e.g. 512 or 4096 bytes.
8.2.1
Initializing the Media Driver Function Set
Once the block media driver functions listed in the g_MediaDriverList actually exist, all that is needed is to call the
abstract function
R_MEDIA_Initialize(&ATAPI_MEDIA_DEVICE_DRIVER);
which will write the actual driver member functions to g_MediaDriverList at runtime. Once the member functions have
popluated g_MediaDriverList, calls to the other abstract block media functions; R_MEDIA_Open, R_MEDIA_Read,
R_MEDIA_Write,… will redirect to call the user’s particular driver functions. In other words, it all happens behind the
scene without the user having to replace the abstract call with the actual driver calls.
This initialization call is already done in PMSC in file r_media_driver_api.c.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 31 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
This runtime registration of the drivers can be omitted, and the member functions be called directly, but the member
functions must then not be declared (and defined) as static in the driver source code, as in the RAM and API sample
drivers.
8.3
Changing (adding) Storage Media
Suppose you would like to change what media the data is stored on. Default is EEPROM. To use a different storage
media, the read, write, etc functions must first be made to conform to the block media driver API described above.
8.3.1
1.
2.
Steps to conform a driver to the block media API
Add the media driver interface function source code using return types and arguments as specified in
r_media_driver_api.h. Then add a media_driver_s structure containing pointers to these members at the top of
this file.
In r_usb_atapi_driver_config.h, add the definitions as described in 8.2. and call the abstract initialize function in
8.2.1, before any calls to the block driver API functions are made.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 32 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
9. The EEPROM Media Driver
The EEPROM media driver that is supplied preconfigured to use EEPROM as a storage media device. While this is
provided primarily as a simplified example of a media driver to demonstrate the functionality of USB-PMSC, it can still
be useful as a means to transfer data to or from the MCU to the USB host.
(1). Operates as the attached media device
The sample code operates as media with 64KByte EEPROM (Renesas: R1EX25512ATA00A).
(2). Media is preformatted to appear as removable FAT file storage device.
(3). Media driver supports connection to Windows OS (XP, 7, etc) host.
(4). Default format may be overwritten by format command from the host.
(5). Host can read files from EEPROM or write files to it, and can update the FAT format information as needed.
9.1
EEPROM Media Driver Default FAT Format
The EEPROM media device is preformatted to appear as removable FAT file storage device.
The file r_eeprom_disk_format_data.c contains the section declarations and the pre-initialized data that will get stored
to EEPROM at system startup.
The beginning of the EEPROM area (lowest memory address) is considered to be the boot sector (sector 0), as block
zero is the default boot sector area in a FAT formatted storage device. Therefore, all storage blocks are addressed
relative to this location. When a host device accesses the media device it will always communicate in terms of starting
logical block number “LBN”, and “block count”, the number of blocks to transfer (512 for WindowsXP and 4096 for
Windows7). The host knows how to navigate a FAT formatted storage device, and will read the first sector to gain
information about the specific format on the EEPROM, and then discover where to look for additional file information.
From that the host will know which block numbers to access for EEPROM data storage.
Alternatively, the host can re-format the EEPROM, replacing the default boot sector, FAT tables, etc, with its own
format. In this case the host still knows where in the EEPROM a specific block of data resides.
Note: It is not strictly necessary for a USB-PMSC device to have a FAT file system format, however most host systems
will expect to use the PMSC device for file storage with FAT as the file system type.
The USB device cannot access the FAT storage on its own. See chapter 11.
9.2
EEPROM Global Area Variables
The entire EEPROM RAM section is of global scope with a number of named variables. Table 9-1 lists the global area
variables of the media driver.
Table 9-1 Media Driver Global Areas
Type
uint8_t
uint8_t
uint8_t
uint8_t
Variable Name
eeprom_boot_sector
usb_gpmsc_Table1
usb_gpmsc_TableFat
usb_gpmsc_RootDir
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Description
Primary Boot Record area
Dummy area
FAT table
Directory entry area
(sector 0)
(sector 1)
(sector 2 and 3)
(sector 4)
Page 33 of 41
Renesas USB MCU
9.3
USB Peripheral Mass Storage Class Driver (PMSC)
Constant Definitions
Table 9-2 shows the constant definitions used for the EEPROM media driver.
Table 9-2 PMSDD Constant Definitions
Description
Definition name
Value
Remark
Media type
EEPROM_MEDIATYPE
0xF8u
Modifiable
Signature
EEPROM_SIGNATURE
0xAA55u
Sector size
EEPROM_SECTSIZE
512ul
Not
modifiable
Modifiable
Cluster size
FAT number
EEPROM_CLSTSIZE
EEPROM_FATNUM
0x01u
0x02u
Modifiable
Modifiable
Media size *1
Total number of
sectors*2
EEPROM_MEDIASIZE
EEPROM_TOTALSECT
64*1024(=64Kbyte)
EEPROM_MEDIA_SIZE / EEPROM_SECTSIZE
Modifiable
Not
modifiable
FAT Table Length*2
EEPROM_FATLENGTH
341ul(FAT12)
FAT table length*2
EEPROM_FATSIZE
(((EEPROM_TOTALSECT-8) /
EEPROM_FATLENGTH)+1)
Not
modifiable
Not
modifiable
Root directory
EEPROM_ROOTTOP
(((EEPROM_FATSIZE *
EEPROM_FATNUM+1)/8+1)*8)
FAT start
EEPROM_FATTOP
(EEPROM_ROOTTOP - (EEPROM_FATSIZE *
EEPROM_FATNUM))
Root Directory size
EEPROM_ROOTSIZE
1ul
Not
modifiable
(Not used)
Not
modifiable
(Not used)
Not
modifiable
(Not used)
*1 A minimum 20K byte capacity is required when connecting the device to a PC running WindowsXP.
FAT12 is selected when the media size is set to under 2M bytes.
FAT16 is selected when the media size is set to under 32M bytes.
*2 Total number of sectors, FAT data length, and FAT table length are automatically calculated based on the media size.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 34 of 41
Renesas USB MCU
9.4
USB Peripheral Mass Storage Class Driver (PMSC)
Operation Overview
Table 9-3 lists the EEPROM media variables and Figure 9.1 shows the EEPROM media block diagram.
Table 9-3 Media Variables
Category
PBR
Dummy area
FAT1
FAT2
ROOT DIR
Sector No.
Sector 0
Sector 1
Sector 2
Sector 3
Sector 4
Physical Address
0x0000
0x0200
0x0400
0x0600
0x0800
Sector 0
PBR
Accesible Size
512Byte
512Byte
512Byte EEPROM_FATSIZE
512Byte EEPROM_FATSIZE
512Byte16
EEPROM__SECTSIZE
Sector 1
Dummy area
Sector 2
FAT1
EEPROM_FATSIZE
Sector 3
FAT2
EEPROM_FATSIZE
EEPROM_ROOTTOP
Sector 4
Data (ROOT DIR)
EEPROM_TOTALSECT
Data
Figure 9.1 Media Block
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 35 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
10. Resource Registration in Scheduler
When using the scheduler, it is necessary to register resources such as task IDs, and mailbox IDs in the
file"r_usb_ckernelid.h".
In the sample file, the registrations are as follows.
/* Peripheral MSC Sample Task */
#define USB_PFLSH_TSK
USB_TID_1
#define USB_PFLSH_MBX
USB_PFLSH_TSK
/* Task ID */
/* Mailbox ID */
/* Peripheral MSC Driver Task */
#define USB_PMSC_TSK
USB_TID_2
#define USB_PMSC_MBX
USB_PMSC_TSK
/* Task ID */
/* Mailbox ID */
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 36 of 41
Renesas USB MCU
11.
USB Peripheral Mass Storage Class Driver (PMSC)
Limitations
The PMSC firmware does not include a FAT library, so it cannot access the storage via file system calls on its own.
Adding local media access is possible, but a FAT driver must be added to the firmware.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 37 of 41
Renesas USB MCU
12.
USB Peripheral Mass Storage Class Driver (PMSC)
Setup for the e2 studio project
(1). Start up e2 studio.
* If starting up e2 studio for the first time, the Workspace Launcher dialog box will appear first. Specify the folder
which will store the project.
(2). Select [File]  [Import]; the import dialog box will appear.
(3). In the Import dialog box, select [Existing Projects into Workspace].
Figure 12-1
Select Import Source
(4). Press [Browse] for [Select root directory]. Select the folder in which [.cproject ] (project file) is stored.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 38 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
Figure 12-2
Project Import Dialog Box
(5). Click [Finish].
This completes the step for importing a project to the project workspace.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 39 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
Using the e2 studio project with CS+
13.
This package contains a project only for e2 studio. When you use this project with CS+, import the project to CS+ by
following procedures.
[Note]
The rcpc file is stored in "workspace\RL78\CCRL\devicename" folder.
Launch CS+ and click “Start”.
Select [Open Exsisting e2studio/CubeSuite/High-performance Embedded
Workshop/PM+ project] in Start menu.
Select the file with the extension
[.rcpc] and click Open button.
Select [project file for
e2studio]
Select the device used in
the project.
Select the used project
e.g. Sample
The project name depends on the AN.
Select Project type, and specify the
project name and its location.
Click OK button if they are OK.
Figure 13-1
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Using the e2 studio project with CS+
Page 40 of 41
Renesas USB MCU
USB Peripheral Mass Storage Class Driver (PMSC)
Website and Support
Renesas Electronics Website
http://www.renesas.com/
Inquiries
http://www.renesas.com/contact/
All trademarks and registered trademarks are the property of their respective owners.
R01AN0710EJ0215 Rev.2.15
Mar 28, 2016
Page 41 of 41
Revision Record
Rev.
1.00
2.00
Date
Dec.10.2010
Mar.29.2013
2.10
2.11
2.12
2.13
2.14
Aug.01.2013
Oct. 31. 2013
Mar.31.2014
Mar.16.2015
Jan.18.2016
2.15
Mar. 28. 2016
Description
Page
Summary
—
First edition issued
—
Revision of the document by firmware upgrade.
Complete rewrite of Media Driver chapter.
—
RL78/L1C, RX111 is supported. Error is fixed.
—
2.2.1 Folder Structure was corrected.
—
R8C is supported. Error is fixed.
—
RX111 is deleted from Target Device
—
Supported Technical Update (Document No. TN-RL*-A055A/E and
TN-RL*-A033B/E)
—
CC-RL compiler is supported.
A-1
General Precautions in the Handling of MPU/MCU Products
The following usage notes are applicable to all MPU/MCU products from Renesas. For detailed usage notes on the
products covered by this document, refer to the relevant sections of the document as well as any technical updates that
have been issued for the products.
1. Handling of Unused Pins
Handle unused pins in accordance with the directions given under Handling of Unused Pins in the
manual.
 The input pins of CMOS products are generally in the high-impedance state. In operation with an
unused pin in the open-circuit state, extra electromagnetic noise is induced in the vicinity of LSI, an
associated shoot-through current flows internally, and malfunctions occur due to the false
recognition of the pin state as an input signal become possible. Unused pins should be handled as
described under Handling of Unused Pins in the manual.
2. Processing at Power-on
The state of the product is undefined at the moment when power is supplied.
 The states of internal circuits in the LSI are indeterminate and the states of register settings and
pins are undefined at the moment when power is supplied.
In a finished product where the reset signal is applied to the external reset pin, the states of pins
are not guaranteed from the moment when power is supplied until the reset process is completed.
In a similar way, the states of pins in a product that is reset by an on-chip power-on reset function
are not guaranteed from the moment when power is supplied until the power reaches the level at
which resetting has been specified.
3. Prohibition of Access to Reserved Addresses
Access to reserved addresses is prohibited.
 The reserved addresses are provided for the possible future expansion of functions. Do not access
these addresses; the correct operation of LSI is not guaranteed if they are accessed.
4. Clock Signals
After applying a reset, only release the reset line after the operating clock signal has become stable.
When switching the clock signal during program execution, wait until the target clock signal has
stabilized.
 When the clock signal is generated with an external resonator (or from an external oscillator)
during a reset, ensure that the reset line is only released after full stabilization of the clock signal.
Moreover, when switching to a clock signal produced with an external resonator (or by an external
oscillator) while program execution is in progress, wait until the target clock signal is stable.
5. Differences between Products
Before changing from one product to another, i.e. to a product with a different part number, confirm
that the change will not lead to problems.
 The characteristics of an MPU or MCU in the same group but having a different part number may
differ in terms of the internal memory capacity, layout pattern, and other factors, which can affect
the ranges of electrical characteristics, such as characteristic values, operating margins, immunity
to noise, and amount of radiated noise. When changing to a product with a different part number,
implement a system-evaluation test for the given product.
Notice
1.
Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples. You are fully responsible for
the incorporation of these circuits, software, and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use
of these circuits, software, or information.
2.
Renesas Electronics has used reasonable care in preparing the information included in this document, but Renesas Electronics does not warrant that such information is error free. Renesas Electronics
assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein.
3.
Renesas Electronics does not assume any liability for infringement of patents, copyrights, or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or
technical information described in this document. No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights of Renesas Electronics or
others.
4.
You should not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part. Renesas Electronics assumes no responsibility for any losses incurred by you or
third parties arising from such alteration, modification, copy or otherwise misappropriation of Renesas Electronics product.
5.
Renesas Electronics products are classified according to the following two quality grades: "Standard" and "High Quality". The recommended applications for each Renesas Electronics product depends on
the product's quality grade, as indicated below.
"Standard": Computers; office equipment; communications equipment; test and measurement equipment; audio and visual equipment; home electronic appliances; machine tools; personal electronic
equipment; and industrial robots etc.
"High Quality": Transportation equipment (automobiles, trains, ships, etc.); traffic control systems; anti-disaster systems; anti-crime systems; and safety equipment etc.
Renesas Electronics products are neither intended nor authorized for use in products or systems that may pose a direct threat to human life or bodily injury (artificial life support devices or systems, surgical
implantations etc.), or may cause serious property damages (nuclear reactor control systems, military equipment etc.). You must check the quality grade of each Renesas Electronics product before using it
in a particular application. You may not use any Renesas Electronics product for any application for which it is not intended. Renesas Electronics shall not be in any way liable for any damages or losses
incurred by you or third parties arising from the use of any Renesas Electronics product for which the product is not intended by Renesas Electronics.
6.
You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics, especially with respect to the maximum rating, operating supply voltage
range, movement power voltage range, heat radiation characteristics, installation and other product characteristics. Renesas Electronics shall have no liability for malfunctions or damages arising out of the
use of Renesas Electronics products beyond such specified ranges.
7.
Although Renesas Electronics endeavors to improve the quality and reliability of its products, semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and
malfunctions under certain use conditions. Further, Renesas Electronics products are not subject to radiation resistance design. Please be sure to implement safety measures to guard them against the
possibility of physical injury, and injury or damage caused by fire in the event of the failure of a Renesas Electronics product, such as safety design for hardware and software including but not limited to
redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures. Because the evaluation of microcomputer software alone is very difficult,
please evaluate the safety of the final products or systems manufactured by you.
8.
Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product. Please use Renesas Electronics
products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances, including without limitation, the EU RoHS Directive. Renesas Electronics assumes
no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations.
9.
Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or
regulations. You should not use Renesas Electronics products or technology described in this document for any purpose relating to military applications or use by the military, including but not limited to the
development of weapons of mass destruction. When exporting the Renesas Electronics products or technology described in this document, you should comply with the applicable export control laws and
regulations and follow the procedures required by such laws and regulations.
10. It is the responsibility of the buyer or distributor of Renesas Electronics products, who distributes, disposes of, or otherwise places the product with a third party, to notify such third party in advance of the
contents and conditions set forth in this document, Renesas Electronics assumes no responsibility for any losses incurred by you or third parties as a result of unauthorized use of Renesas Electronics
products.
11. This document may not be reproduced or duplicated in any form, in whole or in part, without prior written consent of Renesas Electronics.
12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electronics products, or if you have any other inquiries.
(Note 1)
"Renesas Electronics" as used in this document means Renesas Electronics Corporation and also includes its majority-owned subsidiaries.
(Note 2)
"Renesas Electronics product(s)" means any product developed or manufactured by or for Renesas Electronics.
http://www.renesas.com
SALES OFFICES
Refer to "http://www.renesas.com/" for the latest and detailed information.
Renesas Electronics America Inc.
2801 Scott Boulevard Santa Clara, CA 95050-2549, U.S.A.
Tel: +1-408-588-6000, Fax: +1-408-588-6130
Renesas Electronics Canada Limited
9251 Yonge Street, Suite 8309 Richmond Hill, Ontario Canada L4C 9T3
Tel: +1-905-237-2004
Renesas Electronics Europe Limited
Dukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, U.K
Tel: +44-1628-585-100, Fax: +44-1628-585-900
Renesas Electronics Europe GmbH
Arcadiastrasse 10, 40472 Düsseldorf, Germany
Tel: +49-211-6503-0, Fax: +49-211-6503-1327
Renesas Electronics (China) Co., Ltd.
Room 1709, Quantum Plaza, No.27 ZhiChunLu Haidian District, Beijing 100191, P.R.China
Tel: +86-10-8235-1155, Fax: +86-10-8235-7679
Renesas Electronics (Shanghai) Co., Ltd.
Unit 301, Tower A, Central Towers, 555 Langao Road, Putuo District, Shanghai, P. R. China 200333
Tel: +86-21-2226-0888, Fax: +86-21-2226-0999
Renesas Electronics Hong Kong Limited
Unit 1601-1611, 16/F., Tower 2, Grand Century Place, 193 Prince Edward Road West, Mongkok, Kowloon, Hong Kong
Tel: +852-2265-6688, Fax: +852 2886-9022
Renesas Electronics Taiwan Co., Ltd.
13F, No. 363, Fu Shing North Road, Taipei 10543, Taiwan
Tel: +886-2-8175-9600, Fax: +886 2-8175-9670
Renesas Electronics Singapore Pte. Ltd.
80 Bendemeer Road, Unit #06-02 Hyflux Innovation Centre, Singapore 339949
Tel: +65-6213-0200, Fax: +65-6213-0300
Renesas Electronics Malaysia Sdn.Bhd.
Unit 1207, Block B, Menara Amcorp, Amcorp Trade Centre, No. 18, Jln Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, Malaysia
Tel: +60-3-7955-9390, Fax: +60-3-7955-9510
Renesas Electronics India Pvt. Ltd.
No.777C, 100 Feet Road, HAL II Stage, Indiranagar, Bangalore, India
Tel: +91-80-67208700, Fax: +91-80-67208777
Renesas Electronics Korea Co., Ltd.
12F., 234 Teheran-ro, Gangnam-Gu, Seoul, 135-080, Korea
Tel: +82-2-558-3737, Fax: +82-2-558-5141
© 2016 Renesas Electronics Corporation. All rights reserved.
Colophon 5.0
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement