Hello,
I'm working on the USB PCDC on RA6M5 MCU. When I connect the USB to the Host(Windows machine), I got this error:
Here is the USB PCDC stack configuration:
Here is the init code:
void USBInit(void) { fsp_err_t err = FSP_SUCCESS; R_IOPORT_PinCfg( &g_ioport_ctrl, BSP_IO_PORT_04_PIN_07, ((uint32_t) IOPORT_CFG_PERIPHERAL_PIN | (uint32_t) IOPORT_PERIPHERAL_USB_FS)); err = R_USB_Open(&g_basic0_ctrl, &g_basic0_cfg); if (err == FSP_ERR_USB_BUSY) { // usb is already open, close and reopen to re-enable interrupts R_USB_Close(&g_basic0_ctrl); err = R_USB_Open(&g_basic0_ctrl, &g_basic0_cfg); } if (err != FSP_SUCCESS) { printf("ERROR: faild to open usb\n"); return; } err = R_USB_ClassTypeGet(&g_basic0_ctrl, &g_usb_class_type); if (err != FSP_SUCCESS) { printf("ERROR: faild to get usb class\n"); return; } err = R_USB_ModuleNumberGet(&g_basic0_ctrl, &g_usb_module_number); if (err != FSP_SUCCESS) { printf("ERROR: faild to get module number\n"); return; } }
The init code works. Then I called this:
static void usbProcessEvents(void) { fsp_err_t err = FSP_SUCCESS; static usb_pcdc_linecoding_t g_line_coding; usb_instance_ctrl_t event_ctrl = g_basic0_ctrl; do { err = R_USB_EventGet(&event_ctrl, &usb_event); if (err != FSP_SUCCESS) { break; } switch (usb_event) { case USB_STATUS_CONFIGURED: { b_usb_attach = true; err = R_USB_Read( &event_ctrl, g_read_buffer, READ_BUFFER_SIZE, (uint8_t)g_usb_class_type); if (err != FSP_SUCCESS) { printf("USB: starting read failed \r\n"); } break; } case USB_STATUS_WRITE_COMPLETE: { ... } ... default: { break; } } } while (usb_event != USB_STATUS_NONE); }
Here is the descriptor file I copied from the sample project. I'll adjust it to use our vendor ID and manufacturer ID later:
/*********************************************************************************************************************** * File Name : r_usb_pcdc_descriptor.c * Description : USB PCDC Descriptor definition. **********************************************************************************************************************/ /*********************************************************************************************************************** * DISCLAIMER * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all * applicable laws, including copyright laws. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS * SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of * this software. By using this software, you agree to the additional terms and conditions found by accessing the * following link: * http://www.renesas.com/disclaimer * * Copyright (C) 2020 Renesas Electronics Corporation. All rights reserved. ***********************************************************************************************************************/ /****************************************************************************** Includes <System Includes> , "Project Includes" ******************************************************************************/ #include <r_usb_basic.h> #include <r_usb_basic_api.h> #include "r_usb_basic_cfg.h" /****************************************************************************** Macro definitions ******************************************************************************/ /* bcdUSB */ #define USB_BCDNUM (0x0200U) /* Release Number */ #define USB_RELEASE (0x0200U) /* DCP max packet size */ #define USB_DCPMAXP (64U) /* Configuration number */ #define USB_CONFIGNUM (1U) /* Vendor ID */ #define USB_VENDORID (0x298EU) /* Product ID */ #define USB_PRODUCTID (0x07D1U) //#define USB_VENDORID (0x045BU) /* Product ID */ //#define USB_PRODUCTID (0x5310U) /* Class-Specific Configuration Descriptors */ #define USB_PCDC_CS_INTERFACE (0x24U) /* bDescriptor SubType in Communications Class Functional Descriptors */ /* Header Functional Descriptor */ #define USB_PCDC_DT_SUBTYPE_HEADER_FUNC (0x00U) /* Call Management Functional Descriptor. */ #define USB_PCDC_DT_SUBTYPE_CALL_MANAGE_FUNC (0x01U) /* Abstract Control Management Functional Descriptor. */ #define USB_PCDC_DT_SUBTYPE_ABSTRACT_CTR_MANAGE_FUNC (0x02U) /* Union Functional Descriptor */ #define USB_PCDC_DT_SUBTYPE_UNION_FUNC (0x06U) /* Communications Class Subclass Codes */ #define USB_PCDC_CLASS_SUBCLASS_CODE_ABS_CTR_MDL (0x02U) /* USB Class Definitions for Communications Devices Specification release number in binary-coded decimal. */ #define USB_PCDC_BCD_CDC (0x0110U) /* Descriptor length */ #define USB_PCDC_QD_LEN (10U) #define USB_PCDC_CD1_LEN (67U) #define STRING_DESCRIPTOR0_LEN (4U) #define STRING_DESCRIPTOR1_LEN (16U) #define STRING_DESCRIPTOR2_LEN (44U) #define STRING_DESCRIPTOR3_LEN (46U) #define STRING_DESCRIPTOR4_LEN (22U) #define STRING_DESCRIPTOR5_LEN (18U) #define STRING_DESCRIPTOR6_LEN (28U) /* Descriptor data Mask */ #define USB_UCHAR_MAX (0xffU) #define USB_W_TOTAL_LENGTH_MASK (256U) #define USB_W_MAX_PACKET_SIZE_MASK (64U) #define USB_PCDC_BCD_CDC_MASK (256U) /****************************************************************************** Private global variables and functions ******************************************************************************/ /****************************************************************************** Exported global variables ******************************************************************************/ /****************************************************************************** Exported global functions (to be accessed by other files) ******************************************************************************/ /* Standard Device Descriptor */ uint8_t g_apl_device[USB_DD_BLENGTH + ( USB_DD_BLENGTH % 2)] = { USB_DD_BLENGTH, /* 0:bLength */ USB_DT_DEVICE, /* 1:bDescriptorType */ (USB_BCDNUM & (uint8_t) USB_UCHAR_MAX), /* 2:bcdUSB_lo */ ((uint8_t) (USB_BCDNUM >> 8) & (uint8_t) USB_UCHAR_MAX), /* 3:bcdUSB_hi */ USB_IFCLS_CDCC, /* 4:bDeviceClass */ 0, /* 5:bDeviceSubClass */ 0, /* 6:bDeviceProtocol */ (uint8_t) USB_DCPMAXP, /* 7:bMAXPacketSize(for DCP) */ (USB_VENDORID & (uint8_t) USB_UCHAR_MAX), /* 8:idVendor_lo */ ((uint8_t) (USB_VENDORID >> 8) & (uint8_t) USB_UCHAR_MAX), /* 9:idVendor_hi */ ((uint16_t) USB_PRODUCTID & (uint8_t) USB_UCHAR_MAX), /* 10:idProduct_lo */ ((uint8_t) (USB_PRODUCTID >> 8) & (uint8_t) USB_UCHAR_MAX), /* 11:idProduct_hi */ (USB_RELEASE & (uint8_t) USB_UCHAR_MAX), /* 12:bcdDevice_lo */ ((uint8_t) (USB_RELEASE >> 8) & (uint8_t) USB_UCHAR_MAX), /* 13:bcdDevice_hi */ 1, /* 14:iManufacturer */ 2, /* 15:iProduct */ 6, /* 16:iSerialNumber */ USB_CONFIGNUM /* 17:bNumConfigurations */ }; /************************************************************ * Device Qualifier Descriptor * ************************************************************/ uint8_t g_apl_qualifier_descriptor[USB_PCDC_QD_LEN + ( USB_PCDC_QD_LEN % 2)] = { USB_PCDC_QD_LEN, /* 0:bLength */ USB_DT_DEVICE_QUALIFIER, /* 1:bDescriptorType */ (USB_BCDNUM & (uint8_t) USB_UCHAR_MAX), /* 2:bcdUSB_lo */ ((uint8_t) (USB_BCDNUM >> 8) & (uint8_t) USB_UCHAR_MAX), /* 3:bcdUSB_hi */ 0, /* 4:bDeviceClass */ 0, /* 5:bDeviceSubClass */ 0, /* 6:bDeviceProtocol */ (uint8_t) USB_DCPMAXP, /* 7:bMAXPacketSize(for DCP) */ USB_CONFIGNUM, /* 8:bNumConfigurations */ 0 /* 9:bReserved */ }; /************************************************************ * Configuration Or Other_Speed_Configuration Descriptor * ************************************************************/ /* For Full-Speed */ uint8_t g_apl_configuration[USB_PCDC_CD1_LEN + ( USB_PCDC_CD1_LEN % 2)] = { USB_CD_BLENGTH, /* 0:bLength */ USB_SOFT_CHANGE, /* 1:bDescriptorType */ USB_PCDC_CD1_LEN % USB_W_TOTAL_LENGTH_MASK, /* 2:wTotalLength(L) */ USB_PCDC_CD1_LEN / USB_W_TOTAL_LENGTH_MASK, /* 3:wTotalLength(H) */ 2, /* 4:bNumInterfaces */ 1, /* 5:bConfigurationValue */ 0, /* 6:iConfiguration */ USB_CF_RESERVED | USB_CF_SELFP, /* 7:bmAttributes */ (10 / 2), /* 8:MAXPower (2mA unit) */ /* Interface Descriptor */ USB_ID_BLENGTH, /* 0:bLength */ USB_DT_INTERFACE, /* 1:bDescriptor */ 0, /* 2:bInterfaceNumber */ 0, /* 3:bAlternateSetting */ 1, /* 4:bNumEndpoints */ USB_IFCLS_CDCC, /* 5:bInterfaceClass */ USB_PCDC_CLASS_SUBCLASS_CODE_ABS_CTR_MDL, /* 6:bInterfaceSubClass */ 1, /* 7:bInterfaceProtocol */ 0, /* 8:iInterface */ /* Communications Class Functional Descriptorss */ 5, /* 0:bLength */ USB_PCDC_CS_INTERFACE, /* 1:bDescriptorType */ USB_PCDC_DT_SUBTYPE_HEADER_FUNC, /* 2:bDescriptorSubtype */ USB_PCDC_BCD_CDC % USB_W_TOTAL_LENGTH_MASK, /* 3:bcdCDC_lo */ USB_PCDC_BCD_CDC / USB_W_TOTAL_LENGTH_MASK, /* 4:bcdCDC_hi */ /* Communications Class Functional Descriptorss */ 4, /* 0:bLength */ USB_PCDC_CS_INTERFACE, /* 1:bDescriptorType */ USB_PCDC_DT_SUBTYPE_ABSTRACT_CTR_MANAGE_FUNC, /* 2:bDescriptorSubtype */ 2, /* 3:bmCapabilities */ /* Communications Class Functional Descriptorss */ 5, /* 0:bLength */ USB_PCDC_CS_INTERFACE, /* 1:bDescriptorType */ USB_PCDC_DT_SUBTYPE_UNION_FUNC, /* 2:bDescriptorSubtype */ 0, /* 3:bMasterInterface */ 1, /* 4:bSlaveInterface0 */ /* Communications Class Functional Descriptorss */ 5, /* 0:bLength */ USB_PCDC_CS_INTERFACE, /* 1:bDescriptorType */ USB_PCDC_DT_SUBTYPE_CALL_MANAGE_FUNC, /* 2:bDescriptorSubtype */ /* D1:1-Device can send/receive call management information over a Data Class interface. */ /* D0:1-Device handles call management itself. */ 3, /* 3:bmCapabilities */ 1, /* 4:bDataInterface */ /* Endpoint Descriptor 0 */ 7, /* 0:bLength */ USB_DT_ENDPOINT, /* 1:bDescriptorType */ USB_EP_IN | USB_EP3, /* 2:bEndpointAddress */ USB_EP_INT, /* 3:bmAttribute */ 16, /* 4:wMAXPacketSize_lo */ 0, /* 5:wMAXPacketSize_hi */ 0x10, /* 6:bInterval */ /* Interface Descriptor */ USB_ID_BLENGTH, /* 0:bLength */ USB_DT_INTERFACE, /* 1:bDescriptor */ 1, /* 2:bInterfaceNumber */ 0, /* 3:bAlternateSetting */ 2, /* 4:bNumEndpoints */ USB_IFCLS_CDCD, /* 5:bInterfaceClass */ 0, /* 6:bInterfaceSubClass */ 0, /* 7:bInterfaceProtocol */ 0, /* 8:iInterface */ /* Endpoint Descriptor 0 */ USB_ED_BLENGTH, /* 0:bLength */ USB_DT_ENDPOINT, /* 1:bDescriptorType */ USB_EP_IN | USB_EP1, /* 2:bEndpointAddress */ USB_EP_BULK, /* 3:bmAttribute */ USB_W_MAX_PACKET_SIZE_MASK, /* 4:wMAXPacketSize_lo */ 0, /* 5:wMAXPacketSize_hi */ 0, /* 6:bInterval */ /* Endpoint Descriptor 1 */ USB_ED_BLENGTH, /* 0:bLength */ USB_DT_ENDPOINT, /* 1:bDescriptorType */ USB_EP_OUT | USB_EP2, /* 2:bEndpointAddress */ USB_EP_BULK, /* 3:bmAttribute */ USB_W_MAX_PACKET_SIZE_MASK, /* 4:wMAXPacketSize_lo */ 0, /* 5:wMAXPacketSize_hi */ 0, /* 6:bInterval */ }; /* For High-Speed */ uint8_t g_apl_hs_configuration[USB_PCDC_CD1_LEN + ( USB_PCDC_CD1_LEN % 2)] = { 9, /* 0:bLength */ USB_SOFT_CHANGE, /* 1:bDescriptorType */ USB_PCDC_CD1_LEN % USB_W_TOTAL_LENGTH_MASK, /* 2:wTotalLength(L) */ USB_PCDC_CD1_LEN / USB_W_TOTAL_LENGTH_MASK, /* 3:wTotalLength(H) */ 2, /* 4:bNumInterfaces */ 1, /* 5:bConfigurationValue */ 0, /* 6:iConfiguration */ USB_CF_RESERVED | USB_CF_SELFP, /* 7:bmAttributes */ (10 / 2), /* 8:MAXPower (2mA unit) */ /* Interface Descriptor */ 9, /* 0:bLength */ USB_DT_INTERFACE, /* 1:bDescriptor */ 0, /* 2:bInterfaceNumber */ 0, /* 3:bAlternateSetting */ 1, /* 4:bNumEndpoints */ USB_IFCLS_CDCC, /* 5:bInterfaceClass */ USB_PCDC_CLASS_SUBCLASS_CODE_ABS_CTR_MDL, /* 6:bInterfaceSubClass */ 1, /* 7:bInterfaceProtocol */ 0, /* 8:iInterface */ /* Communications Class Functional Descriptorss */ 5, /* 0:bLength */ USB_PCDC_CS_INTERFACE, /* 1:bDescriptorType */ USB_PCDC_DT_SUBTYPE_HEADER_FUNC, /* 2:bDescriptorSubtype */ USB_PCDC_BCD_CDC % USB_PCDC_BCD_CDC_MASK, /* 3:bcdCDC_lo */ USB_PCDC_BCD_CDC / USB_PCDC_BCD_CDC_MASK, /* 4:bcdCDC_hi */ /* Communications Class Functional Descriptorss */ 4, /* 0:bLength */ USB_PCDC_CS_INTERFACE, /* 1:bDescriptorType */ USB_PCDC_DT_SUBTYPE_ABSTRACT_CTR_MANAGE_FUNC, /* 2:bDescriptorSubtype */ 2, /* 3:bmCapabilities */ /* Communications Class Functional Descriptorss */ 5, /* 0:bLength */ USB_PCDC_CS_INTERFACE, /* 1:bDescriptorType */ USB_PCDC_DT_SUBTYPE_UNION_FUNC, /* 2:bDescriptorSubtype */ 0, /* 3:bMasterInterface */ 1, /* 4:bSlaveInterface0 */ /* Communications Class Functional Descriptorss */ 5, /* 0:bLength */ USB_PCDC_CS_INTERFACE, /* 1:bDescriptorType */ USB_PCDC_DT_SUBTYPE_CALL_MANAGE_FUNC, /* 2:bDescriptorSubtype */ /* D1:1-Device can send/receive call management information over a Data Class interface. */ /* D0:1-Device handles call management itself. */ 3, /* 3:bmCapabilities */ 1, /* 4:bDataInterface */ /* Endpoint Descriptor 0 */ 7, /* 0:bLength */ USB_DT_ENDPOINT, /* 1:bDescriptorType */ USB_EP_IN | USB_EP3, /* 2:bEndpointAddress */ USB_EP_INT, /* 3:bmAttribute */ 16, /* 4:wMAXPacketSize_lo */ 0, /* 5:wMAXPacketSize_hi */ 0x10, /* 6:bInterval */ /* Interface Descriptor */ 9, /* 0:bLength */ USB_DT_INTERFACE, /* 1:bDescriptor */ 1, /* 2:bInterfaceNumber */ 0, /* 3:bAlternateSetting */ 2, /* 4:bNumEndpoints */ USB_IFCLS_CDCD, /* 5:bInterfaceClass */ 0, /* 6:bInterfaceSubClass */ 0, /* 7:bInterfaceProtocol */ 0, /* 8:iInterface */ /* Endpoint Descriptor 0 */ 7, /* 0:bLength */ USB_DT_ENDPOINT, /* 1:bDescriptorType */ USB_EP_IN | USB_EP1, /* 2:bEndpointAddress */ USB_EP_BULK, /* 3:bmAttribute */ 0, /* 4:wMAXPacketSize_lo */ 2, /* 5:wMAXPacketSize_hi */ 0, /* 6:bInterval */ /* Endpoint Descriptor 1 */ 7, /* 0:bLength */ USB_DT_ENDPOINT, /* 1:bDescriptorType */ USB_EP_OUT | USB_EP2, /* 2:bEndpointAddress */ USB_EP_BULK, /* 3:bmAttribute */ 0, /* 4:wMAXPacketSize_lo */ 2, /* 5:wMAXPacketSize_hi */ 0, /* 6:bInterval */ }; /************************************* * String Descriptor * *************************************/ /* UNICODE 0x0409 English (United States) */ uint8_t g_cdc_string_descriptor0[STRING_DESCRIPTOR0_LEN + ( STRING_DESCRIPTOR0_LEN % 2)] = { STRING_DESCRIPTOR0_LEN, /* 0:bLength */ USB_DT_STRING, /* 1:bDescriptorType */ 0x09, 0x04 /* 2:wLANGID[0] */ }; /* iManufacturer */ uint8_t g_cdc_string_descriptor1[STRING_DESCRIPTOR1_LEN + ( STRING_DESCRIPTOR1_LEN % 2)] = { STRING_DESCRIPTOR1_LEN, /* 0:bLength */ USB_DT_STRING, /* 1:bDescriptorType */ 'R', 0x00, /* 2:wLANGID[0] */ 'E', 0x00, 'N', 0x00, 'E', 0x00, 'S', 0x00, 'A', 0x00, 'S', 0x00, }; /* iProduct */ uint8_t g_cdc_string_descriptor2[STRING_DESCRIPTOR2_LEN + ( STRING_DESCRIPTOR2_LEN % 2)] = { STRING_DESCRIPTOR2_LEN, /* 0:bLength */ USB_DT_STRING, /* 1:bDescriptorType */ 'C', 0x00, 'D', 0x00, 'C', 0x00, ' ', 0x00, 'U', 0x00, 'S', 0x00, 'B', 0x00, ' ', 0x00, 'D', 0x00, 'e', 0x00, 'm', 0x00, 'o', 0x00, 'n', 0x00, 's', 0x00, 't', 0x00, 'r', 0x00, 'a', 0x00, 't', 0x00, 'i', 0x00, 'o', 0x00, 'n', 0x00, }; /* iInterface */ uint8_t g_cdc_string_descriptor3[STRING_DESCRIPTOR3_LEN + ( STRING_DESCRIPTOR3_LEN % 2)] = { STRING_DESCRIPTOR3_LEN, /* 0:bLength */ USB_DT_STRING, /* 1:bDescriptorType */ 'C', 0x00, 'o', 0x00, 'm', 0x00, 'm', 0x00, 'u', 0x00, 'n', 0x00, 'i', 0x00, 'c', 0x00, 'a', 0x00, 't', 0x00, 'i', 0x00, 'o', 0x00, 'n', 0x00, 's', 0x00, ' ', 0x00, 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 's', 0x00 }; /* iConfiguration */ uint8_t g_cdc_string_descriptor4[STRING_DESCRIPTOR4_LEN + ( STRING_DESCRIPTOR4_LEN % 2)] = { STRING_DESCRIPTOR4_LEN, /* 0:bLength */ USB_DT_STRING, /* 1:bDescriptorType */ 'F', 0x00, /* 2:wLANGID[0] */ 'u', 0x00, 'l', 0x00, 'l', 0x00, '-', 0x00, 'S', 0x00, 'p', 0x00, 'e', 0x00, 'e', 0x00, 'd', 0x00 }; /* iConfiguration */ uint8_t g_cdc_string_descriptor5[STRING_DESCRIPTOR5_LEN + ( STRING_DESCRIPTOR5_LEN % 2)] = { STRING_DESCRIPTOR5_LEN, /* 0:bLength */ USB_DT_STRING, /* 1:bDescriptorType */ 'H', 0x00, /* 2:wLANGID[0] */ 'i', 0x00, '-', 0x00, 'S', 0x00, 'p', 0x00, 'e', 0x00, 'e', 0x00, 'd', 0x00 }; /* iSerialNumber */ uint8_t g_cdc_string_descriptor6[STRING_DESCRIPTOR6_LEN + ( STRING_DESCRIPTOR6_LEN % 2)] = { STRING_DESCRIPTOR6_LEN, /* 0:bLength */ USB_DT_STRING, /* 1:bDescriptorType */ '0', 0x00, /* 2:wLANGID[0] */ '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '0', 0x00, '1', 0x00, }; uint8_t *g_apl_string_table[] = { g_cdc_string_descriptor0, g_cdc_string_descriptor1, g_cdc_string_descriptor2, g_cdc_string_descriptor3, g_cdc_string_descriptor4, g_cdc_string_descriptor5, g_cdc_string_descriptor6 }; /****************************************************************************** Renesas Abstracted Peripheral Communications Devices Class Driver API functions ******************************************************************************/ /****************************************************************************** End Of File ******************************************************************************/
Could you please help find out where is the problem for the descriptor failure? Also, how can I test the USB features on the device? Is there a way to send some string from Windows side or from the device side?
Thanks!
Hi pilot,
Thanks for reaching out to Renesas Engineering Community.
Have you been able to use usb_pcdc example first ? https://github.com/renesas/ra-fsp-examples/tree/master/example_projects/ek_ra6m5/usb_pcdc
Please follow the instructions and make sure that jumper J12 placement is pins 2-3 and J15 pins are connected.
I hope it helps.
Regards,
AZ
Hi AZ,
Thanks for the info. I tried the RA6M4 evaluation board. The USB seems working.
I'll look into my implementation to figure out where the problem is.
Thanks again!