APPLICATION NOTE Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R01AN0512EJ0210 Rev.2.10 Apr 1, 2013 Introduction This document is an application note for Renesas USB MCU and USB ASSP. USB basic firmware, a sample program for USB interface control using Renesas USB MCU and USB ASSP.
Renesas USB MCU and USB ASSP 5. 6. 7. 8. 9. USB Basic Host and Peripheral firmware 4.4 Peripheral Control Transfer 52 4.5 Data Transfer 54 4.6 Pipe Definition 57 4.7 Descriptor 59 4.8 Peripheral sample program 60 4.9 How to run USB‐BASIC‐FW in peripheral mode 63 Host 69 5.1 Host Control Driver (HCD) 69 5.2 Host Manager (MGR) 69 5.3 API (Application Programming Interface) 71 5.4 Host call‐back functions 109 5.5 Structure Definitions 112 5.
Renesas USB MCU and USB ASSP 9.2 10. USB Basic Host and Peripheral firmware How to register in RTOS 149 Debug Information Output 150 10.1 When the debug information is output on the console window (HEW) 150 10.2 When the debug information is outputted to UART 150 10.3 Debug Information macros 150 11. DTC/EXDMA Transfer 151 11.1 Overview 151 11.2 How to DTC/EXDMA transfer in the sample program 154 12. Limitations R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP 1. 1.1 USB Basic Host and Peripheral firmware Document Overview Overview This document is an instruction manual for USB Basic Host and Peripheral firmware, a sample program for USB control using Renesas USB MCU and USB ASSP This firmware includes a uITRON version and an OS-less version. This document is intended to be used together with the device’s data sheet of “1.2 Related Documents”. 1.2 Related Documents 1. Universal Serial Bus Revision 2.0 specification 【http://www.
Renesas USB MCU and USB ASSP 1.3 USB Basic Host and Peripheral firmware List of Terms Terms and abbreviations used in this document are listed below.
Renesas USB MCU and USB ASSP 2. USB Basic Host and Peripheral firmware Overview 2.1 Development Goals USB-BASIC-FW was developed with the following goals in mind. • To simplify the development of USB communication programs by customers using Renesas. • To provide source code examples for hardware control of USB. 2.2 Features of USB-BASIC-FW The main features of USB-BASIC-FW are as follows. 2.2.1 Overall • Can control RX62N, RX63N, RX630, RX63T ,R8A66597 and R8A66593 by common source code.
Renesas USB MCU and USB ASSP 2.3 USB Basic Host and Peripheral firmware Function USB-BASIC-FW source code includes files for Host, Peripheral (Function) and common code.
Renesas USB MCU and USB ASSP 2.4.2 USB Basic Host and Peripheral firmware List of files The files provided in USB-BASIC-FW are listed below. The Project columns indicate whether a file is included in a build configuration: P = The file is included in the PERI build configuration. H = The file is included in the HOST build configuration. PH = The file is included in the PERI_HOST build configuration. The source file that is highlighted to aqua color may be referred to, and modified by the user.
Renesas USB MCU and USB ASSP HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB USB Basic Host and Peripheral firmware dbsct.c Section Initialize resetprg.c Reset program rx_mcu.c MCU setting keydriver.c lcddriver.c adcdriver.c leddriver.c scidriver.c r_usb_creg_abs.c r_usb_creg_dmadtc.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Table 2-2 List of Source file (RTOS ) Folder HCD HCD HCD HCD HCD HCD PCD PCD PCD PCD PCD LIB LIB LIB LIB LIB LIB hubd SMPL SMPL SMPL ANSI ANSI ANSI ANSI SmplMain SmplMain SmplMain SmplMain SmplMain VENDOR VENDOR VENDOR VENDOR VENDOR VENDOR VENDOR File Name r_usb_hcontrolrw.c r_usb_hdriver.c r_usb_hdriverapi.c r_usb_hintfifo.c r_usb_hmanager.c r_usb_hstdfunction r_usb_pcontrolrw.c r_usb_pdriver.c r_usb_pdriverapi.c r_usb_pintfifo.
Renesas USB MCU and USB ASSP HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB HwResource ForUSB USB Basic Host and Peripheral firmware r_usb_host.cfg Configuration file for RTOS resource r_usb_perihost.cfg Configuration file for RTOS resource r_usb_peri.
Renesas USB MCU and USB ASSP 2.5 USB Basic Host and Peripheral firmware Software Configuration In peripheral mode, USB-BASIC-FW comprises the peripheral driver (PCD), and the application (APL). PDCD is the class driver and not part of the USB-BASIC-F/W. See Table 2-3. In host mode, USB-BASIC-FW comprises the host driver (HCD), the manager (MGR), the hub class driver (HUBCD) and the application (APL).
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware User Programming Layer Peripheral Mode Host Mode 8 Application (APL) 8 Application (APL) 7 Device driver (HDD) 6 Device class driver (HDCD) Scheduler Function (non-OS) uITRON 6 Device class driver (PDCD) 4 Manager Task (MGR) 5 HUB Task (HUBCD) 3 Host Driver Task (HCD) 2 Peripheral Driver Task (PCD) 1 USB Interrupt Handler USB - BASIC - F/W Hardware Figure 2-1 Task Configuration of USB-BASIC-FW Table 2-3 Software function over
Renesas USB MCU and USB ASSP 2.7 USB Basic Host and Peripheral firmware Host and Peripheral Sample Vendor Demo USB-BASIC-FW includes a sample “vendor class application” task for both host and peripheral. These interact with eachother when connected - even if on the same MCU. Data is transferred in both directions using endpoints EP1 to EP4: 2.8 1. The peripheral will send a byte which is incremented from 0x00 to 0xFF using EP1 IN and EP3 IN. 2.
Renesas USB MCU and USB ASSP 3. USB Basic Host and Peripheral firmware How to Register Class Driver The class driver which the user created functions as the USB class driver by registering with USB-BASIC-FW. 3.1 How to register Peripheral Class Driver Please consult function usb_papl_registration () in r_usb_vendor_papl.c and register the class driver into USB-BASICFW. For details, please refer to Chapter 4.3.1.
Renesas USB MCU and USB ASSP 3.2 USB Basic Host and Peripheral firmware How to register Host Class Driver Please consult function usb_hapl_registration () in r_usb_vendor_hapl.c and register the class driver into USB-BASICFW. For details, please refer to the Chapter 5.5.2. The following describes how to register user-created class drivers and applications in USB-BASIC-FW. void usb_hapl_registration(USB_UTR_t *ptr) { USB_HCDREG_t driver; /* Driver registration */ /* Interface Class */ driver.
Renesas USB MCU and USB ASSP 4. USB Basic Host and Peripheral firmware Peripheral 4.1 Peripheral Control Driver (PCD) 4.1.1 Basic functions PCD is a program for controlling the hardware. PCD analyzes requests from PDCD (not part of the USB-BASIC-F/W) and controls the hardware accordingly. It also sends notification of control results using a user provided call-back function. PCD also analyzes requests from hardware and notifies PDCD accordingly. PCD accomplishes the following: 1. 2. 3. 4. 5. 6. 7.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Table 4-1 Peripheral Function Used Control Transfer Stage Control read Control write Control w/o data Control read status Control write status Control transfer end 4.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware on which transfer type was used for the pipe (endpoint). Use the control API with the USB_CTL_RD_LENGTH_GET or USB_CTL_WR_LENGTH_GET parameter. The user data in these data transfer arrays beyond the length returned by the control call is not to be used . Such data is old (from previous transfer). R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware open Enable USB peripheral device class communication and confirm Format int16_t open (int8_t *name, uint16_t mode, uint16_t flg) Arguments *name Class code : USB_CLASS_PSTD_BULK / USB_CLASS_PSTD_INT mode Mode ( Not used, set to 0) flg Flag (Not used, set to 0) Return Value - File number.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example int16_t usb_smp_fn; void usb_apl_task() { : usb_smp_fn = open((int8_t *) USB_CLASS_PSTD_BULK, 0, 0); if(usb_smp_fn != -1) { /* USB Transfer */ } : } R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware close End USB device class communication Format int16_t close (int16_t fileno) Arguments fileno File number Return Value - Error code Description This function ends the USB device class communication specified by the file number. If the USB device class communication ends successfully, the function sends (0) as the return value. If the communication fails, it returns (-1). Note 1. Call this function from the user application.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware read USB receive Format int32_t read (int16_t fileno, uint8_t *buf, int32_t count) Arguments fileno File number *buf Pointer to data buffer count Data transfer size Return Value - Error code Description This function executes a data receive request for the USB device class specified in the file number.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example int16_t usb_smp_fn; void usb_apl_task() { : /* Set data receive complete notification call-back */ control(usb_smp_fn, USB_CTL_RD_NOTIFY_SET, (void*)&usb_ smp_Read_Notify); /* receiving data request */ read(usb_smp_fn, (uint8_t *)buf, (int32_t)size); /* receiving request status check */ err = control(usb_spvendor_bulk_fn, USB_CTL_GET_READ_STATE, (void*)&state); if(err != USB_CTL_ERR_PROCESS_COMPLETE) { /* Error Processing */ } : }
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware write USB send Format int32_t write (int16_t fileno, uint8_t *buf, int32_t count) Arguments fileno File number *buf Pointer to data buffer count Data transfer size Return Value - Error code Description This function executes a data transmit request for the USB device class specified in the file number. The data transmit function writes data to the FIFO buffer in the specified data transfer size (3rd argument).
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example int16_t usb_smp_fn; void usb_apl_task() { : /* Set data transmit complete notification call-back.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware control Process a control code Format int32_t control (int16_t fileno, USB_CTRLCODE_t code, void *data) Arguments filneno File number code Control code data Pointer to data Return Value - Error code Description This function performs according to the control code. If an unsupported control code is specified, the function sends (-1) as the return value. The following are control codes supported by control.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Note Call this function from the user application. See “4.2.2 General operation using ANSI API”, for more explanation on how to use this function from the context of a user application.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware <USB_CTL_P_GET_DEVICE_INFO> int16_t usb_smp_fn; void usb_apl_task(USB_UTR_t *ptr) { USB_CTL_PARAMETER_t smp_parameter; : smp_parameter.device_information.
Renesas USB MCU and USB ASSP 4.2.3 USB Basic Host and Peripheral firmware PCD API A PDCD module (USB class driver) implements hardware control requests by using the PCD API. The return values of each API function are scheduler macro error codes. A list of PCD API functions is shown in Table 4-3. Any of the functions can be used with the non-ANSI interface.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_PcdOpen Start PCD task Format USB_ER_t R_usb_pstd_PcdOpen (USB_UTR_t *ptr) Arguments *ptr Pointer to a USB transfer structure Return Value [non-OS] USB_E_OK Success [RTOS] - Error code. Please refer to RI600/4 User's manual for RX family Real-time OS. Description [non-OS] This function initializes the pipe information. Return value is always USB_E_OK.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_PcdClose() End PCD task Format USB_ER_t R_usb_pstd_PcdClose(USB_UTR_t *ptr) Arguments *ptr Pointer to a USB Transfer Structure Return Value [non-OS] USB_E_OK Success [RTOS] - Error code. Please refer to RI600/4 User's manual for RX family Real-time OS. Description [non-OS] No processing. Return value is always USB_E_OK. [RTOS] Ending PCD task. Note 1.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_TransferStart() Data transfer request Format USB_ER_t R_usb_pstd_TransferStart(USB_UTR_t *ptr) Arguments *ptr Pointer to a USB Transfer Structure Return Value [non-OS] USB_E_OK Success USB_E_ERROR Failure [RTOS] - Error code. Please refer to RI600/4 User's manual for RX family Real-time OS. Description This function transfers data via the pipe. This function executes data transfer requests to the PCD.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example USB_UTR_t trn_msg[USB_NUM_USBIP][USB_MAXPIPE_NUM + 1]; USB_ER_t usb_smp_task(USB_UTR_t *ptr, uint16_t pipe, uint32_t size, uint8_t *table) { : /* Transfer information setting */ trn_msg[ptr->ip][pipe].msghead = (USB_MH_t)NULL; /* NULL only */ trn_msg[ptr->ip][pipe].keyword = pipe; /* Pipe No*/ trn_msg[ptr->ip][pipe].tranadr = table; /* Pointer to data buffer */ trn_msg[ptr->ip][pipe].
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_TransferEnd Data transfer forced end request Format USB_ER_t R_usb_pstd_TransferEnd(USB_UTR_t *ptr, uint16_t pipe, uint16_t status) Arguments *ptr Pointer to a USB transfer structure pipe Pipe number status USB communication status Return Value [non-OS] USB_E_OK Success USB_E_ERROR Failure [RTOS] - Error code. Please refer to RI600/4 User's manual for RX family Real-time OS.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_PcdChangeDeviceState USB peripheral device state change request Format USB_ER_t R_usb_pstd_PcdChangeDeviceState (USB_UTR_t *ptr, uint16_t state, uint16_t port_no, USB_CB_INFO_t complete) Arguments *ptr Pointer to a USB Transfer Structure state Device state to be transitioned to port_no Port number complete Call-back function executed at end of PCD processing Return Value [non-OS] USB_E_OK Success USB_E_ERROR Failur
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example void usb_smp_task(USB_UTR_t *ptr) { : /* STALL response request */ R_usb_pstd_PcdChangeDeviceState(ptr, USB_DO_STALL, USB_PIPE0, usb_smp_dummy) : } R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_DeviceInformation Get a USB peripheral’s device state information Format void R_usb_pstd_DeviceInformation (USB_UTR_t *ptr, uint16_t *tbl) Arguments *ptr Pointer to a USB Transfer Structure *tbl Pointer to the buffer that the device information is stored. Return Value - - Description This function gets USB peripherals device state information.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_DriverRegistration Register a PDCD Format void R_usb_pstd_DriverRegistration (USB_UTR_t *ptr, USB_PCDREG_t *registinfo) Arguments *ptr Pointer to a USB Transfer Structure *registinfo Pointer to class driver structure. (See section 4.3.1 for information on this structure) Return Value - - Description This function registers the PDCD information, which is registered in the class driver structure, in the PCD.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_PcdTask The PCD Task Format void R_usb_pstd_PcdTask(USB_VP_INT stacd) Arguments stacd Task start code Not used Return Value - - Description This function executes hardware control when running as a USB peripheral. Note 1. Call this in the loop that executes the scheduler processing for non-OS. See “Figure 4-2 Static State Program Flow “for a usage example. 2. This function does not need to be called for RTOS.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_ControlRead FIFO access request for control read transfer Format uint16_t R_usb_pstd_ControlRead(USB_UTR_t *ptr, uint32_t bsize, uint8_t *table) Arguments *ptr Pointer to a USB transfer structure, containing pipe number, read size, etc bsize Transmit data buffer size *table Pointer to transmit data buffer address.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_ControlWrite FIFO access request for control write transfer Format void R_usb_pstd_ControlWrite (USB_UTR_t *ptr, uint32_t bsize, uint8_t *table) Argument *ptr Pointer to a USB transfer structure containing pipe number etc bsize Receive data buffer size for control write transfer *table Receive data buffer address for control write transfer Return Value - - Description During a control transfer data stage, this functio
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_ControlEnd Control transfer end request Format void R_usb_pstd_ControlEnd (USB_UTR_t *ptr, uint16_t status) Argument *ptr Pointer to a USB Transfer Structure status Status Return Value - Description This function issues a request for control transfer status stage execution to PCD. It is called at the control transfer status stage. Besides above arguments, also set the following value for the status argument.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_SetStall Set STALL to PID of PIPE with callback Format void R_usb_pstd_SetStall (USB_UTR_t *ptr, USB_UTR_t complete, uint16_t pipeno) Argument *ptr Pointer to a USB Transfer Structure Complete Callback function pipeno Pipe number Return Value - - Description Set STALL as PID of the pipe number specified by the argument.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_SetPipeStall Set STALL to PID of PIPE (no callback) Format void R_usb_pstd_SetStall (USB_UTR_t *ptr, uint16_t pipeno) Argument *ptr Pointer to a USB Transfer Structure pipeno Pipe number Return Value - - Description Setting STALL as PID for the specified pipe number Note 1. Besides above arguments, also set the following members of the USB Transfer Structure. USB_REGADR_t uint16_t 2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_GetUsbIpAdr Get the USB register base address Format void R_usb_cstd_GetUsbIpAdr ( uint16_t usbip ) Argument usbip USB IP number Return Value USB register base address Description Return USB register base address of the specified USB IP . Note Please call this function from the user application. Example void usb_smp_task( void ) { USB_UTR_t utr; : utr.ip = USB_HOST_USBIP_NUM; utr.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_UsbIpInit Initialize the USB module Format void R_usb_cstd_UsbIpInit ( USB_UTR_t *ptr ) Argument *ptr Pointer to a USB Transfer Structure Return Value - Description Initialize the USB IP module specified by the USB Transfer Structure. Note 1. Besides above arguments, also set the following members of the USB Transfer Structure. USB_REGADR_t uint16_t 2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_ClearHwFunction USB H/W register initialization Format void R_usb_cstd_ClearHwFunction ( USB_UTR_t *ptr ) Argument *ptr Pointer to a USB Transfer Structure Return Value - Description USB H/W register initialization request Note Besides above arguments, also set the following members of the USB Transfer Structure. USB_REGADR_t uint16_t R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_SetRegPipeCtr Set the value of PIPExCTR register Format void R_usb_cstd_SetRegPipeCtr( USB_UTR_t *ptr, uint16_t pipeno, uint16_t data ) Argument *ptr Pointer to a USB Transfer Structure pipeno Pipe number data Setting value to register Return Value - Description Set the value(3rd parameter) to PIPExCTR Register for pipe number(2nd parameter). Note 1.
Renesas USB MCU and USB ASSP 4.2.4 USB Basic Host and Peripheral firmware PCD Call-back functions Table 4-4 R_usb_pstd_TransferStart call-back Call-back Call format Arguments Return values Description Notes Data Transfer Request call-back function (*USB_CB_t)(USB_UTR_t *); USB_UTR_t * Submitted USB_UTR_t pointer ⎯ ⎯ ⎯ This function is executed at data transfer* end.
Renesas USB MCU and USB ASSP 4.3 USB Basic Host and Peripheral firmware Structure Definitions The structures used in USB peripheral mode are described below. They are defined in file usb_ctypedef.h. 4.3.1 USB_PCDREG_t structure The USB_PCDREG_t structure is used to register PDCD information using the function R_usb_pstd_DriverRegsitration. The call-back function registered in USB_PCDREG_t is executed when the device state changes, etc. Table 4-7 lists the members of the USB_PCDREG_t structure.
Renesas USB MCU and USB ASSP 4.3.2 USB Basic Host and Peripheral firmware The USB_REQUEST structure USB_REQUEST_t is the structure where the latest USB request other than the standard request is stored. This structure is used as the argument to the call-back function that was registered in member ctrltrans of the USB_PCDREG_t structure. Table 4-8 shows the member of USB_REQUEST_t structure.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware <Example class request processing function> void usb_pvendor_UsrCtrlTransFunction(USB_UTR_t *ptr, USB_REQUEST_t *preq, uint16_t ctsq) { If (preq->ReqTypeType == USB_CLASS) { /* Switch on control transfer stage.
Renesas USB MCU and USB ASSP 4.4.2 USB Basic Host and Peripheral firmware Note Make sure that the capacity of the user buffer exceeds the transmit/receive data size (Bsize) of the control transfer data stage. 4.5 Data Transfer 4.5.1 Transfer requests When using the ANSI-type interface, use read() or write() to start a data transfer request. When not using the ANSI-type interface, use R_usb_pstd_TransferStart() to start a data transfer.
Renesas USB MCU and USB ASSP 4.5.3 USB Basic Host and Peripheral firmware The USB Communication Structure (USB_UTR_t) The following describes the structure members used for data transfer. USB communication with a connected host or peripheral device, with the exception of control transfer during peripheral operation, can be accomplished by notifying the following structure to PCD. Table 4-9 shows the members of the USB Transfer Structure.
Renesas USB MCU and USB ASSP 2. USB Basic Host and Peripheral firmware USB communication data length (tranlen) Reception or ControlRead transfer: Stores the receive data length. Transmission or ControlWrite transfer: Stores the transmit data length. NoDataControl transfer: Set to 0. The remaining transmit/receive data length is stored after USB communication end. In case of control transfer in host mode, the remaining data length from the data stage is stored. 3.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_pstd_TransferStart() is called and data transfer request executed. After data transfer is complete, the call-back function “complete” that was set in (1) above for is called and the transfer results are notified to PDCD. Refer to 4.5.2, Notification of transfer result. 4.6 Pipe Definition 4.6.
Renesas USB MCU and USB ASSP 1). USB Basic Host and Peripheral firmware Pipe definition item 1 Specify the value to be set in the Pipe Window select register. Pipe select : Specify the selected pipe (USB_PIPE1 to USB_PIPE9) Restrictions 2). Pipe definition item 2 Specify the values to be set in the Pipe Configuration register.
Renesas USB MCU and USB ASSP USB_CUSE USB_D0USE USB_D0DMA USB_D1USE USB_D1DMA : : : : : USB Basic Host and Peripheral firmware CPU access using CFIFO CPU access using D0FIFO DTC/DMA access using D0FIFO CPU access using D1FIFO DTC/DMA access using DD1FIFO See “11. DTC/EXDMA Transfer” about using DTC Restrictions ・ The transaction counter work to the receive direction pipe. ・ No sample program are provided for USBC_D0USE and USBC_D1DMA 7).
Renesas USB MCU and USB ASSP 4.8 Peripheral sample program 4.8.1 Function USB Basic Host and Peripheral firmware USB-BASIC-FW peripheral sample program is configured with a sample vendor class driver and sample application and includes the following functions. ・ Operation confirmation is possible using “USBCommandVerifier.exe". ・ Data transfer with USB-BASIC-FW host sample program (see “5.10 Host Sample Program). ・ Works with the new ANSI-type interface.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Figure 4-1 shows the general flow of the initialization routine from reset state to static state.
Renesas USB MCU and USB ASSP 2. USB Basic Host and Peripheral firmware Main task After initialization, the sample program calls the usb_apl_task_switch function and the device returns to the “static state”. With the sample program is in the static state, enumeration and USB operation is triggered via interrupts. 3. Static state operations: ・ Check for processing requests with scheduler.
Renesas USB MCU and USB ASSP 4.9 USB Basic Host and Peripheral firmware How to run USB-BASIC-FW in peripheral mode This section describes how to operate the USB-BASIC-F/W as a peripheral, using USB-BASIC-FW and sample code as an example. 4.9.1 Device selection Table 4-10 lists the main device hardware resources included in USB-BASIC-FW.. Change the folder name of the device to be operated from “HwResourceForUSB_device name” to “HwResourceForUSB.
Renesas USB MCU and USB ASSP 5. USB Basic Host and Peripheral firmware Low power mode The low power mode may be specified as one of the following two options. #define USB_CPU_LPW_PP #define USB_CPU_LPW_PP USB_LPWR_USE_PP USB_LPWR_NOT_USE_PP //Low Power Mode //Not Low Power Mode 6. External bus operating voltage The external bus operating voltage may be specified as one of the following two options. (Used only by R8A66597/R8A66593) #define USB_LDRVSEL #define USB_LDRVSEL 7. USB_VIF1 USB_VIF3 :1.
Renesas USB MCU and USB ASSP 4.9.3 USB Basic Host and Peripheral firmware Valid configurations listed by device The user system definition information for each device is shown below.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Table 4-14 Valid RX63T user configuration options Setting Item Definition Name 1 ANSI Interface USB_ANSIIO_PP 2 USB0 mode USB_FUNCSEL_USBIP0_PP 4 CPU Byte Endian USB_CPUBYTE_PP 5 Low Power Mode USB_CPU_LPW_PP Setting Value USB_ANSIIO_USE_PP USB_ANSIIO_NOT_USE_PP USB_PERI_PP USB_BYTE_LITTLE_PP USB_BYTE_BIG_PP USB_LPWR_USE_PP USB_LPWR_NOT_USE_PP Remarks (Note) Table 4-15 Valid R8A66597/R8A66953 user configuration options Se
Renesas USB MCU and USB ASSP 4.9.4 USB Basic Host and Peripheral firmware Workspace build configuration USB-BASIC-F/W operation can easily be changed by selecting a different Build Configuration in HEW. Table 4-16 shows operation per respective build configuration. Table 4-16 Build Configuration Build Configuration PERI PERI_HOST Contents of Configuration Operate one port as peripheral. Operate both ports; one as peripheral and one as host.
Renesas USB MCU and USB ASSP 4.9.5 USB Basic Host and Peripheral firmware Peripheral mode example The following uses RX62N in an example to show how to setup USB-BASIC-FW and sample program to operate as a USB peripheral. 1. Select HwResourceForUSB Delete the content of folder "HwResourceForUSB”. Copy and paste the content of "HwResourceForUSB_RX62N" into "HwResourceForUSB". The folders named HwResourceForUSB_XXX are not used by any build configuration. 2.
Renesas USB MCU and USB ASSP 5. USB Basic Host and Peripheral firmware Host 5.1 Host Control Driver (HCD) HCD is a program for controlling the hardware. The functions of HCD are shown below. 1. 2. 3. 4. 5. 6. 7. 8. Control transfer (Control Read, Control Write, No-data Control) and result notification. Data transfer (bulk, interrupt) and result notification. Data transfer suspension (all pipes).
Renesas USB MCU and USB ASSP 5.2.1 USB Basic Host and Peripheral firmware USB Standard Requests MGR enumerates connected devices. The USB standard requests issued by MGR are listed below. The descriptor information obtained from a device is stored temporarily, and this information can be fetched by using the HCD API function.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware 5.3 API (Application Programming Interface) 5.3.1 ANSI API The ANSI API provides an ANSI-type interface for applications enabling the use of the same API for applications of different classes. This ANSI interface is made up of its API functions. USB-BASIC-F/W provides 5 API functions: open(), close(), read(), write(), and control(). The user is discouraged from changing these functions.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware open Establish connection with USB device Format int16_t open (int8_t *name, uint16_t mode, uint16_t flg) Argument *name Class code : USB_CLASS_HSTD_BULK / USB_CLASS_HSTD_INT mode Mode ( Not used, set to 0) flg Flag (Not used, set to 0) Return Value - File number (Success: 0x10 -- 0x1F /Failure: -1) As the File Number is required for subsequent communication using read() and write(), the open() function must be called first.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware close End connection with USB device Format int16_t close (int16_t fileno) Argument fileno File number Return Value - Error code Description This function ends the USB device class communication specified by the file number. If the USB device class communication ends successfully, the function sends (0) as the return value. If the communication fails, it returns (-1). Note 1. Call this function from the user application.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware read USB receive process Format int32_t read(int16_t fileno, uint8_t *buf, int32_t count) Argument fileno File number *buf Pointer to data buffer count Data Transfer size Return Value - Error code Description This function executes a data receive transaction request for the USB device class specified by the file number.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Processing at the time of the completion of reception void usb_smp_Read_Notify(USB_UTR_t *ptr, uint16_t data1, uint16_t data2) { : /* Receiving data length check */ err = control(usb_spvendor_bulk_fn, USB_CTL_RD_LENGTH_GET, (void*)&data_len); if(err != USB_CTL_ERR_PROCESS_COMPLETE) { /* Error Processing */ } : } R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware write USB send process Format int32_t write(int16_t fileno, uint8_t *buf, int32_t count) Argument fileno File number *buf Pointer to data buffer count Data Transfer size Return Value - Error code Description This function executes a data transmit request for the USB device class specified in the file number. The data transmit function writes data to the FIFO buffer in the specified data transfer size (3rd argument).
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Processing at the time of the completion of transmitting void usb_smp_write_Notify(USB_UTR_t *ptr, uint16_t data1, uint16_t data2) { : /* Send data length check */ err = control(usb_spvendor_bulk_fn, USB_CTL_WR_LENGTH_GET, (void*)&data_len); if(err != USB_CTL_ERR_PROCESS_COMPLETE) { /* Error Processing */ } : } R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware control Process according to control code Format int16_t control(int16_t fileno, USB_CTRLCODE_t code, void *data) Argument fileno File number code Control Code *data Pointer to data Return Value - Error code Description This function performs processes according to the control code. If an unsupported control code is specified, the function sends (-1) as the return value. The following are control codes supported by control().
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example <USB_CTL_USBIP_NUM> int16_t usb_smp_fn; void usb_apl_task(USB_UTR_t *ptr) { int16_t num; : /* Confirmation USBIP Number */ control(usb_smp_fn, USB_CTL_USBIP_NUM, (void*) &num); : } <USB_CTL_H_RD_TRANSFER_END> int16_t usb_smp_fn; void usb_apl_task(USB_UTR_t *ptr) { USB_CTL_PARAMETER_t smp_parameter; : smp_parameter.transfer_end.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware <USB_CTL_H_GET_DEVICE_INFO> int16_t usb_smp_fn; void usb_apl_task(USB_UTR_t *ptr) { USB_CTL_PARAMETER_t smp_parameter; : smp_parameter.device_information.tbl = &smp_tbl; /* Getting USB device information */ control(usb_smp_fn, USB_CTL_H_GET_DEVICE_INFO, (void)&smp_parameter); : } <USB_CTL_RD_NOTIFY_SET> <USB_CTL_GET_RD_STATE> <USB_CTL_RD_LENGTH_GET> Please refer to example of "read" function.
Renesas USB MCU and USB ASSP 5.3.3 USB Basic Host and Peripheral firmware HCD API A HDCD module will implement hardware control requests by using the following HCD API. The return values of each API function are scheduler macro error codes. A list of HCD API functions is shown in Table 5.2. Any of the functions can be used with the non-ANSI interface. When compiling “with ANSI”, the first part of the table should not be used in the user application. Table 5.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_TransferStart Data transfer request Format USB_ER_t R_usb_hstd_TransferStart (USB_UTR_t *ptr) Argument *ptr Pointer to USB transfer structure Return Value [non-OS] USB_E_OK Success USB_E_ERROR Failure [RTOS] - Error code. Please refer to RI600/4 User's manual for RX family Real-time OS. Description This function requests HCD to execute data transfer(s) for the pipe specified in the Transfer Structure.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example USB_UTR_t usb_smp_trn_Msg[USB_NUM_USBIP][USB_MAXPIPE_NUM + 1]; USB_ER_t usb_smp_task(USB_UTR_t *ptr, uint16_t pipe, uint32_t size, uint8_t *table) { : /* Transfer information setting */ trn_msg[ptr->ip][pipe].msghead = (USB_MH_t)NULL; /* NULL only */ trn_msg[ptr->ip][pipe].keyword = pipe; /* Pipe no. */ trn_msg[ptr->ip][pipe].tranadr = table; /* Pointer to data buffer */ trn_msg[ptr->ip][pipe].
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_TransferEnd Data transfer forced end request Format USB_ER_t R_usb_hstd_TransferEnd (USB_UTR_t *ptr, uint16_t pipe, uint16_t status) Argument *ptr Pointer to USB transfer structure pipe Pipe number status USB communication status Return Value [non-OS] USB_E_OK Success USB_E_ERROR Failure [RTOS] - Error code. Please refer to RI600/4 User's manual for RX family Real-time OS.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example void usb_smp_task(USB_UTR_t *ptr) { uint16_t status; uint16_t pipe; : pipe = USB_PIPEx status = USB_DATA_STOP /* Transfer end request */ err = R_usb_hstd_TransferEnd(ptr, pipe, status); return err; : } R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_SetPipeRegistration Pipe configuration setting request Format USB_ER_t R_usb_hstd_SetPipeRegistration (USB_UTR_t *ptr, uint16_t *table, uint16_t pipe) Argument *ptr Pointer to USB transfer structure *table Pointer to pipe information table pipe Pipe number Return Value - Error code. (USB_E_OK) Description This function configures the hardware pipes.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_ChangeDeviceState USB device state change request Format USB_ER_t R_usb_hstd_ChangeDeviceState (USB_UTR_t USB_CB_t uint16_t uint16_t *ptr, complete, msginfo, member) Argument *ptr Pointer to USB transfer structure complete Call-back function msginfo USB communication status member Port number Return Value [non-OS] USB_E_OK Success USB_E_ERROR Failure [RTOS] - Error code.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example void usb_smp_task(USB_UTR_t *ptr) { : /* Change state request */ msginfo = USB_MSG_HCD_RESUME; err = R_usb_hstd_ChangeDeviceState(ptr, (USB_CB_t)change_cb, msginfo, port); if(err != USB_OK) { /* Error Processing */ } : } R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_HcdOpen Start HCD Task Format USB_ER_t R_usb_hstd_HcdOpen (USB_UTR_t *ptr) Argument *ptr Pointer to a USB Transfer Structure Return Value [non-OS] USB_E_OK Success [RTOS] - Error code. Please refer to RI600/4 User's manual for RX family Real-time OS. Description [non-OS] This function initializes (clears) the host’s pipe information. Return value is USB_E_OK at any time.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_HcdClose End HCD Task Format USB_ER_t R_usb_hstd_HcdClose (void) Argument - - Return Value [non-OS] USB_E_OK Success [RTOS] - Error code. Please refer to RI600/4 User's manual for RX family Real-time OS. Description [non-OS] No processing. Return value is always USB_E_OK at any time. [RTOS] Ending HCD task. Note 1. Call this function from the user application or class driver (HDCD). 2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_HcdTask HCD Task Format void R_usb_hstd_HcdTask (USB_VP_INT stacd) Argument stacd Task start code (Not used) Return Value - - Description When host, call this function regularly so that the USB H/W IP is controlled continuously by HCD. Note 1. Besides above arguments, also set the following members of the USB Transfer Structure before calling the function. USB_REGADR_t uint16_t 2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_DriverRegistration Register HDCD Format void R_usb_hstd_DriverRegistration (USB_UTR_t *ptr, USB_HCDREG_t *callback) Argument *ptr Pointer to USB transfer structure *callback Pointer to class driver structure Return Value - - Description This function registers the HDCD information, which is registered in the class driver structure, in the HCD.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_SetPipeInfo Copy pipe information to host pipe information table Format void R_usb_hstd_SetPipeInfo (uint16_t *ep_tbl, uint16_t *tmp_tbl, uint16_t length) Argument *ep_tbl Pointer to pipe information table (destination) *tmp_tbl Pointer to pipe information table (source) length Length of table Return Value - - Description Pipe information table is copied from source (*tmp_tble) to destination (*ep_tbl).
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_DeviceInformation Request device information for connected peripheral Format void R_usb_hstd_DeviceInformation (USB_UTR_t *ptr, uint16_t devaddr, uint16_t *tbl) Argument *ptr Pointer to USB transfer structure devaddr Device address *tbl Pointer to the table address where acquired device information is stored Return Value - - Description Information about the peripheral connected to the USB port is acquired.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example void usb_smp_task(void) { : /* Check device information */ R_usb_hstd_DeviceInformation(ptr, devaddr, &tbl); : } R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_ChkPipeInfo Setting the pipe information tabl Format uint16_t R_usb_hstd_ChkPipeInfo(uint16_t speed, uint16_t *EpTbl, uint8_t *Descriptor) Argument speed Device Speed EpTbl Pipe Information Table Descriptor Endpoint Descriptor Return Value USB_DIR_H_IN Set the IN endpoint. USB_DIR_H_OUT Set the OPUT endpoint.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_ReturnEnuMGR Enumeration continuation request (non-OS only) Format void R_usb_hstd_ReturnEnuMGR (USB_UTR_t *ptr, uint16_t cls_result) Argument *ptr Pointer to USB transfer structure cls_result Class check result Return Value - - Description The function transmits a message to MGR requesting continuation of enumeration processing.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_EnuWait Enumeration priority update request (non-OS only) Format void R_usb_hstd_EnuWait (USB_UTR_t *ptr, uint8_t taskID) Argument *ptr Pointer to USB transfer structure taskID Task ID Return Value - - Description An Enumeration priority change request is made.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_MgrChangeDeviceState Connected device state change request Format USB_ER_t R_usb_hstd_MgrChangeDeviceState (USB_UTR_t USB_CB_t uint16_t uint16_t *ptr, complete, msginfo, devaddr) Argument *ptr Pointer to a USB Transfer Structure complete Call-back function msginfo Message information devaddr Device address Return Value [non-OS] USB_E_OK Success USB_E_ERROR Failure [RTOS] - Error code.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example void usb_smp_task(void) { : R_usb_hstd_MgrChangeDeviceState(ptr,(USB_CB_t)&usb_smp_callback, msginfo, devaddr); : } R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_MgrOpen Start the MGR Task Format USB_ER_t R_usb_hstd_MgrOpen (USB_UTR_t *ptr) Argument *ptr Pointer to a USB Transfer Structure Return Value [non-OS] USB_E_OK Success [RTOS] - Error code. Please refer to RI600/4 User's manual for RX family Real-time OS. Description [non-OS] The registration state of HDCD is initialized. Return value is USB_E_OK at any time.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_MgrClose End MGR Task Format USB_ER_t R_usb_hstd_MgrClose(void) Argument *ptr Pointer to USB transfer structure Return Value - - Description [non-OS] No processing. Return value is always USB_E_OK. [RTOS] Ending MGR task. Note 1. Please call this function from the user application or class driver . 2. Please do not call this function after ending MGR task.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hstd_MgrTask MGR Task Format void R_usb_hstd_MgrTask (USB_VP_INT_t stcd) Argument stacd Task start code (Not used) Return Value - - Description When host, call this function continuously to run the Manager (MGR) task. (HDCD sends messages to MGR which in turn calls HCD. Note 1. Call this in the loop that executes the scheduler processing for non-OS operations. 2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_GetUsbIpAdr Get USB register base address Format void R_usb_cstd_GetUsbIpAdr ( uint16_t usbip ) Argument usbip USB IP number Return Value USB register base address Description Return USB register base address of specified USB IP . Note Call this function from the user application. Example void usb_smp_task( void ) { USB_UTR_t utr; : utr.ip = USB_HOST_USBIP_NUM; utr.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_UsbIpInit Initialize USB module Format void R_usb_cstd_UsbIpInit ( USB_UTR_t *ptr ) Argument *ptr Pointer to a USB Transfer Structure Return Value - Description Initialize specified USB IP module. Note 1. Besides above arguments, also set the following members of the USB Transfer Structure. USB_REGADR_t uint16_t 2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_ClearHwFunction USB-Related Register Initialization Format void R_usb_cstd_ClearHwFunction( USB_UTR_t *ptr ) Argument *ptr Pointer to a USB Transfer Structure Return Value - Description USB-Related Register Initialization Request Note Besides above arguments, also set the following members of the USB Transfer Structure. USB_REGADR_t uint16_t R01AN0512EJ0210 Rev.2.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_SetRegDvstctr0 Set DVSTCTR0 register Format void R_usb_cstd_SetRegDvstctr0 ( USB_UTR_t *ptr, uint16_t data ) Argument *ptr Pointer to a USB Transfer Structure data Setting value to register Return Value - - Description Set the value of the second argument to the DVSTCTR0 register. DVSTCTR0 controls the state of the USB data bus. Note 1.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_SetRegPipeCtr Set the value of PIPExCTR register Format void R_usb_cstd_SetRegPipeCtr( USB_UTR_t *ptr, uint16_t pipeno, uint16_t data ) Argument *ptr Pointer to a USB Transfer Structure pipeno Pipe number data Setting value to register Return Value - - Description Set the value of the third parameter to the PIPExCTR register, where ‘x’ is the specified pipe number (second parameter). Note 1.
Renesas USB MCU and USB ASSP 5.4 Host call-back functions 5.4.1 HCD call-backs USB Basic Host and Peripheral firmware Call-backs are used so that the user does not need to poll for events. The user application registers a callback in order to be alerted when, for example, requests made to HCD are completed, and data is has been transferred over USB to the peripheral. By using call-backs the application is propelled forward by the USB USB-BASIC-F/W stack.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Table 5.5 Other call-backs Name Call format Arguments Return values Description Other Call back Functions (*USB_CB_INFO_t)( USB_UTR_t*,uint16_t, uint16_t) USB_UTR_t * Pointer to a USB Transfer Structure uint16_t NOARGUMENT: Not used uint16_t msginfo: Command category - - - The following commands is set to the third argument USB_MSG_HCD_ATTACH: Executed at end of attach processing.
Renesas USB MCU and USB ASSP 5.4.2 USB Basic Host and Peripheral firmware MGR call-backs Table 5.
Renesas USB MCU and USB ASSP 5.5 USB Basic Host and Peripheral firmware Structure Definitions The structures used in USB host mode are described below. They are defined in file usb_ctypedef.h. 5.5.1 USB_HCDINFO_t structure The USB_HCDINFO_t structure is used when transferring messages to HCD. Members of USB_HCDINFO_t Structure are shown in Table 5.8. Table 5.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Table 5.9 USB_HCDREG_t structure members Type uint16_t uint16_t uint16_t uint16_t uint16_t Variable Name rootport devaddr devstate ifclass *tpl uint16_t USB_CB_INFO_t USB_CB_CHECK_t *pipetbl classinit classcheck USB_CB_INFO_t devconfig USB_CB_INFO_t devdetach USB_CB_INFO_t devsuspend USB_CB_INFO_t devresume USB_CB_INFO_t overcurrent R01AN0512EJ0210 Rev.2.10 Apr 1, 2013 Description Used by HCD.
Renesas USB MCU and USB ASSP 5.6 USB Basic Host and Peripheral firmware Target Peripheral List USB-BASIC-FW needs to create a target peripheral list (TPL) for each device class. Please register vendor ID and product ID by a set of the working USB device to TPL. Please set this TPL to the member (tpl) in USB_HCDREG_t structure. (Please refer to "USB_HCDREG_t Structure" in "5.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware The following is an example of a vendor request transmit. USBC_UTR_tusb_gsmp_ControlSetupUtr; USBC_ER_t usb_hsmp_VendorRequestProcess(void) { USBC_ER_t err; /* Set Call-back function */ usb_gsmp_ControlSetupUtr.complete = &usb_smp_VendorRequestResult; /* Transmission pipe setup */ usb_gsmp_ControlSetupUtr.keyword = (uint16_t)USB_PIPE0; usb_gsmp_ControlSetupUtr.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware 5.8 Data Transfer and Control Data Transfer 5.8.1 Data transfer request When using the ANSI IO API interface, use read() or write() to start the data transfer request. When not using the ANSI interface, use R_usb_pstd_TransferStart() to start the data transfer. For more details on the API functions described here, please refer to the corresponding API section. [Note] Control transfer cannot use the ANSI interface.
Renesas USB MCU and USB ASSP 5.8.4 USB Basic Host and Peripheral firmware The USB Communication Structure (USB_UTR_t) The structure used for Control and data transfer is described below. USB communications with the connected device are enabled by notifying HCD of the following structure members. Members of USB_UTR_t Structure are shown in Table 5.10. Table 5.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Additional Communication Structure details for host 1. Buffer address for USB communication (tranadr) Reception or ControlRead transfer: Specifies the address of the buffer for storing receive data. Transmission or ControlWrite transfer: Specifies the address of the buffer for storing transmit data. NoDataControl transfer: Ignored if specified. 2.
Renesas USB MCU and USB ASSP 5.8.6 USB Basic Host and Peripheral firmware Notes on Data Reception Use a transaction counter for the receive pipe. When a short packet is received, the expected remaining receive data length is stored in tranlen of USBC_UTR_t structure and transfer ends. When the received data exceeds the buffer size, data read from the FIFO buffer up to the buffer size and transfer ends.
Renesas USB MCU and USB ASSP 5.9 Pipe Information 5.9.1 Overview USB Basic Host and Peripheral firmware HDCD needs to hold a pipe setup which suited the class driver concerned as a pipe information table. The host sample program has indicated the sample table holding the pipe information on a device to r_usb_vendor_hdefep.c. 5.9.2 Pipe Information Table A pipe information table comprises the following six items (uint16_t × 6). 1. 2. 3. 4. 5. 6.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware 2. Pipe definition item 2 Specify the values to be set in the pipe configuration register. Transfer type BRDY operation designation Double buffer mode Continuous transmit/receive mode SHTNAK operation designation Transfer direction Endpoint number Restrictions : : : : : : : Specify either USB_BULK or USB_INT. Specify USB_BFREOFF. Specify either USB_DBLBON or USB_DBLBOFF. Specify either USB_CNTMDON or USB_CNTMDOFF.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware 6. Pipe definition item 6 Specify the FIFO port to be used for the pipe. USB_CUSE USB_D0USE USB_D0DMA USB_D1USE USB_D1DMA Restrictions : : : : : CFIFO is used and CPU access is carried out. D0FIFO is used and CPU access is carried out. D0FIFO is used and DTC / DMA access is carried out. D1FIFO is used and CPU access is carried out. D1FIFO is used and DTC / DMA access is carried out. (1).
Renesas USB MCU and USB ASSP 5.10 USB Basic Host and Peripheral firmware Host Sample Program USB-BASIC-FW host sample program is configured with a vendor class driver and sample application. It includes the following features. 1. 2. Data transfer with USB-BASIC-FW peripheral sample program (see 5.10 Host Sample Program) ANSI-type API Host–peripheral data communication sample program The host sample program can communicate with a peripheral device also running the USB-BASIC-F/W sample code.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware 2. The ‘Static State’ After initialization, the sample program calls usb_apl_task_switch and the device returns to the “static state” (initialization done, but not enumeration ). usb_apl_task_switch is a never ending loop which continuously does the following. (1). Checks for processing requests with the scheduler. (2). If processing requests are present, it selects the task with highest priority and sets the task processing request flag.
Renesas USB MCU and USB ASSP 5.11 USB Basic Host and Peripheral firmware How to work USB-BASIC-FW as Host mode This section describes how to operate the USB-BASIC-F/W as a host, using USB-BASIC-FW and sample code as an example. 5.11.1 Device selection Table 5.12 lists the main device hardware resources included in USB-BASIC-FW. Change the folder name of the device to be operated from “HwResourceForUSB_device name” to “HwResourceForUSB.” Table 5.
Renesas USB MCU and USB ASSP 5. USB Basic Host and Peripheral firmware Low power mode The low power mode may be specified as one of the following two options。 #define USB_CPU_LPW_PP #define USB_CPU_LPW_PP 6. USB_LPWR_USE_PP USB_LPWR_NOT_USE_PP :Low Power Mode :Not Low Power Mode External bus operating voltage The external bus operating voltage may be specified as one of the following two options. (Used only by R8A66597) #define USB_LDRVSEL #define USB_LDRVSEL 7. USB_VIF1 USB_VIF3 :1.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Valid configurations listed by device The user configuration for each device is shown in Table 5.17 from Table 5.13. Table 5.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Table 5.16 Valid RX63T user configuration options Setting Item Definition Name 1 ANSI Interface USB_ANSIIO_PP 2 USB0 mode USB_FUNCSEL_USBIP0_PP 4 CPU Byte Endian USB_CPUBYTE_PP 5 Low Power Mode USB_CPU_LPW_PP Setting Value USB_ANSIIO_USE_PP USB_ANSIIO_NOT_USE_PP USB_HOST_PP USB_BYTE_LITTLE_PP USB_BYTE_BIG_PP USB_LPWR_USE_PP USB_LPWR_NOT_USE_PP Remarks (Note) Table 5.
Renesas USB MCU and USB ASSP 5.11.3 USB Basic Host and Peripheral firmware Workspace build configuration File inclusion and exclusion, depending on whether host or peripheral functionality (or both) was selected in the user configuration file r_usb_usrconfig.h, is changed simply be selecting the proper Build Configuration. Table 5.18 shows the operation per respective Build Configuration . Table 5.
Renesas USB MCU and USB ASSP 5.11.4 USB Basic Host and Peripheral firmware Host mode example The following uses RX62N as an example to show the setup routine that enables USB-BASIC-FW and the sample program to operate as host. 1. Selecting HwResourceForUSB Change the folder name from "HwResourceForUSB_RX62N" to "HwResourceForUSB". 2. Selecting USB mode (Host/Peripheral) Set macros USB_FUNCSEL_USBIP0_PP and USB_FUNCSEL_USBIP1_PP in the user definition information file (r_usb_usrconfig.h) as follows.
Renesas USB MCU and USB ASSP 6. 6.1 USB Basic Host and Peripheral firmware HUB Class Basic Functions HUBCD is a task that manages the states of the down ports of a connected USB hub and supplements the functions of HCD and HDCD. HUBCD performs the following functions. 1. State management for devices connected to the USB hub down ports 2. Enumeration of devices connected to the USB hub down ports 6.2 HUBCD API Functions Table 6.1 lists the API functions of HUBCD. Table 6.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_ usb_hstd_HubRegistAll Register HUBCD Format void R_ usb_hstd_HubRegistAll(USB_UTR_t *ptr, USB_HCDREG_t *callback) Argument *ptr Pointer to a USB Transfer Structure *callback Pointer to Class driver structure Return Value - - Description The information on HUBCD is registered into a class driver structure. After registration is complete, the initialization call-back function is executed. Note 1.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_hhub_Task HUB Task Format void R_usb_hhub_Task(USB_VP_INT stacd) Argument stacd Task start code (Not used) Return Value - - Description At the time of selection of a host, the state of the down port of the connected USB hub is managed, and the function between HCD and HDCD is complemented. Note 1. Call this in the loop that executes the scheduler processing for non-OS operations. 2.
Renesas USB MCU and USB ASSP 6.3 USB Basic Host and Peripheral firmware Down Port State Management When the HUBCD task starts, it performs the following for all down ports and confirms that each down port is in the device connected state. 1. Enable port power (HubPortSetFeature:USB_HUB_PORT_POWER) 2. Initialize port (HubPortClrFeature:USB_HUB_C_PORT_CONNECTION) 3. Get port status (HubPortStatus:USB_HUB_PORT_CONNECTION) 6.
Renesas USB MCU and USB ASSP 7. non-OS Scheduler 7.1 Overview USB Basic Host and Peripheral firmware The non-OS scheduler executes task scheduling according to task priority. The following are non-OS task scheduler features. ・ A scheduler function manages requests generated by the tasks and interrupt etc according to the relative priority of the tasks. ・ When multiple requests are generated by tasks with the same priority, they are executed using a FIFO configuration.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_SndMsg Sends processing requests to the priority table Format USB_ER_t R_usb_cstd_SndMsg(uint8_t id, USB_MSG_t *mess) Argument id Task ID to send message.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example void usb_smp_task() { USB_MH_t p_blf; USB_ER_t err; USB_PCDINFO_t *pp; : /*Allocating the messsage store area */ err = R_USB_PGET_BLK(USB_PVENDOR_MPL, &p_blf); if(err == USB_OK) { /* Setting Message */ pp = (USB_CLSINFO_t*)p_blf; pp->msghead = (USB_MH_t)NULL; pp->msginfo = USB_SMP_REQ; pp->keyword = keyword; pp->complete = complete; pp->ip = ptr->ip; pp->ipp = ptr->ipp; } /* Send the message */ err = R_USB_SND_MSG(USB_SMP_MBX, (US
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_iSndMsg Sends processing requests from interrupts to the priority table.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Example void usb_smp_interrupt() { USB_MH_t p_blf; USB_ER_t err; USB_PCDINFO_t *pp; : /*Allocating the messsage store area */ err = R_USB_PGET_BLK(USB_PVENDOR_MPL, &p_blf); if(err == USB_OK) { /* Setting Message */ pp = (USB_CLSINFO_t*)p_blf; pp->msghead = (USB_MH_t)NULL; pp->msginfo = USB_SMP_REQ; pp->keyword = keyword; pp->complete = complete; pp->ip = ptr->ip; pp->ipp = ptr->ipp; } /* Send the message */ err = R_USB_ISND_MSG(USB_SMP_MB
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_RecMsg Checks if an execution request was issued.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_PgetBlk Allocates an area for storing a request information table. Format USB_ER_t R_usb_cstd_PgetBlk(uint8_t id, USB_UTR_t **blk) Argument id Task ID of allocating area **blk Pointer to allocating area Return Value USB_E_OK The area is allocated USB_E_ERROR Task ID is not set The area is not secured Description This function secures an area for storing a message. The function allocates 40 bytes per block.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_RelBlk Releases an area used for storing a request information table Formant USB_ER_t R_usb_cstd_RelBlk(uint8_t id, USB_UTR_t* blk) Argument id Task ID of releasing area . *blk Pointer to released area Return Value USB_E_OK The area is released USB_E_ERROR Task is not set The area is not released Description This function releases an area for storing a message. The function is defined in the R_USB_REL_BLK macro.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_Scheduler Manages requests generated by the tasks Format void R_usb_cstd_Scheduler(void) Argument - - Return Value - - Description Managing requests generated by the tasks and hardware according to the relative priority of the tasks Note Call this function in the loop that executes the scheduler processing for non-OS operations.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_SetTaskPri Set Task Priority Format void R_usb_cstd_SetTaskPri(uint8_t tasknum, uint8_t pri) Argument tasknum Task ID pri Task Priority Return Value - - Description Set the priority to the task. This function sets the priority of the task. Priority (pri) specified in 2nd argument is set to the task specified in the 1st argument (tasknum). Note 1.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware R_usb_cstd_CheckSchedule Checks whether or not processing is scheduled. Format uint8_t R_usb_cstd_CheckSchedule(void) Argument - - Return Value USB_FLGSET Processing request USB_FLGCLR No processing request Description Checks whether or not processing is scheduled. Note Call this in the loop that executes the scheduler processing for non-OS operations.
Renesas USB MCU and USB ASSP 8. USB Basic Host and Peripheral firmware uITRON system 8.1 Overvies RTOS operations use the RX Family real time OS RI600/4, manufactured by Renesas Electronics. For details concerning RI600/4, refer to the RI600/4 User’s Manual (RX Family Real Time OS). 8.2 GUI configurator RTOS uses the GUI configurator packaged with RI600/4 to set the system definitions, time management, system resources, and interrupt handlers.
Renesas USB MCU and USB ASSP 8.4 USB Basic Host and Peripheral firmware uITRON Task start RTOS calls the vsta_knl() in the initialization routine (PowerON_Reset_PC()) function and runs the kernel. After the kernel is run, the usb_cstd_main_task() function is started, all other tasks are started, and then the main task goes to the DOMANT state. 8.5 uITRON Systemcall Table 8-4 shows the system calls used in RTOS.
Renesas USB MCU and USB ASSP 9. 9.1 USB Basic Host and Peripheral firmware How to register in non-OS/RTOS How to register in non-OS The following settings are required to register class drivers and applications in non-OS. For details on schedulers used by non-OS, refer to chapter 6. Non-OS Scheduler. 1. 2. 3. 4. (1). Scheduler settings Task information settings Task registrations in scheduler Task calls Setup of scheduler Set the following items in USB-BASIC-FW r_usb_cKernelid.h file.
Renesas USB MCU and USB ASSP (4). USB Basic Host and Peripheral firmware Calling the application task The following shows the point of calling the application task. a). If the application task uses non-OS scheduler API Please call the application task at the "Inside of the scheduler management" or "outside of the sckeduler management".
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware 10. Debug Information Output When the user describes the debug information output macro from the user application, the user can output the debug information on the console window (HEW). 10.1 When the debug information is output on the console window (HEW) The following shows the debug information output procedure. 1. Please use the following debug macro in the user application to output user debugprint.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware 11. DTC/EXDMA Transfer 11.1 Overview In RX62N, RX63N, RX63T and RX630, when D0FIFO access (USBC_D0DMA) is specified in the pipe information table, USB-BASIC-FW uses the DTC for FIFO access. In RX6N + R8A6667, FIFO access between SDRAM on RX62N-RSK and R8A66597 is used EXDMA. Note that the DTC/EXDMA is a system-dependent function, so the settings for transfer method, access timing, communication start/end timing, DTC/EXDMA, etc.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Table11-3 R8A66597/R8A66593 DMA Setting Specification Setting DMA transfer signal selection (DFORM) Figure 11-1 11.1.
Renesas USB MCU and USB ASSP 11.1.3 USB Basic Host and Peripheral firmware Notes on Data Reception When the received data exceeds the buffer size, data is read from the FIFO buffer up to the buffer size and transfer ends. In Host mode, when the pipe information table is updated in the HCD API function, the following settings are implemented. Please carry out the following setup to a pipe information table at the time of Peripheral operation. • Enable the SHTNAK function for the data receive pipe.
Renesas USB MCU and USB ASSP 11.2 USB Basic Host and Peripheral firmware How to DTC/EXDMA transfer in the sample program The Ep table must be edited in order to execute a DTC transfer in the sample application. 11.2.1 Pipe information table setting for DTC/EXDMA transfer in the Host sample program Edit Ep table “usb_shvendor_smpl_tmp_eptbl” which is in the “r_usb_hvendor_defep.c”.
Renesas USB MCU and USB ASSP 11.2.2 USB Basic Host and Peripheral firmware Pipe information table setting for DTC/EXDMA transfer in the Peripheral sample program Edit Ep table “usb_gpvendor_smpl_eptbl1” which is in the “r_usb_vendor_descriptor.c”.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware 12. Limitations USB-BASIC-FW is subject to the following restrictions. 1. The pipe usage methods are limited by the pipe information setting functions. The receive pipe uses the transaction counter with the SHTNAK function. 2. The structures contain members of different types. (Depending on the compiler, the address alignment of the structure members may be shifted.) 3. PDCD/HDCD must be prepared by the customer. 4.
Renesas USB MCU and USB ASSP USB Basic Host and Peripheral firmware Website and Support Renesas Electronics Website http://www.renesas.com/ Inquiries http://www.renesas.com/inquiry All trademarks and registered trademarks are the property of their respective owners. R01AN0512EJ0210 Rev.2.
Revision Record Rev. 1.00 1.08 Date Jan 31, 2011 May 31, 2011 Description Page — — — — 2.00 2.01 2.10 Jun. 01.2012 Jan. 31.2013 Apr. 01.2013 — — — — Summary First edition issued Target device is added : RX630, R8A66597 Chapter composition is changed: - “6.Sample Program” is divided into “6.Workspace”, “7.Sample Applications”, “13.Non-OS Scheduler” and “14.uITRON System” - “14.General-purpose library” is deleted - “18.EXDMA Transfer” is added 17.
General Precautions in the Handling of MPU/MCU Products The following usage notes are applicable to all MPU/MCU products from Renesas. For detailed usage notes on the products covered by this document, refer to the relevant sections of the document as well as any technical updates that have been issued for the products. 1. Handling of Unused Pins Handle unused pins in accord with the directions given under Handling of Unused Pins in the manual.
Notice 1. Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples. You are fully responsible for the incorporation of these circuits, software, and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits, software, or information. 2.