RA Flexible Software Package Documentation  Release v5.4.0

 
USB (r_usb_basic)

Functions

fsp_err_t R_USB_EventGet (usb_ctrl_t *const p_api_ctrl, usb_status_t *event)
 Obtains completed USB related events. (OS-less Only) More...
 
fsp_err_t R_USB_Callback (usb_callback_t *p_callback)
 Register a callback function to be called upon completion of a USB related event. (RTOS only) More...
 
fsp_err_t R_USB_Open (usb_ctrl_t *const p_api_ctrl, usb_cfg_t const *const p_cfg)
 Applies power to the USB module specified in the argument (p_ctrl). More...
 
fsp_err_t R_USB_Close (usb_ctrl_t *const p_api_ctrl)
 Terminates power to the USB module specified in argument (p_ctrl). USB0 module stops when USB_IP0 is specified to the member (module), USB1 module stops when USB_IP1 is specified to the member (module). More...
 
fsp_err_t R_USB_Read (usb_ctrl_t *const p_api_ctrl, uint8_t *p_buf, uint32_t size, uint8_t destination)
 Bulk/Interrupt data transfer. More...
 
fsp_err_t R_USB_Write (usb_ctrl_t *const p_api_ctrl, uint8_t const *const p_buf, uint32_t size, uint8_t destination)
 Bulk/Interrupt data transfer. More...
 
fsp_err_t R_USB_Stop (usb_ctrl_t *const p_api_ctrl, usb_transfer_t direction, uint8_t destination)
 Requests a data read/write transfer be terminated when a data read/write transfer is being performed. More...
 
fsp_err_t R_USB_Suspend (usb_ctrl_t *const p_api_ctrl)
 Sends a SUSPEND signal from the USB module assigned to the member (module) of the usb_crtl_t structure. More...
 
fsp_err_t R_USB_Resume (usb_ctrl_t *const p_api_ctrl)
 Sends a RESUME signal from the USB module assigned to the member (module) of the usb_ctrl_tstructure. More...
 
fsp_err_t R_USB_VbusSet (usb_ctrl_t *const p_api_ctrl, uint16_t state)
 Specifies starting or stopping the VBUS supply. More...
 
fsp_err_t R_USB_InfoGet (usb_ctrl_t *const p_api_ctrl, usb_info_t *p_info, uint8_t destination)
 Obtains completed USB-related events. More...
 
fsp_err_t R_USB_PipeRead (usb_ctrl_t *const p_api_ctrl, uint8_t *p_buf, uint32_t size, uint8_t pipe_number)
 Requests a data read (Bulk/Interrupt transfer) via the pipe specified in the argument. More...
 
fsp_err_t R_USB_PipeWrite (usb_ctrl_t *const p_api_ctrl, uint8_t *p_buf, uint32_t size, uint8_t pipe_number)
 Requests a data write (Bulk/Interrupt transfer). More...
 
fsp_err_t R_USB_PipeStop (usb_ctrl_t *const p_api_ctrl, uint8_t pipe_number)
 Terminates a data read/write operation. More...
 
fsp_err_t R_USB_UsedPipesGet (usb_ctrl_t *const p_api_ctrl, uint16_t *p_pipe, uint8_t destination)
 Gets the selected pipe number (number of the pipe that has completed initalization) via bit map information. More...
 
fsp_err_t R_USB_PipeInfoGet (usb_ctrl_t *const p_api_ctrl, usb_pipe_t *p_info, uint8_t pipe_number)
 Gets the following pipe information regarding the pipe specified in the argument (p_ctrl) member (pipe): endpoint number, transfer type, transfer direction and maximum packet size. More...
 
fsp_err_t R_USB_PullUp (usb_ctrl_t *const p_api_ctrl, uint8_t state)
 This API enables or disables pull-up of D+/D- line. More...
 
fsp_err_t R_USB_HostControlTransfer (usb_ctrl_t *const p_api_ctrl, usb_setup_t *p_setup, uint8_t *p_buf, uint8_t device_address)
 Performs settings and transmission processing when transmitting a setup packet. More...
 
fsp_err_t R_USB_PeriControlDataGet (usb_ctrl_t *const p_api_ctrl, uint8_t *p_buf, uint32_t size)
 Receives data sent by control transfer. More...
 
fsp_err_t R_USB_PeriControlDataSet (usb_ctrl_t *const p_api_ctrl, uint8_t *p_buf, uint32_t size)
 Performs transfer processing for control transfer. More...
 
fsp_err_t R_USB_PeriControlStatusSet (usb_ctrl_t *const p_api_ctrl, usb_setup_status_t status)
 Set the response to the setup packet. More...
 
fsp_err_t R_USB_RemoteWakeup (usb_ctrl_t *const p_api_ctrl)
 Sends a remote wake-up signal to the connected Host. More...
 
fsp_err_t R_USB_DriverActivate (usb_ctrl_t *const p_api_ctrl)
 Activate USB Driver for USB Peripheral BareMetal. More...
 
fsp_err_t R_USB_CallbackMemorySet (usb_ctrl_t *const p_api_ctrl, usb_callback_args_t *p_callback_memory)
 Set callback memory to USB Driver for USB Peripheral BareMetal. More...
 
fsp_err_t R_USB_ModuleNumberGet (usb_ctrl_t *const p_api_ctrl, uint8_t *module_number)
 This API gets the module number. More...
 
fsp_err_t R_USB_ClassTypeGet (usb_ctrl_t *const p_api_ctrl, usb_class_t *class_type)
 This API gets the class type. More...
 
fsp_err_t R_USB_DeviceAddressGet (usb_ctrl_t *const p_api_ctrl, uint8_t *device_address)
 This API gets the device address. More...
 
fsp_err_t R_USB_PipeNumberGet (usb_ctrl_t *const p_api_ctrl, uint8_t *pipe_number)
 This API gets the pipe number. More...
 
fsp_err_t R_USB_DeviceStateGet (usb_ctrl_t *const p_api_ctrl, uint16_t *state)
 This API gets the state of the device. More...
 
fsp_err_t R_USB_DataSizeGet (usb_ctrl_t *const p_api_ctrl, uint32_t *data_size)
 This API gets the read data size. More...
 
fsp_err_t R_USB_SetupGet (usb_ctrl_t *const p_api_ctrl, usb_setup_t *setup)
 This API gets the setup information. More...
 
fsp_err_t R_USB_OtgCallbackSet (usb_ctrl_t *const p_api_ctrl, usb_otg_callback_t *p_callback)
 Set callback function to be called when the OTG role swap was completed on Azure RTOS. More...
 
fsp_err_t R_USB_OtgSRP (usb_ctrl_t *const p_api_ctrl)
 Start the SRP processing for OTG on Azure RTOS. More...
 
fsp_err_t R_USB_TypeCInfoGet (usb_ctrl_t *const p_api_ctrl, usb_typec_info_t *p_info)
 USB Type-C connect Information get. More...
 

Detailed Description

Driver for the USB peripheral on RA MCUs. This module implements the USB Interface.

Overview

The USB module operates in combination with the device class drivers provided by Renesas to form a complete USB stack.

Features

The USB module has the following key features:

Note
Supported speeds are dependent on the MCU.

Support Device Class

This driver supports the following device classes.

Host/Peripheral Device Class BareMetal FreeRTOS AzureRTOS
Host HCDC (ACM) Yes Yes Yes
HCDC (ECM) Yes
HHID Yes Yes Yes
HMSC Yes Yes Yes
HPRN Yes
HUVC Yes
HVND Yes Yes
HCDC+HMSC (Composite) Yes
Peripheral PCDC Yes Yes Yes
PHID Yes Yes Yes
PMSC Yes Yes Yes
PPRN Yes Yes Yes
PAUD Yes
DFU Yes
PVND Yes Yes
PCDC+PMSC Yes Yes Yes
PHID+PMSC Yes Yes
PCDC+PHID Yes Yes
PCDC+PCDC Yes Yes
PHID+PHID Yes Yes
PCDC+PVND Yes Yes
Other OTG (CDC) Yes
OTG (HID) Yes
OTG (MSC) Yes

Configuration

Build Time Configurations for r_usb_basic

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

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
PLL FrequencyMCU Specific OptionsSpecify the PLL frequency supplied to the USB module. This setting only applies to USB1 (not USB0).
CPU Bus Access Wait CyclesMCU Specific OptionsThis setting controls the delay for consecutive USB peripheral register access. Set this value to a number of CPU cycles that is equivalent to 40.8ns or more.
Battery ChargingMCU Specific OptionsSpecify whether or not to include battery charging functionality.
Power IC Shutdown PolarityMCU Specific OptionsSelect the polarity of the Shutdown signal on the power supply IC (if provided).
Dedicated Charging Port (DCP) ModeMCU Specific OptionsWhen enabled, USB communication is disabled and the port is used for charging only.
Notifications for SET_INTERFACE/SET_FEATURE/CLEAR_FEATURE
  • Disabled
  • Enabled
Enabled When enabled, the application will receive notifications for SET_INTERFACE, SET_FEATURE and CLEAR_FEATURE messages.
Double Buffering
  • Disabled
  • Enabled
Enabled When enabled, the FIFOs for Pipes 1-5 are double-buffered.
Continuous Transfer ModeMCU Specific OptionsEnable or disable continuous transfer mode.
LDO RegulatorMCU Specific OptionsEnable or disable LDO regulator.
Type-CMCU Specific OptionsEnable or disable Type-C.
DMA SupportMCU Specific OptionsEnable or disable DMA support for the USB module.
DMA Source AddressMCU Specific OptionsSet this to match the speed mode when DMA is enabled. Otherwise, set to 'DMA Disabled'.
DMA Destination AddressMCU Specific OptionsSet this to match the speed mode when DMA is enabled. Otherwise, set to 'DMA Disabled'.
USB Compliance Test mode
  • Enabled
  • Disabled
Disabled Display the information required to take the compliance test.
USB TPL table nameEnter the TPL table name.NULL Enter the name of the TPL Table.

Configurations for Connectivity > USB (r_usb_basic)

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_basic0 Module name.
USB Mode
  • Host mode
  • Peri mode
  • OTG mode
Host mode Select the usb mode.
USB Speed
  • Full Speed
  • Hi Speed
  • Low Speed
Full Speed Select the USB speed.
USB Module Number
  • USB_IP0 Port
  • USB_IP1 Port
USB_IP0 Port Specify the USB module number to be used.
USB Device ClassRefer to the RA Configuration tool for available options.Peripheral Communications Device Class Select the USB device class.
USB DescriptorUSB Descriptor must be a valid C symbol.g_usb_descriptor Enter the name of the descriptor to be used.
For how to create a descriptor structure, refer to the Descriptor definition chapter in the usb_basic manual.
Specify NULL when using the Host class.
USB Compliance CallbackCompliance Callback must be a valid C symbol.NULL Set the callback for compliance tests here.
USBFS Interrupt PriorityMCU Specific OptionsSelect the interrupt priority used by the main USBFS ISR.
USBFS Resume PriorityMCU Specific OptionsSelect the interrupt priority used by the USBFS Resume ISR.
USBFS D0FIFO Interrupt PriorityMCU Specific OptionsSelect the interrupt priority used by the USBFS D0FIFO.
USBFS D1FIFO Interrupt PriorityMCU Specific OptionsSelect the interrupt priority used by the USBFS D1FIFO.
USBHS Interrupt PriorityMCU Specific OptionsSelect the interrupt priority used by the main USBHS ISR.
USBHS D0FIFO Interrupt PriorityMCU Specific OptionsSelect the interrupt priority used by the USBHS D0FIFO ISR.
USBHS D1FIFO Interrupt PriorityMCU Specific OptionsSelect the interrupt priority used by the USBHS D1FIFO ISR.
USB CallbackEnter the address of the function.NULL A user callback function can be defined here.
USB Callback ContextEnter the address of the context.NULL Set the callback context here.

Clock Configuration

The USB module uses PLL as the clock source. The PLL frequency can be set in the Clocks tab of the configuration editor or by using the CGC Interface at run-time.

Note
When using HOCO as the PLL source on Cortex M33 parts the FLL function must be enabled for correct USB operation. Refer to the MCU Family -> Clocks group of the BSP properties in the RA configuration tool to adjust FLL settings.

Pin Configuration

In peripheral mode the USB_VBUS and/or USBHS_VBUS pins are used to detect the USB connection status (connected or disconnected) and should be connected to the USB VBUS signal.

Note
USB_VBUS and USBHS_VBUS are 5V-tolerant pins.

In host mode the USBHS_VBUSEN, USBHS_OVRCURA and USBHS_OVRCURB pins should be connected to the relevant pins of an external power supply IC, if available. These pins will be used to manage the USB VBUS supply.

DMA Configuration

When using DMA with USB the following properties must be configured for each DMAC module:

Config Name Select Name Description
Transfer Size 2 Bytes
4 Bytes
In FS mode, select "2 Bytes"
In HS mode, select "4 Bytes"
Activation sourceUSBFS FIFO 0
USBFS FIFO 1
USBHS FIFO 0
USBHS FIFO 1
USB FS Reception
USB FS Transmission
USB HS Reception
USB HS Transmission

Descriptor definition

In Peripheral mode, the usb_descriptor_t structure stores descriptor information including the device and configuration descriptors. The values set in this structure are sent to the USB host as part of enumeration.

typedef struct usb_descriptor
{
uint8_t *p_device; /* Pointer to device descriptor */
uint8_t *p_config_f; /* Pointer to full-speed configuration descriptor */
uint8_t *p_config_h; /* Pointer to high-speed configuration descriptor (HS only) */
uint8_t *p_qualifier; /* Pointer to device qualifier descriptor (HS only) */
uint8_t **pp_string; /* Pointer to string descriptor table */
uint8_t num_string; /* Number of strings in table */
} usb_descriptor_t;
Note
Even in high-speed mode the full-speed configuration must be made available:
/* Example USB FS descriptor struct */
usb_descriptor_t g_usb_descriptor =
{
smp_device,
smp_config_f,
NULL,
NULL,
smp_str_table,
3,
};
/* Example USB HS descriptor struct */
usb_descriptor_t g_usb_descriptor =
{
smp_device,
smp_config_f,
smp_config_h,
smp_qualifier,
smp_str_table,
3,
};

String Descriptor

This USB driver requires string descriptors to be registered in the string descriptor table. Use the following format to define the elements:

/* String descriptor 0 is reserved for language ID information */
uint8_t str_descriptor_0[]
{
0x04, /* Length */
0x03, /* Descriptor type */
0x09, 0x04 /* Language ID */
};
uint8_t str_descriptor_manufacturer[] =
{
0x10, /* Length */
0x03, /* Descriptor type */
'R', 0x00,
'E', 0x00,
'N', 0x00,
'E', 0x00,
'S', 0x00,
'A', 0x00,
'S', 0x00
};
uint8_t str_descriptor_product[] =
{
0x12, /* Length */
0x03, /* Descriptor type */
'C', 0x00,
'D', 0x00,
'C', 0x00,
'_', 0x00,
'D', 0x00,
'E', 0x00,
'M', 0x00,
'O', 0x00
};
/* String descriptor table */
uint8_t * smp_str_table[] =
{
str_descriptor_0, /* Index: 0 */
str_descriptor_manufacturer, /* Index: 1 */
str_descriptor_product, /* Index: 2 */
};
Note
Set the string index values in the device/configuration descriptors (iManufacturer, iConfiguration etc.) to the index of the desired string in the string descriptor table. For example, in the table below, the manufacturer is described in str_descriptor_manufacturer and the value of iManufacturer in the device descriptor is 1.

Other Descriptors

Refer to the Universal Serial Bus Revision 2.0 specification (http://www.usb.org/developers/docs/) for details on how to construct the device, configuration and qualifier descriptors.

Usage Notes

Program Structure

USB applications (whether using an RTOS or not) should be written as an event-handling loop. Either a callback function (RTOS only) or R_USB_EventGet should be used to provide event data to the application loop where a switch statement handles the event.

Note
1.The USB_STATUS_CONFIGURED event should be confirmed before calling R_USB_Read or R_USB_Write.
2.When attaching or detaching USB cable, the suspend or resume event may be notified to the application program in USB peripheral mode. Please ignore these events since the notification of these events to the application program does not affect the operation.

Limitations

Developers should be aware of the following limitations when using the USB driver:

Compliance Test

Please set as follows to the following items in RA configuration (r_usb_basic) when doing the compliance test.

1.USB Compliance Test mode Set "Enabled" in this item.

compliance_enable.png
Compliance Test Setting

2.USB TPL table name. Set the start address of TPL(Target Peripheral List) defined in the application program.

tpl_start_address.png
TPL Start Address Setting

Please refer to the following about how to define for TPL.
The following example is when two devices are set in TPL.

const uint16_t usb_tpl_table[] =
{
2, /* Number of tpl */
0, /* Reserved */
0x0123, 0x4567, /* Vendor ID, Product ID (1st device) */
0x89ab, 0xcdef /* Vendor ID, Product ID (2nd device) */
};

3.USB Compliance Callback Set the start address of the callback function defined in the application program.

compliance_callback.png
Compliance Callback Setting

The user needs to create this callback function by referring to the following.

void usb_compliance_disp (void * param)
{
usb_compliance_t *disp_data;
uint8_t print_data[32];
disp_data = (usb_compliance_t*)param;
switch(disp_data->status)
{
case USB_COMPLIANCETEST_ATTACH: /* Device Attach Detection */
display("\nATTACH \n");
break;
case USB_COMPLIANCETEST_DETACH: /* Device Detach Detection */
display("\nDETACH \n");
break;
case USB_COMPLIANCETEST_TPL: /* TPL device connect */
display("\nTPL PID:%04x VID:%04x \n",disp_data->pid, disp_data->vid);
break;
case USB_COMPLIANCETEST_NOTTPL: /* Not TPL device connect */
display("\nNOTPL PID:%04x VID:%04x \n",disp_data->pid, disp_data->vid);
break;
case USB_COMPLIANCETEST_HUB: /* USB Hub connect */
display("\nHub \n");
break;
case USB_COMPLIANCETEST_OVRC: /* over current */
break;
case USB_COMPLIANCETEST_NORES: /* Responce Time out for Control Read Transfer */
display("\nNOTRESP \n");
break;
case USB_COMPLIANCETEST_SETUP_ERR: /* Setup Transaction Error */
break;
default:
break;
}
} /* End of function usb_compliance_disp() */

Please replace the display function described in the example with the display function created by the customer.

Callback function for USB Peripheral

The user can get completed USB event using callback function in USB Peripheral for BareMetal.

usb_callback_args_t g_apl_usb_event_callback;
#define BUFSIZE 10
usb_callback_args_t g_apl_usb_event_buffer[BUFSIZE];
g_apl_usb_event_buffer[g_apl_buffer_wp] = g_apl_usb_event_callback;
g_apl_buffer_wp++;
g_apl_buffer_wp %= BUFSIZE;

TrustZone

  1. The USB driver for FreeRTOS cannot be allocated in Secure region.
  2. Please place the descriptor file in Secure region when using Non-Secure Callable.
  3. The user callback function should be specified using the R_USB_Callback function after calling the R_USB_Open function when using Non-Secure Callable.
  4. For Non-Secure region, please do USB clock setting when creating Secure project.
  5. Please do USB pin setting when creating USB driver project.

Support Composite Device

This driver for FreeRTOS supports the following compoiste device when this driver for FreeRTOS works in USB Host mode.

  1. PCDC + PMSC

How to Configuration

USB_Host_composite_stack1.png
Add HMSC and HCDC Stack
USB_Host_composite_stack2.png
Delete g_basic1 instance

UCLK setting

Enable UCLK in "Clocks" tab on e² studio when using the following MCU.

  1. RA6M4

Examples

USB Basic Example

This is a basic example of minimal use of the USB in an application.

void usb_basic_example (void)
{
usb_event_info_t event_info;
usb_status_t event;
g_usb_on_usb.open(&g_basic0_ctrl, &g_basic0_cfg);
memset(&event_info, 0, sizeof(usb_event_info_t));
/* Loop back between PC(TerminalSoft) and USB MCU */
while (1)
{
g_usb_on_usb.eventGet(&event_info, &event);
switch (event)
{
g_usb_on_usb.read(&g_basic0_ctrl, g_buf, DATA_LEN, USB_CLASS_PCDC);
break;
g_usb_on_usb.write(&g_basic0_ctrl, g_buf, event_info.data_size, USB_CLASS_PCDC);
break;
case USB_STATUS_REQUEST: /* Receive Class Request */
if (USB_PCDC_SET_LINE_CODING == (event_info.setup.request_type & USB_BREQUEST))
{
g_usb_on_usb.periControlDataGet(&g_basic0_ctrl, (uint8_t *) &g_line_coding, LINE_CODING_LENGTH);
}
else if (USB_PCDC_GET_LINE_CODING == (event_info.setup.request_type & USB_BREQUEST))
{
g_usb_on_usb.periControlDataSet(&g_basic0_ctrl, (uint8_t *) &g_line_coding, LINE_CODING_LENGTH);
}
else
{
g_usb_on_usb.periControlStatusSet(&g_basic0_ctrl, USB_SETUP_STATUS_ACK);
}
break;
break;
default:
break;
}
}
} /* End of function usb_main() */

USB Host Composite (CDC+MSC) Example

This is Host composiete (CDC+MSC) example of minimal use of the USB in an application.

#define RESET_VALUE (0x00)
#define EP_INFO \
"\r\nThis example project demonstrates basic functionalities of USB Host Communication Device \r\n" \
"Class (HCDC) driver on Renesas RA MCUs using 2 RA Boards. The Board 1(with USB HCDC Example \r\n" \
"running on it)communicates with Board2(with USB PCDC Example project running). Board 1 initiates\r\n" \
"the communication by sending commands to Board 2 and Board 2 responds by sending the data.\r\n" \
"Board1 prints the received data on the RTTViewer.\r\n\n\n"
#define HCDC_TSK_STACK_SIZE 1024
#define HCDC_TSK_PRI 2
#define BUF_SIZE 512
#define KIT_INFO ('1')
#define NEXT_STEPS ('2')
#define CARRIAGE_RETURN ('\r')
#define SET_LINE_CODING (USB_CDC_SET_LINE_CODING | USB_HOST_TO_DEV | USB_CLASS | USB_INTERFACE)
#define GET_LINE_CODING (USB_CDC_GET_LINE_CODING | USB_DEV_TO_HOST | USB_CLASS | USB_INTERFACE)
#define SET_CONTROL_LINE_STATE (USB_CDC_SET_CONTROL_LINE_STATE | USB_HOST_TO_DEV | USB_CLASS | USB_INTERFACE)
#define LINE_CODING_LENGTH (0x07U)
#define VALUE_ZERO (0x0000U)
#define NO_WAIT_TIME 0
#define CDC_READ_DATA_LEN 512
#define CDC_WRITE_DATA_LEN 512
#define ZERO_INDEX 0
void usb_app_hcdc_task(void * pvParameters);
static void usb_app_common_callback(usb_event_info_t * p_event_info, usb_hdl_t cur_task, usb_onoff_t usb_state);
static void usb_app_hcdc_callback(usb_event_info_t * p_event_info, usb_hdl_t cur_task, usb_onoff_t usb_state);
static void set_line_coding(usb_instance_ctrl_t * p_ctrl, uint8_t device_address);
static void set_control_line_state(usb_instance_ctrl_t * p_ctrl, uint8_t device_address);
static void get_line_coding(usb_instance_ctrl_t * p_ctrl, uint8_t device_address);
static void usb_data_process(usb_event_info_t * event_info);
static void handle_error(fsp_err_t err, char * err_str);
static void process_usb_operation(uint8_t p_input_buffer);
static void usb_write_operation(void);
static void usb_read_operation(void);
static void format_usb_device(void);
static bool check_usb_connection(void);
static void usb_safely_eject(void);
static void update_buffer(void);
static void fat_clean_up(void);
static fsp_err_t usb_init(void);
static TaskHandle_t g_app_hcdc_tsk_hdl;
static usb_callback_t * g_usb_host_apl_callback[2];
static FF_Disk_t my_disk;
static usb_hcdc_linecoding_t g_serial_state;
static usb_hcdc_linecoding_t g_com_parm;
static uint8_t g_write_data[WRITE_ITEM_SIZE] = {RESET_VALUE}; /* Data(10k) to write to file */
static uint8_t g_read_data[WRITE_ITEM_SIZE] = {RESET_VALUE}; /* Variable to store the data read from file */
static uint8_t g_snd_buf[BUF_SIZE] BSP_ALIGN_VARIABLE(4) = {RESET_VALUE};
static uint8_t g_rcv_buf[BUF_SIZE] BSP_ALIGN_VARIABLE(4) = {RESET_VALUE};
static uint8_t g_usb_dummy = RESET_VALUE; /* dummy variable to send */
static volatile bool g_err_flag = false; /* error flag bit */
static bool b_usb_hmsc_close = false;
static volatile bool g_rm_freertos_plus_fat_insertion_events = false;
extern
void new_thread0_entry (void * pvParameters)
{
FSP_PARAMETER_NOT_USED(pvParameters);
BaseType_t err_task = pdFALSE;
memset(&my_disk, RESET_VALUE, sizeof(my_disk));
fsp_pack_version_t version = {RESET_VALUE};
/* version get API for FLEX pack information */
R_FSP_VersionGet(&version);
g_usb_host_apl_callback[0] = usb_app_hcdc_callback; // HCDC App Callback
g_usb_host_apl_callback[1] = g_basic0_cfg.p_usb_apl_callback; // HMSC App Callback
R_USB_Callback(usb_app_common_callback);
/* Example Project information printed on the Console */
APP_PRINT(BANNER_INFO,
EP_VERSION,
version.version_id_b.major,
version.version_id_b.minor,
version.version_id_b.patch);
APP_PRINT(EP_INFO);
fsp_err_t freertos_fat_error = FSP_SUCCESS;
freertos_fat_error = usb_init();
if (FSP_SUCCESS != freertos_fat_error)
{
APP_ERR_PRINT("\r\nError in initializing FreeRTOS+FAT with USB_HMSC\r\n");
APP_ERR_TRAP(freertos_fat_error);
}
err_task = xTaskCreate((TaskFunction_t) usb_app_hcdc_task,
"HCDC_TSK",
HCDC_TSK_STACK_SIZE,
NULL,
HCDC_TSK_PRI,
&g_app_hcdc_tsk_hdl);
if (pdPASS != err_task)
{
APP_ERR_PRINT("\r\nAppTask Create failed.\r\n");
return;
}
/* Print USB HMSC menu */
APP_PRINT(USB_HMSC_MENU);
while (true)
{
static uint8_t rtt_input_buf[BUFFER_SIZE_DOWN] = {RESET_VALUE};
static uint8_t converted_rtt_input = RESET_VALUE;
/*Read RTT input from user*/
if (APP_CHECK_DATA)
{
APP_READ(rtt_input_buf);
converted_rtt_input = (uint8_t) atoi((char *) rtt_input_buf);
process_usb_operation(converted_rtt_input);
}
if ((false == b_usb_hmsc_close) && (false == g_rm_freertos_plus_fat_insertion_events))
{
APP_PRINT("\r\n\n USB Device disconnected without Eject option.\r\n");
APP_PRINT("\r\n Connect the USB and Execute Safely Eject option to make sure file operations works"
"correctly\r\n");
/* Wait until USB Device is connected */
while (true != check_usb_connection())
{
;
}
}
vTaskDelay(1);
}
}
/*******************************************************************************************************************
* This function initiates the USB operation by calling respective functions.
**********************************************************************************************************************/
static void process_usb_operation (uint8_t input_buffer)
{
fsp_err_t freertos_fat_error = FSP_SUCCESS;
switch (input_buffer)
{
case USB_WRITE:
{
usb_write_operation();
usb_read_operation();
APP_PRINT(USB_HMSC_MENU);
break;
}
case USB_FORMAT:
{
format_usb_device();
APP_PRINT(USB_HMSC_MENU);
break;
}
case USB_SAFELY_EJECT:
{
usb_safely_eject();
APP_PRINT(USB_HMSC_MENU);
break;
}
case USB_INIT:
{
if (true == b_usb_hmsc_close)
{
freertos_fat_error = usb_init();
if (FSP_SUCCESS != freertos_fat_error)
{
APP_ERR_PRINT("\r\nError in initializing FreeRTOS+FAT with USB_HMSC\r\n");
APP_ERR_TRAP(freertos_fat_error);
}
}
else
{
APP_PRINT("\r\n FreeRTOS+FAT USB_HMSC driver is already Initialized. Provide any other command\r\n");
}
APP_PRINT(USB_HMSC_MENU);
break;
}
default:
{
APP_PRINT("\r\n Invalid input. Provide a valid input\r\n");
break;
}
}
}
/*******************************************************************************************************************
* This function performs USB HMSC write operation.
******************************************************************************************************************/
static void usb_write_operation (void)
{
FF_FILE * file_pointer = NULL;
FF_Stat_t file_details;
int32_t file_error = SUCCESS;
/* Capture the number of bytes written in the variable to check write status. */
size_t bytes_written = RESET_VALUE;
memset(&file_details, RESET_VALUE, sizeof(file_details));
/* Double check the connection again to ensure the USB device is still mounted */
if ((true == check_usb_connection()) && (true != b_usb_hmsc_close))
{
/* Once connection is detected open file is write mode */
file_pointer = ff_fopen((const char *) FILE_NAME, WRITE_MODE);
if (NULL != file_pointer)
{
/* Fill write buffer with data */
update_buffer();
APP_PRINT(" USB write operation will be initiated.\n");
/* Write API writes */
bytes_written = ff_fwrite(g_write_data, sizeof(g_write_data[RESET_VALUE]), WRITE_ITEM_SIZE, file_pointer);
if (WRITE_ITEM_SIZE != bytes_written)
{
APP_ERR_PRINT(" ff_write API failed. Closing opened file.\r\n");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
file_error = ff_fclose(file_pointer);
if (SUCCESS != file_error)
{
APP_ERR_PRINT("ff_fclose API failed");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
}
return;
}
/* Close the file after write operation and open again in read mode */
file_error = ff_fclose(file_pointer);
if (SUCCESS != file_error)
{
APP_ERR_PRINT("ff_fclose API failed");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
return;
}
file_error = ff_stat((const char *) FILE_NAME, &file_details);
/* ff_stat returns 0 on success and -1 on error */
if (SUCCESS == file_error)
{
/* Compare the actual bytes written and file size after write operation */
if (bytes_written == file_details.st_size)
{
APP_PRINT(" %d bytes Data successfully written to file %s \n", bytes_written, FILE_NAME);
APP_PRINT(" Write operation is Successful \n");
}
else
{
APP_ERR_PRINT("ff_write API failed ");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
return;
}
}
else
{
APP_ERR_PRINT("ff_stat API failed");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
return;
}
}
else
{
APP_ERR_PRINT("ff_fopen API failed");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
return;
}
}
else
{
APP_PRINT("USB Device disconnected or not initialized after Eject command\n");
}
}
/*******************************************************************************************************************
* This function performs USB HMSC read operation.
*******************************************************************************************************************/
static void usb_read_operation (void)
{
FF_FILE * file_pointer = NULL;
FF_Stat_t file_details;
int32_t file_error = SUCCESS;
memset(&file_details, RESET_VALUE, sizeof(file_details));
/* Double check the connection again to ensure the USB device is still mounted */
if ((true == check_usb_connection()) && (true != b_usb_hmsc_close))
{
/* Open the file read mode to read data written previously */
file_pointer = ff_fopen((const char *) FILE_NAME, READ_MODE);
if (file_pointer != NULL)
{
APP_PRINT(" USB read operation will be initiated.\n");
/* Capture the number of bytes read in the variable to check read status. */
size_t bytes_read = RESET_VALUE;
bytes_read = ff_fread(g_read_data, sizeof(g_read_data[RESET_VALUE]), WRITE_ITEM_SIZE, file_pointer);
if (READ_WRITE_FAILURE == bytes_read)
{
APP_ERR_PRINT(" ff_read API failed. Closing opened file \r\n", stdioGET_ERRNO());
file_error = ff_fclose(file_pointer);
if (SUCCESS != file_error)
{
APP_ERR_PRINT("ff_fclose API failed");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
return;
}
return;
}
file_error = ff_fclose(file_pointer);
if (SUCCESS != file_error)
{
APP_ERR_PRINT("ff_fclose API failed");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
return;
}
file_error = ff_stat((const char *) FILE_NAME, &file_details);
/* ff_stat returns 0 on success and -1 on error */
if (SUCCESS == file_error)
{
/* Compare the actual bytes written and file size after write operation */
if (bytes_read == file_details.st_size)
{
APP_PRINT(" %d bytes Data successfully read from file %s \n", bytes_read, FILE_NAME);
APP_PRINT(" Read operation is Successful \n");
}
else
{
APP_ERR_PRINT("ff_write API failed ");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
return;
}
/* Compare Write and Read data. */
if (SUCCESS == memcmp(g_write_data, g_read_data, WRITE_ITEM_SIZE))
{
APP_PRINT("\r\nWrite and Read data is same\r\n");
}
else
{
APP_ERR_PRINT("\r\nWrite and Read data did not match\r\n");
}
}
else
{
APP_ERR_PRINT("ff_stat API failed");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
return;
}
}
else
{
APP_ERR_PRINT("ff_fopen API failed");
/* Adding extra %d as parses string and prints %d as-is. */
APP_PRINT(" %d\r\n", stdioGET_ERRNO());
return;
}
}
else
{
APP_PRINT("USB Device disconnected or not initialized after Eject command\n");
}
}
/*******************************************************************************************************************
* This function performs USB HMSC format operation.
******************************************************************************************************************/
static void format_usb_device (void)
{
if ((true == check_usb_connection()) && (true != b_usb_hmsc_close))
{
APP_PRINT("\r\n USB Device Formatting will be initiated. Formatting will take time "
"depending on USB Device capacity.\r\n");
APP_PRINT(" Do not disconnect the USB device while formatting is in progress. Please Wait ...\r\n");
/* Formatting time varies with USB Device capacity. Might take longer time for higher capacity USB Device */
FF_Error_t ff_error = FF_Format(&my_disk, my_disk.xStatus.bPartitionNumber, pdFALSE, pdFALSE);
if (FF_ERR_NONE != ff_error)
{
APP_ERR_PRINT("\r\n FF_Format API failed %d. Check the USB Device.\r\n", FF_GetErrMessage(ff_error));
APP_PRINT(" %d\r\n", FF_GetErrMessage(ff_error));
}
else
{
APP_PRINT("\r\nUSB Device Formatted successfully \r\n");
}
}
else
{
APP_PRINT("USB Device disconnected or not initialized after Eject command\n");
}
}
/*******************************************************************************************************************
* This function closes USB HMSC on FreeRTOS+FAT and safely ejects.
******************************************************************************************************************/
static void usb_safely_eject (void)
{
/* Check the USB Device Connection before formating */
if ((true == check_usb_connection()) && (true != b_usb_hmsc_close))
{
fsp_err_t freertos_fat_error = RM_FREERTOS_PLUS_FAT_DiskDeinit(&g_rm_freertos_plus_fat0_ctrl, &my_disk);
if (FSP_SUCCESS != freertos_fat_error)
{
APP_ERR_PRINT("\r\nFREERTOS PLUS FAT DiskDeinit API failed\r\n");
APP_ERR_TRAP(freertos_fat_error);
}
/* Close the FREERTOS_PLUS_FAT_Close instance on safely ejecting */
freertos_fat_error = RM_FREERTOS_PLUS_FAT_Close(&g_rm_freertos_plus_fat0_ctrl);
if (FSP_SUCCESS != freertos_fat_error)
{
APP_ERR_PRINT("\r\nFREERTOS PLUS FAT CLOSE API failed\r\n");
APP_ERR_TRAP(freertos_fat_error);
}
APP_PRINT("\r\nUSB Device can be safely removed now\r\n");
/* Update the flag */
b_usb_hmsc_close = true;
g_rm_freertos_plus_fat_insertion_events = false;
}
else
{
/* USB Device disconnected */
APP_PRINT("USB Device disconnected or not initialized after Eject command\n");
}
}
/*******************************************************************************************************************
* This function checks the USB HMSC connection status.
******************************************************************************************************************/
static bool check_usb_connection (void)
{
if (true != g_rm_freertos_plus_fat_insertion_events)
{
return false;
}
else
{
APP_PRINT("\r\n USB Device is connected\r\n");
return true;
}
}
/*******************************************************************************************************************
* This function updates write buffer with data and clears read buffer.
******************************************************************************************************************/
static void update_buffer (void)
{
for (uint16_t i = RESET_VALUE; i < WRITE_ITEM_SIZE; i++)
{
g_write_data[i] = ASCII_CHAR_A;
g_read_data[i] = RESET_VALUE;
}
}
/*******************************************************************************************************************
* This function is callback for FreeRTOS+FAT and triggered when USB Pen drive is removed or inserted.
******************************************************************************************************************/
static void free_rtos_fat_callback (rm_freertos_plus_fat_callback_args_t * p_args)
{
{
g_rm_freertos_plus_fat_insertion_events = true;
}
{
g_rm_freertos_plus_fat_insertion_events = false;
}
}
/*******************************************************************************************************************
* This function Initializes the FreeRTOS+FAT instance..
*******************************************************************************************************************/
static fsp_err_t usb_init (void)
{
fsp_err_t freertos_fat_error = FSP_SUCCESS;
int32_t file_error = SUCCESS;
memset(&device, RESET_VALUE, sizeof(device));
/* Open FreeRTOS PLUS FAT */
freertos_fat_error = RM_FREERTOS_PLUS_FAT_Open(&g_rm_freertos_plus_fat0_ctrl, &g_rm_freertos_plus_fat0_cfg);
if (FSP_SUCCESS != freertos_fat_error)
{
APP_ERR_PRINT("\r\nFREERTOS PLUS FAT OPEN API failed\r\n");
return freertos_fat_error;
}
APP_PRINT("\r\n\nFreeRTOS+FAT Open successful\r\n");
/* Wait for USB Device connection */
APP_PRINT(" Connect USB Device...\r\n");
/* Wait until USB Device is connected */
while (true != check_usb_connection())
{
;
}
/* Initialize the mass storage device. This should not be done until the device is plugged in and initialized. */
freertos_fat_error = RM_FREERTOS_PLUS_FAT_MediaInit(&g_rm_freertos_plus_fat0_ctrl, &device);
if (FSP_SUCCESS != freertos_fat_error)
{
APP_ERR_PRINT("\r\nFreeRTOS Plus FAT Media Init API failed\r\n");
fat_clean_up();
return freertos_fat_error;
}
/* Initialize one disk for each partition used in the application. */
freertos_fat_error = RM_FREERTOS_PLUS_FAT_DiskInit(&g_rm_freertos_plus_fat0_ctrl,
&g_rm_freertos_plus_fat0_disk_cfg,
&my_disk);
if (FSP_SUCCESS != freertos_fat_error)
{
APP_ERR_PRINT("\r\nFreeRTOS Plus FAT Disk Init API failed\r\n");
fat_clean_up();
return freertos_fat_error;
}
/* Mount each disk. This assumes the disk is already partitioned and formatted. */
FF_Error_t ff_err = FF_Mount(&my_disk, my_disk.xStatus.bPartitionNumber);
if (FSP_SUCCESS != ff_err)
{
APP_ERR_PRINT("\r\nFF_Mount API failed\r\n");
/* Close the FREERTOS_PLUS_FAT_Close instance on safely ejecting */
fat_clean_up();
/* As function returns fsp_err_t, ff_err cannot be returned. Hence trapping the error here */
APP_ERR_TRAP(ff_err);
}
/* Add the disk to the file system. */
file_error = FF_FS_Add("/", &my_disk);
if (SUCCESS == file_error)
{
APP_ERR_PRINT("\r\nFF_Mount API failed\r\n");
/* Close the FREERTOS_PLUS_FAT_Close instance on safely ejecting */
fat_clean_up();
/* As function returns fsp_err_t, ff_err cannot be returned. Hence trapping the error here */
APP_ERR_TRAP(file_error);
}
/* Set this flag to let application know that USB is initialized */
b_usb_hmsc_close = false;
return freertos_fat_error;
}
/*******************************************************************************************************************
* This function closes the FreeRTOS+FAT instance..
*******************************************************************************************************************/
static void fat_clean_up (void)
{
fsp_err_t freertos_fat_error = FSP_SUCCESS;
/* Close the FREERTOS_PLUS_FAT_Close instance on any failure */
freertos_fat_error = RM_FREERTOS_PLUS_FAT_Close(&g_rm_freertos_plus_fat0_ctrl);
if (FSP_SUCCESS != freertos_fat_error)
{
APP_PRINT("\r\nFREERTOS PLUS FAT CLOSE API failed\r\n");
}
else
{
APP_PRINT("\r\nFREERTOS PLUS FAT instance Closed successfully.\r\n");
}
}
/******************************************************************************
* Event notification thread for Interrupt IN/OUT test.
******************************************************************************/
static void usb_app_hcdc_task (void * pvParameters)
{
fsp_err_t err = FSP_SUCCESS;
static usb_event_info_t * event_info = NULL;
BaseType_t err_queue = pdFALSE;
memset(&g_serial_state, RESET_VALUE, sizeof(g_serial_state));
memset(&g_com_parm, RESET_VALUE, sizeof(g_com_parm));
g_snd_buf[ZERO_INDEX] = KIT_INFO;
uint32_t i;
/*Fill the write buffer*/
for (i = RESET_VALUE; i < CDC_WRITE_DATA_LEN; i++)
{
g_snd_buf[i] = (uint8_t) i;
}
while (true)
{
/* Handle error if queue send fails*/
if (true == g_err_flag)
{
handle_error(g_err_flag, "Error in sending usb event through queue");
}
/* Receive message from queue and analyzing the received message*/
err_queue = xQueueReceive(g_usb_queue, &event_info, (portMAX_DELAY));
/* Handle error */
if (pdTRUE != err_queue)
{
handle_error(err_queue, "Error in receiving USB event message through queue");
}
switch (event_info->event)
{
{
vTaskDelay(200); // GR_debug
/* CDC Class request "SetLineCoding" */
set_line_coding(&g_basic0_ctrl, event_info->device_address);
break;
}
{
/* CDC class communication data process */
usb_data_process(event_info);
break;
}
{
/* Report receive start */
err = R_USB_Read(&g_basic0_ctrl, g_rcv_buf, CDC_READ_DATA_LEN, event_info->device_address);
/* Handle Error */
if (FSP_SUCCESS != err)
{
handle_error(err, "**R_USB_Read API FAILED**");
}
break;
}
{
/* Check Complete request "SetLineCoding" */
if (USB_CDC_SET_LINE_CODING == (event_info->setup.request_type & USB_BREQUEST))
{
/* Class notification "SerialState" receive start */
set_control_line_state(&g_basic0_ctrl, event_info->device_address);
}
/* Check Complete request "SetControlLineState" */
else if (USB_CDC_SET_CONTROL_LINE_STATE == (event_info->setup.request_type & USB_BREQUEST))
{
/* CDC Class request "SetLineCoding" */
get_line_coding(&g_basic0_ctrl, event_info->device_address);
}
else if (USB_CDC_GET_LINE_CODING == (event_info->setup.request_type & USB_BREQUEST))
{
err = R_USB_Write(&g_basic0_ctrl, g_snd_buf, CDC_WRITE_DATA_LEN, event_info->device_address);
if (FSP_SUCCESS != err)
{
handle_error(err, "**R_USB_Write API FAILED**");
}
}
else
{
/* Not support request */
}
break;
}
default:
{
/* No operation to do*/
break;
}
}
vTaskDelay(200);
}
}
/*******************************************************************************************************************
* In this function initializes to set control line state information for host control transfer.
******************************************************************************************************************/
static void set_control_line_state (usb_instance_ctrl_t * p_ctrl, uint8_t device_address)
{
usb_setup_t setup;
fsp_err_t err = FSP_SUCCESS;
setup.request_type = SET_CONTROL_LINE_STATE; /* bRequestCode:SET_CONTROL_LINE_STATE, bmRequestType */
setup.request_value = VALUE_ZERO; /* wValue:Zero */
setup.request_index = VALUE_ZERO; /* wIndex:Interface */
setup.request_length = VALUE_ZERO; /* wLength:Zero */
err = R_USB_HostControlTransfer(p_ctrl, &setup, &g_usb_dummy, device_address);
if (FSP_SUCCESS != err)
{
handle_error(err, "**R_USB_HOSTControlTransfer API FAILED**");
}
}
/*******************************************************************************************************************
* In this function initializes to set line coding information for host control transfer.
******************************************************************************************************************/
static void set_line_coding (usb_instance_ctrl_t * p_ctrl, uint8_t device_address)
{
usb_setup_t setup;
fsp_err_t err = FSP_SUCCESS;
g_com_parm.dwdte_rate = (uint32_t) USB_HCDC_SPEED_9600;
setup.request_type = SET_LINE_CODING; /* bRequestCode:SET_LINE_CODING, bmRequestType */
setup.request_value = VALUE_ZERO; /* wValue:Zero */
setup.request_index = VALUE_ZERO; /* wIndex:Interface */
setup.request_length = LINE_CODING_LENGTH; /* Data:Line Coding Structure */
/* Request Control transfer */
err = R_USB_HostControlTransfer(p_ctrl, &setup, (uint8_t *) &g_com_parm, device_address);
if (FSP_SUCCESS != err)
{
handle_error(err, "**R_USB_HostControlTransfer API FAILED**");
}
} /* End of function cdc_set_line_coding */
/*******************************************************************************************************************
* In this function initializes to get line coding information for host control transfer.
******************************************************************************************************************/
static void get_line_coding (usb_instance_ctrl_t * p_ctrl, uint8_t device_address)
{
usb_setup_t setup;
fsp_err_t err = FSP_SUCCESS;
setup.request_type = GET_LINE_CODING; /* bRequestCode:GET_LINE_CODING, bmRequestType */
setup.request_value = VALUE_ZERO; /* wValue:Zero */
setup.request_index = VALUE_ZERO; /* wIndex:Interface */
setup.request_length = LINE_CODING_LENGTH; /* Data:Line Coding Structure */
/* Request Control transfer */
err = R_USB_HostControlTransfer(p_ctrl, &setup, (uint8_t *) &g_com_parm, device_address);
if (FSP_SUCCESS != err)
{
handle_error(err, "**R_USB_HostControlTransfer API FAILED**");
}
}
/*******************************************************************************************************************
* This function is called to do closing of usb module using its HAL level API and handles the error trap.
* Handle the Error internally with Proper Message. Application handles the rest.
******************************************************************************************************************/
static void handle_error (fsp_err_t err, char * err_str)
{
}
/*******************************************************************************************************************
* This function is to do data process with peripheral device
******************************************************************************************************************/
static void usb_data_process (usb_event_info_t * event_info)
{
fsp_err_t err = FSP_SUCCESS;
if (USB_CLASS_HCDC == event_info->type)
{
if (RESET_VALUE < event_info->data_size)
{
if (0 != memcmp(g_rcv_buf, g_snd_buf, event_info->data_size))
{
APP_PRINT("\r\n Sending and receiving data do not match :%s", g_rcv_buf);
}
err = R_USB_Write(&g_basic0_ctrl, g_snd_buf, CDC_WRITE_DATA_LEN, event_info->device_address);
if (FSP_SUCCESS != err)
{
handle_error(err, "**R_USB_Write API FAILED**");
}
APP_PRINT("\r\n Received data :%s", g_rcv_buf);
}
else
{
/* Send the data reception request when the zero-length packet is received. */
err = R_USB_Read(&g_basic0_ctrl, g_rcv_buf, event_info->data_size, event_info->device_address);
if (FSP_SUCCESS != err)
{
handle_error(err, "**R_USB_Read API FAILED**");
}
}
}
else
{
/* Class notification "SerialState" receive start */
err = R_USB_Read(&g_basic0_ctrl,
(uint8_t *) &g_serial_state,
USB_HCDC_SERIAL_STATE_MSG_LEN,
event_info->device_address);
/* Error Handle */
if (FSP_SUCCESS != err)
{
handle_error(err, "**R_USB_Read API FAILED**");
}
}
} /* End of function usb_data_process */
/*******************************************************************************************************************
* This function is callback for FreeRTOS+HCDC and triggers when USB event occurs from the device.
******************************************************************************************************************/
static void usb_app_common_callback (usb_event_info_t * p_event_info, usb_hdl_t cur_task, usb_onoff_t usb_state)
{
if (USB_CLASS_REQUEST == p_event_info->type)
{
if ((USB_CDC_SET_LINE_CODING == (p_event_info->setup.request_type & USB_BREQUEST)) ||
(USB_CDC_GET_LINE_CODING == (p_event_info->setup.request_type & USB_BREQUEST)) ||
(USB_CDC_SET_CONTROL_LINE_STATE == (p_event_info->setup.request_type & USB_BREQUEST)))
{
g_usb_host_apl_callback[0](p_event_info, cur_task, usb_state); // HCDC Callback
}
else
{
g_usb_host_apl_callback[1](p_event_info, cur_task, usb_state); // HMSC Callback
}
}
else
{
if ((USB_CLASS_HCDC == p_event_info->type) || (USB_CLASS_HCDCC == p_event_info->type))
{
g_usb_host_apl_callback[0](p_event_info, cur_task, usb_state); // HCDC Callback
}
else
{
g_usb_host_apl_callback[1](p_event_info, cur_task, usb_state); // HMSC Callback
}
}
}
/*******************************************************************************************************************
* This function is callback for FreeRTOS+HCDC and triggers when USB event occurs from the device.
******************************************************************************************************************/
static void usb_app_hcdc_callback (usb_event_info_t * p_event_info, usb_hdl_t cur_task, usb_onoff_t usb_state)
{
/* Send event received to queue */
if (pdTRUE != (xQueueSend(g_usb_queue, (const void *) &p_event_info, (TickType_t) (NO_WAIT_TIME))))
{
g_err_flag = true;
}
}

Typedefs

typedef usb_event_info_t usb_instance_ctrl_t
 

Typedef Documentation

◆ usb_instance_ctrl_t

typedef usb_event_info_t usb_instance_ctrl_t

USB private control block. DO NOT MODIFY. Initialization occurs when R_USB_Open is called.

Function Documentation

◆ R_USB_EventGet()

fsp_err_t R_USB_EventGet ( usb_ctrl_t *const  p_api_ctrl,
usb_status_t event 
)

Obtains completed USB related events. (OS-less Only)

In USB host mode, the device address value of the USB device that completed an event is specified in the usb_ctrl_t structure member (address) specified by the event's argument. In USB peripheral mode, USB_NULL is specified in member (address). If this function is called in the RTOS execution environment, a failure is returned.

Return values
FSP_SUCCESSEvent Get Success.
FSP_ERR_USB_FAILEDIf called in the RTOS environment, an error is returned.
Note
Do not use the same variable as the first argument of R_USB_Open for the first argument.
Do not call this API in the interrupt function.

◆ R_USB_Callback()

fsp_err_t R_USB_Callback ( usb_callback_t *  p_callback)

Register a callback function to be called upon completion of a USB related event. (RTOS only)

This function registers a callback function to be called when a USB-related event has completed. If this function is called in the OS-less execution environment, a failure is returned.

Return values
FSP_SUCCESSSuccessfully completed.
FSP_ERR_ASSERTIONParameter is NULL error.
Note
Do not call this API in the interrupt function.

◆ R_USB_Open()

fsp_err_t R_USB_Open ( usb_ctrl_t *const  p_api_ctrl,
usb_cfg_t const *const  p_cfg 
)

Applies power to the USB module specified in the argument (p_ctrl).

Return values
FSP_SUCCESSSuccess in open.
FSP_ERR_USB_BUSYSpecified USB module now in use.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_Close()

fsp_err_t R_USB_Close ( usb_ctrl_t *const  p_api_ctrl)

Terminates power to the USB module specified in argument (p_ctrl). USB0 module stops when USB_IP0 is specified to the member (module), USB1 module stops when USB_IP1 is specified to the member (module).

Return values
FSP_SUCCESSSuccess.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_USB_NOT_OPENUSB module is not open.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_Read()

fsp_err_t R_USB_Read ( usb_ctrl_t *const  p_api_ctrl,
uint8_t *  p_buf,
uint32_t  size,
uint8_t  destination 
)

Bulk/Interrupt data transfer.

Requests USB data read (bulk/interrupt transfer). The read data is stored in the area specified by argument (p_buf). After data read is completed, confirm the operation by checking the return value (USB_STATUS_READ_COMPLETE) of the R_USB_GetEvent function. The received data size is set in member (size) of the usb_ctrl_t structure. To figure out the size of the data when a read is complete, check the return value (USB_STATUS_READ_COMPLETE) of the R_USB_GetEvent function, and then refer to the member (size) of the usb_crtl_t structure.

Return values
FSP_SUCCESSSuccessfully completed (Data read request completed).
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_USB_BUSYData receive request already in process for USB device with same device address.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
1. Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).
2. Allocate the following the storage area when using DMA transfer and specify the start address of the allocated storage area to the 2nd argument(p_buf).
(1). When using High-speed and enabling continuous transfer mode, allocate the storage area with a size that is a multiple of 2048.
(2). When using High-speed and disabling continuous transfer mode, allocate the storage area with a size that is a multiple of 512.
(3). When using Full-speed, allocate the storage area with a size that is a multiple of 64.
3. Specify the following address to the 2nd argument (p_buf) when using DMA transfer.
(1). When using High-speed module, specify start address of the buffer area aligned on 4-byte boundary.
(2). When using Full-speed module, specify start address of the buffer area aligned on 2-byte boundary.

◆ R_USB_Write()

fsp_err_t R_USB_Write ( usb_ctrl_t *const  p_api_ctrl,
uint8_t const *const  p_buf,
uint32_t  size,
uint8_t  destination 
)

Bulk/Interrupt data transfer.

Requests USB data write (bulk/interrupt transfer). Stores write data in area specified by argument (p_buf). Set the device class type in usb_ctrl_t structure member (type). Confirm after data write is completed by checking the return value (USB_STATUS_WRITE_COMPLETE) of the R_USB_GetEvent function. For sending a zero-length packet, please refer the following Note.

Return values
FSP_SUCCESSSuccessfully completed. (Data write request completed)
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_USB_BUSYData write request already in process for USB device with same device address.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
1. The user needs to send the zero-length packet(ZLP) since this USB driver does not send the ZLP automatically.
When sending a ZLP, the user sets USB_NULL in the third argument (size) of R_USB_Write function as follow.
e.g)
R_USB_Write (&g_basic0_ctrl, &g_buf, USB_NULL);
2. Specify the following address to the 2nd argument (p_buf) when using DMA transfer.
(1). When using High-speed module, specify start address of the buffer area aligned on 4-byte boundary.
(2). When using Full-speed module, specify start address of the buffer area aligned on 2-byte boundary.
3. Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_Stop()

fsp_err_t R_USB_Stop ( usb_ctrl_t *const  p_api_ctrl,
usb_transfer_t  direction,
uint8_t  destination 
)

Requests a data read/write transfer be terminated when a data read/write transfer is being performed.

To stop a data read, set USB_TRANSFER_READ as the argument (type); to stop a data write, specify USB_WRITE as the argument (type).

Return values
FSP_SUCCESSSuccessfully completed. (stop completed)
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_BUSYStop processing is called multiple times.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_Suspend()

fsp_err_t R_USB_Suspend ( usb_ctrl_t *const  p_api_ctrl)

Sends a SUSPEND signal from the USB module assigned to the member (module) of the usb_crtl_t structure.

After the suspend request is completed, confirm the operation with the return value (USB_STATUS_SUSPEND) of the R_USB_EventGet function.

Return values
FSP_SUCCESSSuccessfully completed.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_USB_BUSYDuring a suspend request to the specified USB module, or when the USB module is already in the suspended state.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_Resume()

fsp_err_t R_USB_Resume ( usb_ctrl_t *const  p_api_ctrl)

Sends a RESUME signal from the USB module assigned to the member (module) of the usb_ctrl_tstructure.

After the resume request is completed, confirm the operation with the return value (USB_STATUS_RESUME) of the R_USB_EventGet function

Return values
FSP_SUCCESSSuccessfully completed.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_USB_BUSYResume already requested for same device address. (USB host mode only)
FSP_ERR_USB_NOT_SUSPENDUSB device is not in the SUSPEND state.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_VbusSet()

fsp_err_t R_USB_VbusSet ( usb_ctrl_t *const  p_api_ctrl,
uint16_t  state 
)

Specifies starting or stopping the VBUS supply.

Return values
FSP_SUCCESSSuccessful completion. (VBUS supply start/stop completed)
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_InfoGet()

fsp_err_t R_USB_InfoGet ( usb_ctrl_t *const  p_api_ctrl,
usb_info_t *  p_info,
uint8_t  destination 
)

Obtains completed USB-related events.

Return values
FSP_SUCCESSSuccessful completion. (VBUS supply start/stop completed)
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_USB_PARAMETERParameter error.

◆ R_USB_PipeRead()

fsp_err_t R_USB_PipeRead ( usb_ctrl_t *const  p_api_ctrl,
uint8_t *  p_buf,
uint32_t  size,
uint8_t  pipe_number 
)

Requests a data read (Bulk/Interrupt transfer) via the pipe specified in the argument.

The read data is stored in the area specified in the argument (p_buf). After the data read is completed, confirm the operation with the R_USB_GetEvent function return value(USB_STATUS_READ_COMPLETE). To figure out the size of the data when a read is complete, check the return value (USB_STATUS_READ_COMPLETE) of the R_USB_GetEvent function, and then refer to the member (size) of the usb_crtl_t structure.

Return values
FSP_SUCCESSSuccessfully completed.
FSP_ERR_USB_BUSYSpecified pipe now handling data receive/send request.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
1. Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).
2. Allocate the following the storage area when using DMA transfer and specify the start address of the allocated storage area to the 2nd argument(p_buf).
(1). When using High-speed and enabling continuous transfer mode, allocate the storage area with a size that is a multiple of 2048.
(2). When using High-speed and disabling continuous transfer mode, allocate the storage area with a size that is a multiple of 512.
(3). When using Full-speed, allocate the storage area with a size that is a multiple of 64.
3. Specify the following address to the 2nd argument (p_buf) when using DMA transfer.
(1). When using High-speed module, specify start address of the buffer area aligned on 4-byte boundary.
(2). When using Full-speed module, specify start address of the buffer area aligned on 2-byte boundary.

◆ R_USB_PipeWrite()

fsp_err_t R_USB_PipeWrite ( usb_ctrl_t *const  p_api_ctrl,
uint8_t *  p_buf,
uint32_t  size,
uint8_t  pipe_number 
)

Requests a data write (Bulk/Interrupt transfer).

The write data is stored in the area specified in the argument (p_buf). After data write is completed, confirm the operation with the return value (USB_STATUS_WRITE_COMPLETE) of the EventGet function. For sending a zero-length packet, please refer the following Note.

Return values
FSP_SUCCESSSuccessfully completed.
FSP_ERR_USB_BUSYSpecified pipe now handling data receive/send request.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
1. The user needs to send the zero-length packet(ZLP) since this USB driver does not send the ZLP automatically.
When sending a ZLP, the user sets USB_NULL in the third argument (size) of R_USB_PipeWrite function as follow.
e.g)
R_USB_PipeWrite (&g_basic0_ctrl, &g_buf, USB_NULL, pipe_number);
2. Specify the following address to the 2nd argument (p_buf) when using DMA transfer.
(1). When using High-speed module, specify start address of the buffer area aligned on 4-byte boundary.
(2). When using Full-speed module, specify start address of the buffer area aligned on 2-byte boundary.
3. Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_PipeStop()

fsp_err_t R_USB_PipeStop ( usb_ctrl_t *const  p_api_ctrl,
uint8_t  pipe_number 
)

Terminates a data read/write operation.

Return values
FSP_SUCCESSSuccessfully completed. (Stop request completed)
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_UsedPipesGet()

fsp_err_t R_USB_UsedPipesGet ( usb_ctrl_t *const  p_api_ctrl,
uint16_t *  p_pipe,
uint8_t  destination 
)

Gets the selected pipe number (number of the pipe that has completed initalization) via bit map information.

The bit map information is stored in the area specified in argument (p_pipe). Based on the information (module member and address member) assigned to the usb_ctrl_t structure, obtains the PIPE information of that USB device.

Return values
FSP_SUCCESSSuccessfully completed.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.

◆ R_USB_PipeInfoGet()

fsp_err_t R_USB_PipeInfoGet ( usb_ctrl_t *const  p_api_ctrl,
usb_pipe_t *  p_info,
uint8_t  pipe_number 
)

Gets the following pipe information regarding the pipe specified in the argument (p_ctrl) member (pipe): endpoint number, transfer type, transfer direction and maximum packet size.

The obtained pipe information is stored in the area specified in the argument (p_info).

Return values
FSP_SUCCESSSuccessfully completed.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.

◆ R_USB_PullUp()

fsp_err_t R_USB_PullUp ( usb_ctrl_t *const  p_api_ctrl,
uint8_t  state 
)

This API enables or disables pull-up of D+/D- line.

Return values
FSP_SUCCESSSuccessful completion. (Pull-up enable/disable setting completed)
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_HostControlTransfer()

fsp_err_t R_USB_HostControlTransfer ( usb_ctrl_t *const  p_api_ctrl,
usb_setup_t *  p_setup,
uint8_t *  p_buf,
uint8_t  device_address 
)

Performs settings and transmission processing when transmitting a setup packet.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
FSP_ERR_USB_BUSYSpecified pipe now handling data receive/send request.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_PeriControlDataGet()

fsp_err_t R_USB_PeriControlDataGet ( usb_ctrl_t *const  p_api_ctrl,
uint8_t *  p_buf,
uint32_t  size 
)

Receives data sent by control transfer.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_BUSYSpecified pipe now handling data receive/send request.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_PeriControlDataSet()

fsp_err_t R_USB_PeriControlDataSet ( usb_ctrl_t *const  p_api_ctrl,
uint8_t *  p_buf,
uint32_t  size 
)

Performs transfer processing for control transfer.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_BUSYSpecified pipe now handling data receive/send request.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_PeriControlStatusSet()

fsp_err_t R_USB_PeriControlStatusSet ( usb_ctrl_t *const  p_api_ctrl,
usb_setup_status_t  status 
)

Set the response to the setup packet.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_PARAMETERParameter error.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_RemoteWakeup()

fsp_err_t R_USB_RemoteWakeup ( usb_ctrl_t *const  p_api_ctrl)

Sends a remote wake-up signal to the connected Host.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
FSP_ERR_USB_NOT_SUSPENDDevice is not suspended.
FSP_ERR_USB_BUSYThe device is in resume operation.
Note
Do not call this API in the following function.
(1). Interrupt function.
(2). Callback function ( for RTOS ).

◆ R_USB_DriverActivate()

fsp_err_t R_USB_DriverActivate ( usb_ctrl_t *const  p_api_ctrl)

Activate USB Driver for USB Peripheral BareMetal.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
Note
Call this API in the in the infinite loop of the application program or a timer interrupt.

◆ R_USB_CallbackMemorySet()

fsp_err_t R_USB_CallbackMemorySet ( usb_ctrl_t *const  p_api_ctrl,
usb_callback_args_t *  p_callback_memory 
)

Set callback memory to USB Driver for USB Peripheral BareMetal.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
Note
Call this API after calling R_USB_Open function.

◆ R_USB_ModuleNumberGet()

fsp_err_t R_USB_ModuleNumberGet ( usb_ctrl_t *const  p_api_ctrl,
uint8_t *  module_number 
)

This API gets the module number.

Return values
FSP_SUCCESSSuccessful completion.

◆ R_USB_ClassTypeGet()

fsp_err_t R_USB_ClassTypeGet ( usb_ctrl_t *const  p_api_ctrl,
usb_class_t class_type 
)

This API gets the class type.

Return values
FSP_SUCCESSSuccessful completion.
Note
In Bare-Metal, In the Bare-Metal version, please specify the variable specified by the 1st argument of the R_USB_EventGet function to the 1st argument of this API.
In the FreeRTOS, please specify one of the following to the 1st argument of this API.
1. The 1st argument of the callback function specified in Conguration.
2. The start address of the area where the structure area of the 1st argument was copied.

◆ R_USB_DeviceAddressGet()

fsp_err_t R_USB_DeviceAddressGet ( usb_ctrl_t *const  p_api_ctrl,
uint8_t *  device_address 
)

This API gets the device address.

Return values
FSP_SUCCESSSuccessful completion.
Note
In Bare-Metal, In the Bare-Metal version, please specify the variable specified by the 1st argument of the R_USB_EventGet function to the 1st argument of this API.
In the FreeRTOS, please specify one of the following to the 1st argument of this API.
1. The 1st argument of the callback function specified in Conguration.
2. The start address of the area where the structure area of the 1st argument was copied.

◆ R_USB_PipeNumberGet()

fsp_err_t R_USB_PipeNumberGet ( usb_ctrl_t *const  p_api_ctrl,
uint8_t *  pipe_number 
)

This API gets the pipe number.

Return values
FSP_SUCCESSSuccessful completion.
Note
In Bare-Metal, In the Bare-Metal version, please specify the variable specified by the 1st argument of the R_USB_EventGet function to the 1st argument of this API.
In the FreeRTOS, please specify one of the following to the 1st argument of this API.
1. The 1st argument of the callback function specified in Conguration.
2. The start address of the area where the structure area of the 1st argument was copied.

◆ R_USB_DeviceStateGet()

fsp_err_t R_USB_DeviceStateGet ( usb_ctrl_t *const  p_api_ctrl,
uint16_t *  state 
)

This API gets the state of the device.

Return values
FSP_SUCCESSSuccessful completion.
Note
In Bare-Metal, In the Bare-Metal version, please specify the variable specified by the 1st argument of the R_USB_EventGet function to the 1st argument of this API.
In the FreeRTOS, please specify one of the following to the 1st argument of this API.
1. The 1st argument of the callback function specified in Conguration.
2. The start address of the area where the structure area of the 1st argument was copied.

◆ R_USB_DataSizeGet()

fsp_err_t R_USB_DataSizeGet ( usb_ctrl_t *const  p_api_ctrl,
uint32_t *  data_size 
)

This API gets the read data size.

Return values
FSP_SUCCESSSuccessful completion.
Note
In Bare-Metal, In the Bare-Metal version, please specify the variable specified by the 1st argument of the R_USB_EventGet function to the 1st argument of this API.
In the FreeRTOS, please specify one of the following to the 1st argument of this API.
1. The 1st argument of the callback function specified in Conguration.
2. The start address of the area where the structure area of the 1st argument was copied.

◆ R_USB_SetupGet()

fsp_err_t R_USB_SetupGet ( usb_ctrl_t *const  p_api_ctrl,
usb_setup_t *  setup 
)

This API gets the setup information.

Return values
FSP_SUCCESSSuccessful completion.
Note
In Bare-Metal, In the Bare-Metal version, please specify the variable specified by the 1st argument of the R_USB_EventGet function to the 1st argument of this API.
In the FreeRTOS, please specify one of the following to the 1st argument of this API.
1. The 1st argument of the callback function specified in Conguration.
2. The start address of the area where the structure area of the 1st argument was copied.

◆ R_USB_OtgCallbackSet()

fsp_err_t R_USB_OtgCallbackSet ( usb_ctrl_t *const  p_api_ctrl,
usb_otg_callback_t *  p_callback 
)

Set callback function to be called when the OTG role swap was completed on Azure RTOS.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.

◆ R_USB_OtgSRP()

fsp_err_t R_USB_OtgSRP ( usb_ctrl_t *const  p_api_ctrl)

Start the SRP processing for OTG on Azure RTOS.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.
FSP_ERR_ASSERTIONParameter is NULL error.
Note
Do not support the VBUS Pulsing since OTG 2.0 does not support the VBUS Pulsing..

◆ R_USB_TypeCInfoGet()

fsp_err_t R_USB_TypeCInfoGet ( usb_ctrl_t *const  p_api_ctrl,
usb_typec_info_t *  p_info 
)

USB Type-C connect Information get.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_USB_FAILEDThe function could not be completed successfully.