This module provides a USB Peripheral Communications Device Class Driver (PCDC). It implements the USB PCDC Interface.
Refer to USB (r_usb_basic) for the common API (r_usb_basic) to be called from the application.
Overview
The r_usb_pcdc module combines with the r_usb_basic module to provide a USB Peripheral Communications Device Class (PCDC) driver. The PCDC driver conforms to Abstract Control Model of the USB Communications Device Class (CDC) specification and enables communication with a CDC host device.
Features
The r_usb_pcdc module has the following key features:
- Data transfer to and from a USB host
- Response to CDC class requests
- Supports CDC notifications
Configuration
Build Time Configurations for r_usb_pcdc
The following build time configurations are defined in fsp_cfg/r_usb_pcdc_cfg.h:
Configuration | Options | Default | Description |
Configurations for Connectivity > USB PCDC (r_usb_pcdc)
This module can be added to the Stacks tab via New Stack > Connectivity > USB PCDC (r_usb_pcdc).
Configuration | Options | Default | Description |
Name | Name must be a valid C symbol | g_pcdc0 | Module name. |
- Note
- 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
Abstract Control Model Overview
The Abstract Control Model subclass of CDC is a technology that bridges the gap between USB devices and earlier modems (employing RS-232C connections), enabling use of application programs designed for older modems.
Class Requests (Host to Peripheral)
This driver notifies the application when receiving the following class requests:
Request | Code | Description |
SetLineCoding | 0x20 | Sets communication line settings (bitrate, data length, parity, and stop bit length) |
GetLineCoding | 0x21 | Acquires the communication line setting state |
SetControlLineState | 0x22 | Set communication line control signals (RTS, DTR) |
- Note
- For details concerning the Abstract Control Model requests, refer to Table 11 "Requests - Abstract Control Model" in the "USB Communications Class Subclass Specification for PSTN Devices", Revision 1.2.
Data Format of Class Requests
The data format of supported class requests is described below:
Class Notifications (Peripheral to Host)
The following class notifications are supported:
Notification | Code | Description |
SERIAL_STATE | 0x20 | Notification of serial line state |
The data types returned are as follows:
- Note
- The host is notified with SERIAL_STATE whenever a change in the UART port state is detected. This driver will automatically detect overrun, parity and framing errors. A state notification is performed when a transition from normal to error state is detected.
Virtual COM-port Usage
When connected to a PC the CDC device can be used as a virtual COM port. After enumeration, the CDC class requests GetLineCoding and SetControlLineState are executed by the target, and the CDC device is registered in Windows Device Manager as a virtual COM device.
Registering the CDC device as a virtual COM-port in Windows Device Manager enables data communication with the CDC device via a terminal app such as PuTTY. When changing settings of the serial port in the terminal application, the UART setting is propagated to the firmware via the class request SetLineCoding.
Data input (or file transmission) from the terminal app window is transmitted to the board using endpoint 2 (EP2); data from the board side is transmitted to the PC using EP1.
When the last packet of data received is the maximum packet size, and the terminal determines that there is continuous data, the received data may not be displayed in the terminal. If the received data is smaller than the maximum packet size, the data received up to that point is displayed in the terminal.
Multi Port
This driver supports simultaneous operation with Host Mass Storage Class(HMSC). If the user are using MCU that supports 2 USB modules, such as RA6M3, the user can run PCDC on one USB module and HMSC on the other. This driver does not support simultaneous operation using device classes other than HMSC.
Limitations
- 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.
- Please ignore the suspend or resume event occurs when attaching or detaching the USB cable.
Examples
USB PCDC Loopback Example
The main functions of the PCDC loopback example are as follows:
- Receives virtual UART configuration data from the host terminal
- Loops all other received data back to the host terminal
Example Operating Environment
Main Loop processing (Echo mode)
#define USB_APL_YES (1U)
#define USB_APL_NO (0U)
#define APL_NUM_USB_EVENT (10U)
#define APL_USE_BAREMETAL_CALLBACK USB_APL_YES
static uint8_t g_buf[DATA_LEN];
extern uint8_t g_apl_device[];
extern uint8_t g_apl_configuration[];
extern uint8_t g_apl_hs_configuration[];
extern uint8_t g_apl_qualifier_descriptor[];
extern uint8_t * g_apl_string_table[];
#if (BSP_CFG_RTOS == 2)
QueueHandle_t g_apl_mbx_hdl;
#endif
#if (BSP_CFG_RTOS == 0) && (APL_USE_BAREMETAL_CALLBACK == USB_YES)
usb_callback_args_t g_apl_usb_event;
usb_callback_args_t g_apl_usb_event_buf[APL_NUM_USB_EVENT];
uint8_t g_apl_usb_event_wp = 0;
uint8_t g_apl_usb_event_rp = 0;
#endif
void usb_pcdc_example(void);
#if (BSP_CFG_RTOS == 0) && (APL_USE_BAREMETAL_CALLBACK == USB_YES)
void usb_apl_callback(usb_callback_args_t * p_event);
#endif
#if (BSP_CFG_RTOS == 2)
void usb_apl_callback(usb_event_info_t * p_api_event, usb_hdl_t cur_task,
usb_onoff_t usb_state);
#endif
#if (BSP_CFG_RTOS == 2)
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));
}
#endif
#if (BSP_CFG_RTOS == 0) && (APL_USE_BAREMETAL_CALLBACK == USB_YES)
void usb_apl_callback (usb_callback_args_t * p_event)
{
g_apl_usb_event_buf[g_apl_usb_event_wp] = *p_event;
g_apl_usb_event_wp++;
g_apl_usb_event_wp %= APL_NUM_USB_EVENT;
}
#endif
void usb_pcdc_example (void)
{
usb_event_info_t event_info;
#if (BSP_CFG_RTOS == 2)
usb_event_info_t * p_mess;
#endif
g_usb_on_usb.
open(&g_basic0_ctrl, &g_basic0_cfg);
#if (BSP_CFG_RTOS == 0) && (APL_USE_BAREMETAL_CALLBACK == USB_YES)
#endif
memset(&event_info, 0, sizeof(usb_event_info_t));
while (1)
{
#if (BSP_CFG_RTOS == 2)
xQueueReceive(g_apl_mbx_hdl, (void *) &p_mess, portMAX_DELAY);
event_info = *p_mess;
event = event_info.event;
#else
#if (APL_USE_BAREMETAL_CALLBACK == USB_YES)
if (g_apl_usb_event_wp != g_apl_usb_event_rp)
{
event_info = g_apl_usb_event_buf[g_apl_usb_event_rp];
g_apl_usb_event_rp++;
g_apl_usb_event_rp %= APL_NUM_USB_EVENT;
event = event_info.event;
}
#else
g_usb_on_usb.
eventGet(&event_info, &event);
#endif
#endif
switch (event)
{
break;
if (FSP_SUCCESS == event_info.status)
{
}
break;
if ((FSP_SUCCESS == event_info.status) || (FSP_ERR_USB_SIZE_SHORT == event_info.status))
{
}
break;
{
g_usb_on_usb.
periControlDataGet(&g_basic0_ctrl, (uint8_t *) &g_line_coding, LINE_CODING_LENGTH);
}
{
g_usb_on_usb.
periControlDataSet(&g_basic0_ctrl, (uint8_t *) &g_line_coding, LINE_CODING_LENGTH);
}
else
{
}
break;
break;
default:
break;
}
}
}
Descriptor
A template for PCDC descriptors can be found in ra/fsp/src/r_usb_pcdc/r_usb_pcdc_descriptor.c.template. Also, please be sure to use your vendor ID.