RA Flexible Software Package Documentation  Release v5.6.0

 
USB PMSC (r_usb_pmsc)

This module provides a USB Peripheral Mass Storage Class (PMSC) driver. It implements the USB PMSC Interface.

Functions

Refer to USB (r_usb_basic) for the common API (r_usb_basic) to be called from the application.

Detailed Description

Overview

The r_usb_pmsc module combines with the r_usb_basic module to provide USB Peripheral It operates as a Mass Storage class driver (hereinafter referred to as PMSC).
The USB peripheral mass storage class driver (PMSC) comprises a USB mass storage class bulk-only transport (BOT) protocol.
When combined with a USB peripheral control driver and media driver, it enables communication with a USB host as a BOT-compatible storage device.

Features

The r_usb_pmsc module has the following key features:

Configuration

Build Time Configurations for r_usb_pmsc

The following build time configurations are defined in fsp_cfg/r_usb_pmsc_cfg.h:

ConfigurationOptionsDefaultDescription
Bulk Input Transfer Pipe
  • USB PIPE1
  • USB PIPE2
  • USB PIPE3
  • USB PIPE4
  • USB PIPE5
USB PIPE4 Select the USB pipe to use for bulk input transfers.
Bulk Output Transfer Pipe
  • USB PIPE1
  • USB PIPE2
  • USB PIPE3
  • USB PIPE4
  • USB PIPE5
USB PIPE5 Select the USB pipe to use for bulk output transfers.
Vendor InformationVendor Information must be 8 bytes long; pad with spaces if shorter.Vendor Specify the vendor information field (part of the Inquiry command response).
Product InformationProduct Information must be 16 bytes long; pad with spaces if shorter.Mass Storage Specify the product information field (part of the Inquiry command response).
Product Revision LevelProduct Revision Level must be 4 bytes long; pad with spaces if shorter.1.00 Specify the product revision level field (part of the Inquiry command response).
Sector size
  • 512
  • 4096
512 Specifies the sector size.
Number of Transfer SectorsPlease enter a number between 1 and 255.8 Specify the maximum sector size to request with one data transfer.

Configurations for Connectivity > USB PMSC (r_usb_pmsc)

This module can be added to the Stacks tab via New Stack > Connectivity > USB PMSC (r_usb_pmsc).

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_pmsc0 Module name.

Refer to the USB (r_usb_basic) module for hardware configuration options.

Clock Configuration

Refer to the USB (r_usb_basic) module.

Pin Configuration

Refer to the USB (r_usb_basic) module.

Usage Notes

Class Requests

The class requests supported by this driver are shown below.

Request Code Description
Bulk-Only Mass Storage Reset 0xFF Resets the connection interface to the mass storage device.
Get Max Logical Unit Number 0xFE Reports the logical numbers supported by the device.

Storage Commands

This driver supports the following storage commands.

Command Code Description
TEST_UNIT_READY 0x00 Checks the state of the peripheral device.
REQUEST_SENSE 0x03 Gets the error information of the previous storage command execution result.
INQUIRY 0x12 Gets the parameter information of the logical unit.
READ_FORMAT_CAPACITY 0x23 Gets the formattable capacity.
READ_CAPACITY 0x25 Gets the capacity information of the logical unit.
READ10 0x28 Reads data.
WRITE10 0x1A Writes data.
MODE_SENSE10 0x5A Gets the parameters of the logical unit.
Note
A STALL or FAIL error is sent to the host upon receipt of any command not listed in the above table.

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 and the response status are embedded in a Command Block Wrapper (CBW) and a Command Status Wrapper (CSW). The below image shows an overview of how the BOT protocol progresses with command and status data flowing between USB host and peripheral.

r_usb_pmsc_bot_protocol_overview.svg
BOT protocol Overview

Block Media Interface

PMSC implements a block media interface to enable access to higher-level modules. If the block media interface supports multiple media, users can select any media to access.

Note
When the user develops the storage media driver, be sure to define the instance named "g_rm_block_media0".

Limitations

  1. The driver always returns 0 in response to the GetMaxLun command.
  2. The driver supports a sector size of 512 bytes only.
  3. The only media currently supported by the block media interface is an SD card. The card must be inserted before initializing the driver.
  4. When using DMA for Hi-Speed transfers continuous transfer mode must not be used in the USB Basic driver.
  5. The storage area must be formatted before use.
  6. When using the SD/MMC Block Media Implementation (rm_block_media_sdmmc), "Card Detection" must be set to "Not Used" in the SD/MMC Host Interface (r_sdhi) settings.
  7. The driver does not support Low-speed.
  8. This driver does not support simultaneous operation with USB Host device class.
  9. Please ignore the suspend or resume event occurs when attaching or detaching the USB cable.

Examples

USB PMSC Example

In this example, when the evaluation board is connected to the host PC it is recognized as a removable disk and reading/writing files is possible. The FAT type is either FAT12, FAT16, or FAT32 depending on the size of the media used.

r_usb_pmsc_operating_environment.svg
Example Operating Environment
#if (BSP_CFG_RTOS == 2)
/******************************************************************************
* Function Name : usb_apl_callback
* Description : Callback function for Application program
* Arguments : usb_event_info_t *p_api_event : Control structure for USB API.
* : usb_hdl_t cur_task : Task Handle
* : uint8_t usb_state : USB_ON(USB_STATUS_REQUEST) / USB_OFF
* Return value : none
******************************************************************************/
void usb_apl_callback (usb_event_info_t * p_api_event, usb_hdl_t cur_task, usb_onoff_t usb_state)
{
(void) usb_state;
(void) cur_task;
xQueueSend(g_apl_mbx_hdl, (const void *) &p_api_event, (TickType_t) (0));
} /* End of function usb_apl_callback */
#endif /* (BSP_CFG_RTOS == 2) */
void usb_pmsc_example (void)
{
usb_event_info_t usb_event;
#if (BSP_CFG_RTOS == 2)
usb_event_info_t * p_mess;
#else
usb_status_t event;
#endif
g_usb_on_usb.open(&g_basic0_ctrl, &g_basic0_cfg);
/* Loop back between PC(TerminalSoft) and USB MCU */
while (1)
{
#if (BSP_CFG_RTOS == 2) /* FreeRTOS */
xQueueReceive(g_apl_mbx_hdl, (void *) &p_mess, portMAX_DELAY);
event_info = *p_mess;
event = event_info.event;
#else /* (BSP_CFG_RTOS == 2) */
g_usb_on_usb.eventGet(&usb_event, &event);
#endif /* (BSP_CFG_RTOS == 2) */
switch (event)
{
{
break;
}
{
#if USB_SUPPORT_LPW == USB_APL_ENABLE
// @@ low_power_mcu();
#endif /* USB_SUPPORT_LPW == USB_APL_ENABLE */
break;
}
default:
{
break;
}
}
}
} /* End of function usb_main() */

Descriptor

A template for PMSC descriptors can be found in ra/fsp/src/r_usb_pmsc/r_usb_pmsc_descriptor.c.template. Also, please be sure to use your vendor ID.