|
fsp_err_t | R_USB_HMSC_StorageCommand (usb_ctrl_t *const p_api_ctrl, uint8_t *buf, uint8_t command, uint8_t destination) |
| Processing for MassStorage(ATAPI) command. More...
|
|
fsp_err_t | R_USB_HMSC_DriveNumberGet (usb_ctrl_t *const p_api_ctrl, uint8_t *p_drive, uint8_t destination) |
| Get number of Storage drive. More...
|
|
fsp_err_t | R_USB_HMSC_SemaphoreGet (void) |
| Get a semaphore. (RTOS only) More...
|
|
fsp_err_t | R_USB_HMSC_SemaphoreRelease (void) |
| Release a semaphore. (RTOS only) More...
|
|
fsp_err_t | R_USB_HMSC_StorageReadSector (uint16_t drive_number, uint8_t *const buff, uint32_t sector_number, uint16_t sector_count) |
| Read sector information. More...
|
|
fsp_err_t | R_USB_HMSC_StorageWriteSector (uint16_t drive_number, uint8_t const *const buff, uint32_t sector_number, uint16_t sector_count) |
| Write sector information. More...
|
|
This module provides a USB Host Mass Storage Class (HMSC) driver. It implements the USB HMSC Interface.
Overview
The r_usb_hmsc module, when used in combination with the r_usb_basic module, operates as a USB Host Mass Storage Class (HMSC) driver. It is built on the USB Mass Storage Class Bulk-Only Transport (BOT) protocol. It is possible to communicate with BOT-compatible USB storage devices by combining this module with a file system and storage device driver.
- Note
- This module should be used in combination with the FreeRTOS+FAT File System.
Features
The r_usb_hmsc module has the following key features:
- Checking of connected USB storage devices to determine whether or not operation is supported
- Storage command communication using the BOT protocol
- Support for SFF-8070i (ATAPI) USB mass storage subclass
- Sharing of a single pipe for IN/OUT directions or multiple devices
Class Requests
The class requests supported by this driver are shown below.
Request | Description |
GetMaxLun | Gets the maximum number of units that are supported. |
MassStorageReset | Cancels a protocol error. |
Storage Commands
This driver supports the following storage commands:
- TEST_UNIT_READY
- MODE_SELECT10
- MODE_SENSE10
- PREVENT_ALLOW
- READ_FORMAT_CAPACITY
- READ10
- WRITE10
Configuration
Refer to the USB (r_usb_basic) module.
Clock Configuration
Refer to the USB (r_usb_basic) module.
Pin Configuration
Refer to the USB (r_usb_basic) module.
Usage Notes
- Warning
- Due to the wide variety of USB mass storage device implementations, this driver is not guaranteed to work with all devices. When implementing the driver it is important to verify correct operation with the mass storage devices that the end user is expected to use.
For Bare Metal
- To use FreeRTOS+FAT without FreeRTOS, copy FreeRTOSConfigMinimal.h to one of your project's include paths and rename it FreeRTOSConfig.h.
- In configurator, enter the appropriate values in the Main stack size and Heap size fields.
- In the Bare Metal version, specify "NULL" in the Callback item.
For Bare Metal Setting
Limitations
- Some MSC devices may be unable to connect because they are not recognized as storage devices.
- MSC devices that return values of 1 or higher in response to the GetMaxLun command (mass storage class command) are not supported.
- Only USB storage devices with a sector size of 512 bytes can be connected.
- A device that does not respond to the READ_CAPACITY command operates as a device with a sector size of 512 bytes.
- This module must be incorporated into a project using r_usb_basic and does not provide any public APIs.
- This driver does not support Low-speed.
- This driver does not support FreeRTOS operation.
Examples
USB HMSC Example
Example Operating Environment
The following shows an example operating environment for the HMSC.
Refer to the associated instruction manuals for details on setting up the evaluation board and using the emulator, etc.
Example Operating Environment
Application Specifications
The main functions of the application are as follows:
- Performs enumeration and drive recognition processing on MSC devices.
- After the above processsing finisihes, the application writes the file to the MSC device once.
- After writing the above file, the APL repeatedly reads the file. It continues to read the file repeatedly until the switch is pressed again.
Example Code
- Note
- In order to get the example code below to be workable, Has CWD in FreeRTOS+FAT configuration below should be enabled.
FreeRTOS+FAT configuration for Exmaple Code
#define RM_FREERTOS_PLUS_FAT_EXAMPLE_FILE_NAME "TEST_FILE.txt"
#define RM_FREERTOS_PLUS_FAT_EXAMPLE_BUFFER_SIZE_BYTES (10240)
#define RM_FREERTOS_PLUS_FAT_EXAMPLE_PARTITION_NUMBER (0)
#define RM_FREERTOS_PLUS_FAT_EXAMPLE_SUPPORT_USB
typedef enum
{
STATE_ATTACH, STATE_DATA_READY, STATE_DATA_WRITE, STATE_FILE_READ, STATE_DETACH, STATE_ERROR,
} state_t;
extern const rm_freertos_plus_fat_cfg_t g_rm_freertos_plus_fat0_cfg;
uint8_t g_file_data[RM_FREERTOS_PLUS_FAT_EXAMPLE_BUFFER_SIZE_BYTES];
uint8_t g_read_buffer[RM_FREERTOS_PLUS_FAT_EXAMPLE_BUFFER_SIZE_BYTES];
static uint16_t g_state = STATE_DETACH;
void usb_hmsc_baremetal_example (void)
{
uint16_t i;
uint16_t k;
FF_FILE * pxSourceFile;
FF_Disk_t disk;
usb_event_info_t event_info;
FF_Error_t ff_err;
size_t size_return;
int close_err;
for (i = 0; i < RM_FREERTOS_PLUS_FAT_EXAMPLE_BUFFER_SIZE_BYTES; i++)
{
g_file_data[i] = (uint8_t) i;
}
#ifdef RM_FREERTOS_PLUS_FAT_EXAMPLE_SUPPORT_USB
while (1)
{
g_usb_on_usb.
eventGet(&event_info, &event);
switch (event)
{
{
p_instance_ctrl = event_info.p_context;
p_instance_ctrl->device_address = event_info.device_address;
FF_Mount(&disk, RM_FREERTOS_PLUS_FAT_EXAMPLE_PARTITION_NUMBER);
FF_FS_Add("/", &disk);
pxSourceFile = ff_fopen((const char *) RM_FREERTOS_PLUS_FAT_EXAMPLE_FILE_NAME, "w");
ff_fwrite(g_file_data, sizeof(g_file_data), 1, pxSourceFile);
ff_fclose(pxSourceFile);
g_state = STATE_FILE_READ;
break;
}
{
g_state = STATE_DETACH;
break;
}
default:
{
break;
}
}
if (STATE_FILE_READ == g_state)
{
pxSourceFile = ff_fopen((const char *) RM_FREERTOS_PLUS_FAT_EXAMPLE_FILE_NAME, "r");
for (k = 0; k < RM_FREERTOS_PLUS_FAT_EXAMPLE_BUFFER_SIZE_BYTES; k++)
{
g_read_buffer[k] = (uint8_t) 0;
}
size_return = ff_fread(g_read_buffer, sizeof(g_file_data), 1, pxSourceFile);
close_err = ff_fclose(pxSourceFile);
}
}
#endif
}
◆ R_USB_HMSC_StorageCommand()
fsp_err_t R_USB_HMSC_StorageCommand |
( |
usb_ctrl_t *const |
p_api_ctrl, |
|
|
uint8_t * |
buf, |
|
|
uint8_t |
command, |
|
|
uint8_t |
destination |
|
) |
| |
Processing for MassStorage(ATAPI) command.
- Return values
-
FSP_SUCCESS | Success. |
FSP_ERR_USB_FAILED | The function could not be completed successfully. |
FSP_ERR_ASSERTION | Parameter Null pointer error. |
FSP_ERR_USB_PARAMETER | Parameter error. |
◆ R_USB_HMSC_DriveNumberGet()
fsp_err_t R_USB_HMSC_DriveNumberGet |
( |
usb_ctrl_t *const |
p_api_ctrl, |
|
|
uint8_t * |
p_drive, |
|
|
uint8_t |
destination |
|
) |
| |
Get number of Storage drive.
- Return values
-
FSP_SUCCESS | Success. |
FSP_ERR_USB_FAILED | The function could not be completed successfully. |
FSP_ERR_ASSERTION | Parameter Null pointer error. |
FSP_ERR_USB_PARAMETER | Parameter error. |
◆ R_USB_HMSC_SemaphoreGet()
Get a semaphore. (RTOS only)
If this function is called in the OS less execution environment, a failure is returned.
- Return values
-
FSP_SUCCESS | Success. |
FSP_ERR_USB_FAILED | The function could not be completed successfully. |
◆ R_USB_HMSC_SemaphoreRelease()
fsp_err_t R_USB_HMSC_SemaphoreRelease |
( |
void |
| ) |
|
Release a semaphore. (RTOS only)
If this function is called in the OS less execution environment, a failure is returned.
- Return values
-
FSP_SUCCESS | Success. |
FSP_ERR_USB_FAILED | The function could not be completed successfully. |
◆ R_USB_HMSC_StorageReadSector()
fsp_err_t R_USB_HMSC_StorageReadSector |
( |
uint16_t |
drive_number, |
|
|
uint8_t *const |
buff, |
|
|
uint32_t |
sector_number, |
|
|
uint16_t |
sector_count |
|
) |
| |
Read sector information.
- Return values
-
FSP_SUCCESS | Success. |
FSP_ERR_USB_FAILED | The function could not be completed successfully. |
FSP_ERR_ASSERTION | Parameter Null pointer error. |
FSP_ERR_USB_PARAMETER | Parameter error. |
- Note
- The address specified in the argument buff must be 4-byte aligned.
◆ R_USB_HMSC_StorageWriteSector()
fsp_err_t R_USB_HMSC_StorageWriteSector |
( |
uint16_t |
drive_number, |
|
|
uint8_t const *const |
buff, |
|
|
uint32_t |
sector_number, |
|
|
uint16_t |
sector_count |
|
) |
| |
Write sector information.
- Return values
-
FSP_SUCCESS | Success. |
FSP_ERR_USB_FAILED | The function could not be completed successfully. |
FSP_ERR_ASSERTION | Parameter Null pointer error. |
FSP_ERR_USB_PARAMETER | Parameter error. |
- Note
- The address specified in the argument buff must be 4-byte aligned.