R01an2026ej0131 Usb
R01an2026ej0131 Usb
R01AN2026EJ0131
RX Family Rev.1.31
Mar 1, 2021
USB Host Mass Storage Class Driver (HMSC) using Firmware Integration Technology
Introduction
This application note describes USB Host Mass Storage Class Driver (HMSC), which utilizes Firmware Integration
Technology (FIT). This module operates in combination with the USB Basic Host and Peripheral Driver
(USB-BASIC-FW FIT module). It is referred to below as the USB HMSC FIT module.
Target Device
RX65N/RX651 Group
RX64M Group
RX71M Group
RX66T Group
RX72T Group
RX72M Group
RX66N Group
RX72N Group
RX671 Group
When using this application note with other Renesas MCUs, careful evaluation is recommended after making
modifications to comply with the alternate
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
http://www.usb.org/developers/docs/
4. RX64M Group User’s Manual: Hardware (Document number: R01UH0377)
5. RX71M Group User’s Manual: Hardware (Document number: R01UH0493)
6. RX65N/RX651 Group User’s Manual: Hardware (Document number: R01UH0590)
7. RX65N/RX651-2M Group User’s Manual: Hardware (Document number: R01UH0659)
8. RX66T User's Manual: Hardware (Document number. R01UH0749)
9. RX72T User's Manual: Hardware (Document number. R01UH0803)
10. RX72M User's Manual: Hardware (Document number. R01UH0804)
11. RX66N User's Manual: Hardware (Document number. R01UH0825)
12. RX72N User's Manual: Hardware (Document number. R01UH0824)
13. RX671 User's Manual: Hardware (Document number. R01UH0899)
14. RX Family M3S-TFAT-Tiny: FAT file system software (Document number: R20AN0038)
15. RX Family M3S-TFAT-Tiny: Memory Driver Interface Module (Document number: R20AN0335)
16. USB Basic Host and Peripheral Driver using Firmware Integration Technology Application Note
(Document number. R01AN2025)
Contents
1. Overview .......................................................................................................................................... 3
2. Software Configuration................................................................................................................... 5
3. API Information................................................................................................................................ 6
1. Overview
The USB HMSC FIT module, when used in combination with the USB-BASIC-FW FIT module, operates as a USB
host mass storage class driver (HMSC).
The HMSC comprises a USB mass storage class bulk-only transport (BOT) protocol. When combined with a file
system and storage device driver, it enables communication with a BOT-compatible USB storage device.
Note that please use the M3S-TFAT-Tiny (Document number: R20AN0038) and Memory driver interface module
(Document numver: R20AN0335) in combination when using this driver.
1.2 Note
1. This driver is not guaranteed to provide USB communication operation. The customer should verify operation
when utilizing it in a system and confirm the ability to connect to a variety of different types of devices.
2. This driver is confirmed for operation in combination with the following FAT.
RX Family Open Source FAT File System [M3S-TFAT-Tiny] Module
Firmware Integration Technology Rev.3.03
1.3 Limitation
1. Some MSC devices may be unable to be connected (because they are not recognized as storage devices).
2. MSC devices that return values of 1 or higher in response to the GetMaxLun command (mass storage class
command) are not supported.
3. Maximum 4 USB storage devices can be connected.
4. USB storage devices with a sector size of 512 bytes can be connected.
5. A device that does not respond to the READ_CAPACITY command operates as a device with a sector size of
512 bytes.
2. Software Configuration
HDCD (Host Device Class Driver) is the all-inclusive term for HMSDD (Host Mass Storage Device Driver) and
HMSCD (USB Host Mass Storage Class Driver).
Figure 2-1 shows the HMSC software block diagram, with HDCD as the centerpiece. Table 2-1 describes each
module.
Mass Storage
Device Class
Class Driver
(HMSCD)
3. API Information
This Driver API follows the Renesas API naming standards.
Table 3-2 shows the interrupt vector which this driver uses.
Table 3-2 List of Usage Interrupt Vectors
Device Contents
RX64M USBI0 Interrupt (Vector number: 189, Interrupt source number:62, Software Configurable Interrupt B)
RX71M USB D0FIFO0 Interrupt (Vector number: 34) / USB D1FIFO0 Interrupt (Vector number: 35)
USBR0 Interrupt (Vector number:90)
USBAR Interrupt (Vector number: 94)
USB D0FIFO2 Interrupt (Vector number: 32) / USB D1FIFO2 Interrupt (Vector number: 33)
RX65N USBI0 Interrupt (Vector number: 185, Interrupt source number:62, Software Configurable Interrupt B)
RX651 USB D0FIFO0 Interrupt (Vector number: 34) / USB D1FIFO0 Interrupt (Vector number: 35)
RX72M USBR0 Interrupt (Vector number:90)
RX72N
RX66N
RX66T USBI0 Interrupt (Vector number: 174) / USBR0 Interrupt (Vector number: 90)
RX72T USB D0FIFO0 Interrupt (Vector number: 34) / USB D1FIFO0 Interrupt (Vector number: 35)
RX671 USBI0 Interrupt (Vector number: 185, Interrupt source number:62, Software Configurable Interrupt B)
USB D0FIFO0 Interrupt (Vector number: 34) / USB D1FIFO0 Interrupt (Vector number: 35)
USBR0 Interrupt (Vector number:90)
USBI1 Interrupt (Vector number: 182, Interrupt source number:63, Software Configurable Interrupt B)
USB D0FIFO1 Interrupt (Vector number: 36) / USB D1FIFO1 Interrupt (Vector number: 37)
All API calls and their supporting interface definitions are located in r_usb_basic_if.h and r_usb_hmsc_if.h.
This project uses ANSI C99 “Exact width integer types” in order to make the code clearer and more portable. These
types are defined in stdint.h.
(2). RTOS
a. FreeRTOS
Checks arguments Does not check arguments
ROM size 54.2K bytes (Note 4) 53.7K bytes (Note 5)
RAM size 51.2K bytes 51.2K bytes
b. RI600V4
Checks arguments Does not check arguments
ROM size 56.4K bytes (Note 4) 55.9K bytes (Note 5)
RAM size 28.3K bytes 28.3K bytes
[Note]
1. ROM/RAM size for BSP and USB Basic Driver is included in the above size.
2. ROM/RAM size for TFAT is not included in the above size.
3. The above is the size when specifying RX V2 core option.
4. The ROM size of “Checks arguments” is the value when USB_CFG_ENABLE is specified to
USB_CFG_PARAM_CHECKING definition in r_usb_basic_config.h file.
5. The ROM size of “Does not check arguments” is the value when USB_CFG_DISABLE is specified to
USB_CFG_PARAM_CHECKING definition in r_usb_basic_config.h file.
6. The result of RTOS includes the ROM/RAM size of the real-time OS.
3.9 Argument
For the structure used in the argument of API function, refer to chapter "Structures" in the document (Document
number: R01AN2025) for USB Basic Host and Peripheral Driver using Firmware Integration Technology
Application Note.
This module must be added to each project in which it is used. Renesas recommends the method using the Smart
Configurator described in (1) or (3) below. However, the Smart Configurator only supports some RX devices. Please
use the methods of (2) or (4) for RX devices that are not supported by the Smart Configurator.
(1) Adding the FIT module to your project using “Smart Configurator” on e2 studio
By using the Smart Configurator in e2 studio, the FIT module is automatically added to your project. Refer to
“Renesas e2 studio Smart Configurator User Guide (R20AN0451)” for details.
(2) Adding the FIT module to your project using the FIT Configurator in e2 studio
By using the FIT Configurator in e2 studio, the FIT module is automatically added to your project. Refer to
“Adding Firmware Integration Technology Modules to Projects (R01AN1723)” for details.
(3) Adding the FIT module to your project using the Smart Configurator in CS+
By using the Smart Configurator Standalone version in CS+, the FIT module is automatically added to your
project. Refer to “Renesas e2 studio Smart Configurator User Guide (R20AN0451)” for details.
5. Class Driver
5.1 Class Requet
This driver supports the following class request.
2. REQUEST_SENSE
3. MODE_SELECT10
4. MODE_SENSE10
5. PREVENT_ALLOW
6. READ_FORMAT_CAPACITY
7. READ10
8. WRITE10
6. API Functions
The following are Host Mass Storage Class specific API functions
API Desription
R_USB_HmscStrgCmd() Issues a Mass Storage command.
R_USB_HmscGetDriveNo() Obtains the drive number.
R_USB_HmscGetSem() Gets a semaphore (Only RTOS)
R_USB_HmscRelSem() Releases a semaphore (Only RTOS)
Note:
1. Uses the FAT (File Allocation Table) API to access storage media.
2. Refer to chapter "API" in the document (Document number: R01AN2025) for USB Basic Host and Peripheral
Driver using Firmware Integration Technology Application Note. when using other API.
6.1 R_USB_HmscStrgCmd
Format
usb_err_t R_USB_HmscStrgCmd(usb_ctrl_t *p_ctrl, uint8_t *p_buf, uint16_t command)
Arguments
p_ctrl Pointer to usb_ctrl_t structure area
p_buf Pointer to data area
command Mass storage command
Return Value
USB_SUCCESS Successfully completed
USB_ERR_PARA Parameter error
USB_ERR_NG Other error
Description
1. Non-OS
The Mass Storage command assigned to the argument (command) is issued to the MSC device that is specifed by
the members (address and module) in the argument (p_ctrl). An application program can check the completion of
the Mass Storage command with the USB_STS_MSC_CMD_COMPLETE return value of the R_USB_GetEvent
function.
If a Mass Storage command with response data is issued, after checking USB_STS_MSC_CMD_COMPLETE
return value of the R_USB_GetEvent function, an application program can obtain the response data from the area
indicated by the second argument (p_buf). Check the member (size) of the usb_crtl_t structure to get the size of
the response data that was received.
2. RTOS
The Mass Storage command assigned to the argument (command) is issued to the MSC device that is specifed by
the members (address and module) in the argument (p_ctrl). An application program can check whether the mass
storage command complete by refering the argument (the member (event) of the usb_ctrl_t structure) in the
callback function. This driver sets USB_STS_MSC_CMD_COMPLETE to the argument (the event member of the
usb_ctrl_t structure) when completing a Mass Storage command.
If a Mass Storage command with response data is issued, after checking that USB_STS_MSC_CMD_COMPLETE
is set to the argument (the member (event) of the usb_ctrl_t structure), an application program can obtain the
response data from the area indicated by the second argument (p_buf). Check the member (size) of the usb_crtl_t
structure to get the size of the response data that was received.
For both Non-OS and RTOS, assign the following to the argument (command).
Note
1. Before calling this API, assign the module number to the member (module) and the device address to the
member (address). If something other than USB_IP0 or USB_IP1 is assigned to the member (module), then
USB_ERR_PARA will be the return value.
2. If the MCU being used only supports one USB module, then do not assign USB_IP1 to t the member (module).
If USB_IP1 is assigned, then USB_ERR_PARA will be the return value.
3. If USB_NULL is assigned to the argument (p_ctrl), then USB_ERR_PARA will be the return value.
4. Do not assign a pointer to the auto variable (stack) area to the arguments (p_buf).
5. Assign USB_NULL to the argument (p_buf) when issuing the mass storage command without the response data.
6. If a command other than the Mass Storage commands listed in Table 6-1 is assigned to the argument
(command), then USB_ERR_PARA will be the return value.
7. When calling FAT API and this API after issuing the Mass storage command by this API, be sure to call these
APIs after checking the return value (USB_STS_CMD_COMPLETE) of R_USB_GetEvent function.
8. Refer to chapter "7. Return Value (USB_STS_MSC_CMD_COMPLETED) of a Mass Stoage Commnad"
about CSW.
9. The CSW information is set to the member (status) of the usb_ctrl_t structure. If the value of the member
(status) is USB_CSW_FAIL, issue the "Requeset Sense" command to the MSC device using this API.
10. Set the page code (1 Byte) of the "Mode Sense10" command in the start address to the area indicated by the 2nd
argument (p_buf).
11. Set the parameter data for the "Mode Select10" command to the area indicated by the 2nd argument (p_buf)
based on the specification for USB Mass Storage Subclass (SFF-8070i etc).
12. This function can be called when the USB device is in the configured state. When the API is called in any other
state, USB_ERR_NG is returned.
Example
1. Non-OS
void usb_application( void )
{
usb_ctrl_t ctrl;
usb_err_t err;
:
while (1)
{
switch (R_USB_GetEvent(&ctrl))
{
:
case USB_STS_CONFIGURED:
:
g_buf[0] = 0x3F; /* Page Code */
ctrl.module = USB_IP1;
ctrl.address = adr;
R_USB_HmscStrgCmd( &ctrl, &g_buf, USB_ATAPI_MODE_SENSE10 );
:
break;
case USB_STS_MSC_CMD_COMPLETE:
if( ctrl.status == USB_CSW_FAIL )
{
R_USB_HmscStrgCmd(&ctrl, &g_buf, USB_ATAPI_REQUEST_SENSE);
}
:
break;
:
}
}
}
2. RTOS
/* Callback function */
void usb_apl_callback (usb_ctrl_t *p_ctr, rtos_task_id_t task_id, uint8_t is_request)
{
USB_APL_SND_MSG(USB_APL_MBX, (usb_msg_t *)p_ctrl);
}
6.2 R_USB_HmscGetDriveNo
Format
usb_err_t R_USB_HmscGetDriveNo(usb_ctrl_t *p_ctrl, uint8_t *p_drive)
Arguments
p_ctrl Pointer to usb_ctrl_t structure area
p_drive Pointer to the area to store the drive number
Return Value
USB_SUCCESS Successfully completed
USB_ERR_PARA Parameter error
USB_ERR_NG Other error
Description
Based on the information assigned to the usb_crtl_t structure (the member module and address), obtains the
related drive number. The drive number is stored in the area indicated by the argument (p_drive).
Note
1. Before calling this API, assign the device address of the MSC device whose drive number is to be obtained, and
the USB module number (USB_IP0 or USB_IP1) connected to that MSC device, to the members (address and
module) of the usb_crtl_t structure. If there is a problem with what is assigned to these members, then
USB_ERR_PARA will be the return value.
2. If USB_NULL is assigned to the argument (p_ctrl), then USB_ERR_PARA will be the return value.
3. This function can be called when the USB device is in the configured state. When the API is called in any other
state, USB_ERR_NG is returned.
Example
void usb_application( void )
{
usb_ctrl_t ctrl;
uint8_t drive;
:
while (1)
{
switch (R_USB_GetEvent(&ctrl))
{
:
case USB_STS_CONFIGURED:
:
ctrl.module = USB_IP0;
ctrl.address = adr;
R_USB_HmscGetDriveNo( &ctrl, &drive );
:
break;
:
}
}
}
6.3 R_USB_HmscGetSem
Format
void R_USB_HmscGetSem(void)
Arguments
none
Return Value
none
Description
Gets a specific semaphore which is used in HMSC driver.
Note
1. Be sure to call this API before calling the FAT file open function (e.g R_tfat_f_open).
2. If this API is called when a semapohre counter value is zero, the user task which calls this API shift to a
semaphore waiting status.
3. The creation processing of a semaphore which this API uses is performed in USB driver.
Example
/* Callback function */
void usb_apl_callback (usb_ctrl_t *p_ctr, rtos_task_id_t task_id, uint8_t is_request)
{
USB_APL_SND_MSG(USB_APL_MBX, (usb_msg_t *)p_ctrl);
}
void usb_application_task( void )
{
usb_ctrl_t ctrl;
usb_ctrl_t *p_mess;
:
while(1)
{
USB_APL_RCV_MSG(USB_APL_MBX, (usb_msg_t **)&p_mess);
ctrl = *p_mess;
switch (ctrl.event)
{
:
case USB_STS_CONFIGURED:
:
R_USB_HmscGetSem();
R_tfat_f_open(&file, (const char *) &g_msc_file[drvno][0],
(TFAT_FA_CREATE_ALWAYS | TFAT_FA_WRITE));
R_tfat_f_write(&file, g_file_data, sizeof(g_file_data), &file_size);
R_tfat_f_close(&file);
R_USB_HmscRelSem();
:
break;
:
}
}
}
6.4 R_USB_HmscRelSem
Format
void R_USB_HmscRelSem(void)
Arguments
none
Return Value
none
Description
Releases a specific semaphore which is used in HMSC driver.
Note
1. Be sure to call this API after calling the FAT file close function (e.g R_tfat_f_close).
2. An application task during a semaphore waiting status by R_USB_HmscGetSem function is released the
semaphore waiting status by this API.
3. The creation processing of a semaphore which this API uses is performed in USB driver.
Example
/* Callback function */
void usb_apl_callback (usb_ctrl_t *p_ctr, rtos_task_id_t task_id, uint8_t is_request)
{
USB_APL_SND_MSG(USB_APL_MBX, (usb_msg_t *)p_ctrl);
}
void usb_application_task( void )
{
usb_ctrl_t ctrl;
usb_ctrl_t *p_mess;
:
while(1)
{
USB_APL_RCV_MSG(USB_APL_MBX, (usb_msg_t **)&p_mess);
ctrl = *p_mess;
switch (ctrl.event)
{
:
case USB_STS_CONFIGURED:
:
R_USB_HmscGetSem();
R_tfat_f_open(&file, (const char *) &g_msc_file[drvno][0],
(TFAT_FA_CREATE_ALWAYS | TFAT_FA_WRITE));
R_tfat_f_write(&file, g_file_data, sizeof(g_file_data), &file_size);
R_tfat_f_close(&file);
R_USB_HmscRelSem();
:
break;
:
}
}
}
(2). RTOS
When a Mass Storage command completes, the callback function that has been registered using the
R_USB_Callback function will be called by the USB driver. At this time, USB_STS_MSC_CMD_COMPLETE will
be set to the member (event) in the argument (the pointer to the usb_ctrl_t structure) of this callback function.
The following shows the information which is set to the member in the usb_ctrl_t structure when completing Mass
Storage command.
module : USB module number where Mass Storage command has been completed.
address : Device address of USB device where Mass Storage command has been completed.
size : Size of response data
status : CSW information
Note:
1. The member (module) of the usb_ctrl_t structure has the USB module number (USB_IP0 / USB_IP1) connected
to that USB device. The member (address) has the device address of the USB device where the Mass Storage
command has been completed.
2. The member (size) has the size of the response data sent from MSC device.
3. The member (status) has bCSWStatus of the CSW (Command Status Wrapper):
USB_CSW_SUCCESS (Value: 00H) : Successful
USB_CSW_FAIL (Value: 01H) : Failed
USB_CSW_PHASE (Value: 02H) : Phase error
2. Mailbox 2
name : ID_USB_RTOS_HMSC_REQ_MBX
wait_queue : TA_FIFO
message_queue : TA_MFIFO
9. Creating an Application
Refer to the chapter “Creating an Application Program” in the document (Document number: R01AN2025) for
USB Basic Host and Peripheral Driver using Firmware Integration Technology Application Note.
All trademarks and registered trademarks are the property of their respective owners.
A-1
General Precautions in the Handling of Microprocessing Unit and Microcontroller
Unit Products
The following usage notes are applicable to all Microprocessing unit and Microcontroller unit 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.
Trademarks
Renesas and the Renesas logo are trademarks of Renesas Electronics
Corporation. All trademarks and registered trademarks are the property
of their respective owners.