/*********************************************************************************************************************** * 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) 2015(2016) Renesas Electronics Corporation. All rights reserved. ***********************************************************************************************************************/ /******************************************************************************* * File Name : r_usb_pcdc_echo_apl.c * Description : USB Peripheral Communications Devices Class Sample Code ******************************************************************************* * History : DD.MM.YYYY Version Description * : 30.09.2015 2.20 First Release * : 30.09.2016 2.30 Using new USB API. ******************************************************************************/ /****************************************************************************** Includes , "Project Includes" ******************************************************************************/ #include "r_usb_pcdc_apl.h" #if OPERATION_MODE == USB_ECHO /****************************************************************************** Macro definitions ***************************************************************************#***/ /****************************************************************************** Private global variables and functions ******************************************************************************/ static void usb_pin_setting (void); static uint8_t g_buf[DATA_LEN]; const static usb_descriptor_t usb_descriptor = { g_apl_device, /* Pointer to the device descriptor */ g_apl_configuration, /* Pointer to the configuration descriptor for Full-speed */ USB_NULL, /* Pointer to the configuration descriptor for Hi-speed */ USB_NULL, /* Pointer to the qualifier descriptor */ g_apl_string_table /* Pointer to the string descriptor table */ }; /****************************************************************************** Renesas Peripheral Communications Devices Class Sample Code functions ******************************************************************************/ /****************************************************************************** Function Name : usb_main Description : Peripheral CDC application main process Arguments : none Return value : none ******************************************************************************/ void usb_main (void) { usb_ctrl_t ctrl; usb_cfg_t cfg; usb_pin_setting(); /* USB MCU pin setting */ ctrl.module = USE_USBIP; ctrl.type = USB_PCDC; cfg.usb_speed = USB_SUPPORT_SPEED; /* USB_HS/USB_FS */ cfg.usb_mode = USB_PERI; cfg.p_usb_reg = (usb_descriptor_t *)&usb_descriptor; R_USB_Open(&ctrl, &cfg); /* Initializes the USB module */ /* Loop back between PC(TerminalSoft) and USB MCU */ while (1) { switch (R_USB_GetEvent(&ctrl)) { case USB_STS_CONFIGURED : case USB_STS_WRITE_COMPLETE : ctrl.type = USB_PCDC; R_USB_Read(&ctrl, g_buf, DATA_LEN); break; case USB_STS_READ_COMPLETE : R_USB_Write(&ctrl, g_buf, ctrl.size); break; case USB_STS_SUSPEND : case USB_STS_DETACH : #if defined(USE_LPW) low_power_mcu(); #endif /* defined(USE_LPW) */ break; default : break; } } } /* End of function usb_main() */ /****************************************************************************** Function Name : usb_pin_setting Description : USB Pin Setting Arguments : none Return value : none ******************************************************************************/ static void usb_pin_setting (void) { R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_LPC_CGC_SWR); R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_MPC); /* Deep standby USB monitor register (USB0 Transceiver Output fixed) b0 SRPC0 USB0 single end control b3-b1 Reserved 0 b4 FIXPHY0 USB0 transceiver output fix b7-b5 Reserved 0 b8 SRPC1 USB1 single end control b11-b9 Reserved 0 b12 FIXPHY1 USB1 transceiver output fix b15-b13 Reserved 0 b16 DP0 USB0 DP input b17 DM0 USB0 DM input b19-b18 Reserved 0 b20 DOVCA0 USB0 OVRCURA input b21 DOVCB0 USB0 OVRCURB input b22 Reserved 0 b23 DVBSTS0 USB1 VBUS input b24 DP1 USB1 DP input b25 DM1 USB1 DM input b27-b26 Reserved 0 b28 DOVCA1 USB1 OVRCURA input b29 DOVCB1 USB1 OVRCURB input b30 Reserved 0 b31 DVBSTS1 USB1 VBUS input */ USB.DPUSR0R.BIT.FIXPHY0 = 0; /* Enable USB0 port & Pullup & Select Peripheral function b1-b0 USBMD USB mode bit b2 PUPHZS PUPHZ select b3 PDHZS PDHZ select b4 USBE USB enable b7-b5 Reserved 0 */ IOPORT.PFKUSB.BYTE = 0x14; /* Select function mode for the USB0 pins. */ /* Input buffer control register (Enable USB0 VBUS) b0 B0 Pn0 input buffer control bit b1 B1 Pn1 input buffer control bit b2 B2 Pn2 input buffer control bit b3 B3 Pn3 input buffer control bit b4 B4 Pn4 input buffer control bit b5 B5 Pn5 input buffer control bit b6 B6 Pn6 input buffer control bit b7 B7 Pn7 input buffer control bit */ PORT1.ICR.BIT.B6 = 1; R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_MPC); R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_LPC_CGC_SWR); }/* End of function usb_pin_setting */ /****************************************************************************** End of function usb_mcu_init ******************************************************************************/ #endif /* OPERATION_MODE == USB_ECHO */ /****************************************************************************** End Of File ******************************************************************************/