129
APPLICATION NOTE R01AN0512EJ0110 Rev.1.10 Page 1 of 126 Jun 10, 2011 Renesas USB Device USB Basic Firmware Introduction This document is an instruction manual for the Renesas USB Device USB basic firmware, a sample program for USB interface control using the Renesas USB Device. Target Device RX62N, RX630 and R8A66597 Contents 1. Document Overview .......................................................................................................................... 2 2. Overview ........................................................................................................................................... 3 3. Using USB-BASIC-F/W ................................................................................................................... 10 4. User-Defined Macros ...................................................................................................................... 13 5. User-Defined Information ................................................................................................................ 17 6. Workspace ...................................................................................................................................... 28 7. Sample Applications ........................................................................................................................ 33 8. Peripheral Driver (PCD) .................................................................................................................. 41 9. Peripheral Control Transfer ............................................................................................................. 53 10. Host Driver (HCD) ........................................................................................................................... 56 11. Host Control Transfer ...................................................................................................................... 65 12. Host Manager (MGR) ...................................................................................................................... 74 13. Non-OS Scheduler .......................................................................................................................... 89 14. uITRON System .............................................................................................................................. 97 15. HUB class driver(HUBCD) .............................................................................................................. 99 16. Data Transfer ................................................................................................................................ 105 17. DTC Transfer................................................................................................................................. 116 18. EXDMA Transfer ........................................................................................................................... 121 19. Restrictions.................................................................................................................................... 125 R01AN0512EJ0110 Rev.1.10 Jun 10, 2011

Eekol 2012 jan04_int_ems_an_01

  • Upload
    kaomao

  • View
    358

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Citation preview

  • 1. APPLICATION NOTERenesas USB Device R01AN0512EJ0110Rev.1.10USB Basic FirmwareJun 10, 2011IntroductionThis document is an instruction manual for the Renesas USB Device USB basic firmware, a sample program for USBinterface control using the Renesas USB Device.Target DeviceRX62N, RX630 and R8A66597Contents 1. Document Overview .......................................................................................................................... 2 2. Overview ........................................................................................................................................... 3 3. Using USB-BASIC-F/W................................................................................................................... 10 4. User-Defined Macros ...................................................................................................................... 13 5. User-Defined Information ................................................................................................................ 17 6. Workspace ...................................................................................................................................... 28 7. Sample Applications........................................................................................................................ 33 8. Peripheral Driver (PCD) .................................................................................................................. 41 9. Peripheral Control Transfer............................................................................................................. 53 10. Host Driver (HCD) ........................................................................................................................... 56 11. Host Control Transfer ...................................................................................................................... 65 12. Host Manager (MGR) ...................................................................................................................... 74 13. Non-OS Scheduler .......................................................................................................................... 89 14. uITRON System .............................................................................................................................. 97 15. HUB class driver(HUBCD) .............................................................................................................. 99 16. Data Transfer ................................................................................................................................ 105 17. DTC Transfer................................................................................................................................. 116 18. EXDMA Transfer ........................................................................................................................... 121 19. Restrictions.................................................................................................................................... 125R01AN0512EJ0110 Rev.1.10Page 1 of 126Jun 10, 2011

2. USB Basic Firmware1. Document Overview 1.1OverviewThis document is an instruction manual for the Renesas USB Devices USB basic firmware, a sample program for USBinterface control using the Renesas USB Devices.This firmware includes uITRON ver. and OS less ver.This document is intended to be used together with the devices data sheet. 1.2Related Documents[1] Universal Serial Bus Revision 2.0 Specification[http://www.usb.org/developers/docs/][2] Renesas USB Device Hardware ManualAvailable from the Renesas websiteRenesas Website [http://www.renesas.com/index.html]USB Device Page[http://www.renesas.com/prod/usb/] 1.3List of TermsTerms and abbreviations used in this document are listed below.USB: Universal Serial BusUSB-BASIC-F/W: USB basic firmware for Renesas USB Device (non-OS/uITRON)non-OS:USB basic firmware for OS less systemuITRON:USB basic firmware for uITRON systemHEW: High-performance Embedded WorkshopPCD: Peripheral control driver of USB-BASIC-F/WPDCD:Peripheral device class driver (device driver and USB class driver)HCD: Host control driver of USB-BASIC-F/WMGR: Peripheral device state manager of HCDHDCD:Host device class driver (device driver and USB class driver)HUBCD: Hub class sample driverAPL: Application programHTST:Host electrical testTask:Processing unitscheduler: Used to schedule functions, like a simplified OSScheduler macro: Used to call a scheduler function (non-OS)R01AN0512EJ0110 Rev.1.10 Page 2 of 126Jun 10, 2011 3. USB Basic Firmware2. Overview 2.1 Features of USB-BASIC-F/WThe main features of USB-BASIC-F/W are as follows. [Overall]Can control RX62N, RX630 and R8A66597 by common source code.Can use same source code in uITRON or non-OS.Can operate in either host function or peripheral function mode.Multiple device class drivers may be installed without the need to customize USB-BASIC-F/W. (Device class drivers can be registered up to the maximum number of devices that can be connected.) [Host function mode] When a no-response condition is detected during data transfer, the transfer is retried (n retries per transfer on the same pipe: specified by user in file r_usbc_cDefUsr.h). Common API for control transfer, bulk transfer and interrupt transfer is provided. API for devices connect/disconnect processing is provided. API for suspend/resume processing is provided. HUBCD sample program code is provided. Sample application for data transfer is added. (This application operates as Vendor class.) A single pipe can perform multiple exclusive data communication tasks in order to manage HDCD pipe information tables. [Peripheral function mode] Operation can be confirmed by using USBCommandVerifier.exe. (USBCV is available for download from http://www.usb.org/developers/developers/tools/.) API for control transfer is provided. Common API for bulk transfer and interrupt transfer is provided. API for devices connect/disconnect processing is provided. API for suspend/resume processing is provided. Sample application for data transfer is added. (This application operates as Vendor class.)The following functions must be provided by the customer to match the system under development. Overcurrent detection processing when connecting USB cables (host function mode). Descriptor analysis (host function mode). Device class driver 2.2 Development GoalsUSB-BASIC-F/W was developed with the following goals in mind. To simplify the development of USB communication programs by customers using Renesas USB Device. To provide source code examples for hardware control of USB. 2.3 FunctionsThe functions provided by USB-BASIC-F/W are as follows. In host function mode, enumeration as low-speed/full-speed/high-speed device (However, operating speed isdifferent by devices ability.) In peripheral function mode, enumeration as USB1.1/2.0/3.0 host Device connect/disconnect, suspend/resume, and USB bus reset processing Control transfer on pipe 0 Data transfer on pipes 1 to 9 (bulk or interrupt transfer: CPU access/DTC or DMA access) Transfer error determination and transfer retryR01AN0512EJ0110 Rev.1.10 Page 3 of 126Jun 10, 2011 4. USB Basic Firmware2.4 Task ConfigurationIn peripheral function mode, USB-BASIC-F/W comprises the peripheral driver, which controls H/W, and theapplication. In host function mode, USB-BASIC-F/W comprises the host driver, which controls H/W, the manager,which manages device states, the hub class driver, which controls devices connected to the down ports of the USB hub,and the application.Peripheral driver and host driver initiate hardware control according to messages from the various tasks or interrupthandler. They also notify the appropriate task when hardware control ends, of processing results, and of hardwarerequests.Manager manages the states of devices connected and performs enumeration. In addition, manager issues a message tohost driver or hub class driver when the application changes the device state. Hub class driver is sample program codefor managing the states of devices connected to the down ports of the USB hub and performing enumeration. uITRONScheduler Function non-OS Figure 2.1 Task Configuration of USB-BASIC-F/WR01AN0512EJ0110 Rev.1.10 Page 4 of 126Jun 10, 2011 5. USB Basic FirmwareTable 2.1 Task FunctionsNo. Module NameFunction1 USB interrupt handler USB interrupt handlervoid usb_cstd_UsbHandler(void) (USB packet transmit/receive end and special signal detection)2 Peripheral driver (PCD) Hardware control in peripheral function modevoid Peripheral transaction managementusb_pstd_PcdTask(USBC_VP_INT_t)3 Host driver (HCD) Hardware control in host function modevoid Host transaction managementusb_hstd_HcdTask(USBC_VP_INT_t)4 Host manager (MGR) Device state managementvoid Enumerationusb_hstd_MgrTask(USBC_VP_INT_t)HCD/HUBCD control message determination5 Hub class driver (HUBCD) HUB down port device state managementvoid usb_hhub_Task(USBC_VP_INT_t)HUB down port enumeration6 Device class driver (PDCD/HDCD)Provided by the customer as appropriate for the system.7 Device driver (HDD)Provided by the customer as appropriate for the system.8 Application (APL)Provided by the customer as appropriate for the system.2.5 Non-OS Scheduler FunctionA scheduler function manages requests generated by the tasks and hardware according to the relative priority of thetasks. When multiple requests are generated by tasks with the same priority, they are executed using a FIFOconfiguration. To assure commonality with non-OS and uITRON-compatible firmware, requests between tasks areimplemented by transmitting and receiving messages. In addition, call-back functions are used for responses to tasksindicating the end of a request, so the customer need only install appropriate class drivers for the system and there is noneed to modify the scheduler itself.2.6 Sequence OutlineLike USB-BASIC-F/W comprises usbc_cstd_MainTask, MainInit, MainLoop and usb_cstd_UsbHandler. In non-OS,the compositions add scheduler.When an interrupt occurs, the function mode that is selected by USB operational mode setting is checked andnotification is sent by means of a message to PCD/HCD. When the PCD or HCD task receives a message from the USBinterrupt handler, it determines the interrupt source and executes the appropriate processing. (For a sequence outline ofPCD/HCD task, see sections 8 and 10.)The PCD or HCD is selected by USB function setting. (For a USB function setting, see sections 5.)R01AN0512EJ0110 Rev.1.10 Page 5 of 126Jun 10, 2011 6. USB Basic Firmwareusbc_cstd_Main MainInit TaskInitialize USBMainInit()functionRegister driver Start Idle Taskusb_cstd_UsbHandlerInitialize scheduler function USBC_HOST_PPOperating mode?MainLoop()Set priorityUSBC_PERI_PPSet USBClear interrupt Clear interruptIdle Taskoperating mode sourcesource Send message Send messageReturnto PCD to HCDReturn USB_FUNCSEL_PP == USB_FUNCSEL_PP ==Task USBC_PERI_PPUSBC_HOST_PPNoUSBC_TRCV_MSG? MainLoop MainLoop Yes ApplicationApplicationProcessing NoNoTasks starting is Task processing Task processing Return controlledflag set? flag set?by scheduler Yes Yes SchedulerPCD task HCD task No PDCD taskMGR task Processing request? HUB task Yes Select request with SchedulerHDCD tasktop priority Return Set taskScheduler processing flagReturn ReturnFigure 2.2 Sequence Outline (non-OS)R01AN0512EJ0110 Rev.1.10Page 6 of 126Jun 10, 2011 7. USB Basic Firmwareusbc_cstd_MainMainInit TaskInitialize USB MainInit() function Start Idle task Start PCD taskStart MGR task Start HCD taskMainLoop() Register driverSet USB operating modeReturnTask usb_cstd_UsbHandlerUSBC_HOST_PP Operating mode? USBC_TRCV_MSG?USBC_PERI_PPClear interrupt Clear interrupt ProcessingsourcesourceSend message Send message to PCD to HCDReturn Figure 2.3 Sequence Outline (uITRON)R01AN0512EJ0110 Rev.1.10Page 7 of 126Jun 10, 2011 8. USB Basic Firmware2.7 Non-OS Task Operation ExampleAn example of the operation of a USB-BASIC-F/W task is shown below. Execution request received by MGR task in host function mode Note: Operation is the same in peripheral function mode.Execution request MainLoopHCD taskMGR task executionApplicationNoUSBC_TRCV_MSG?No Yes Flag set ? ProcessingYes HCD task Return MGR taskMGR task HUB taskNoUSBC_TRCV_MSG?HDCD taskYesProcessing SchedulerReturn returnHUB task NoUSBC_TRCV_MSG? YesProcessingReturnHDCD task NoUSBC_TRCV_MSG?Yes ProcessingReturnFigure 2.4 Task Operation Example (non-OS)R01AN0512EJ0110 Rev.1.10Page 8 of 126Jun 10, 2011 9. USB Basic Firmware2.8 uITRON Task-Related OperationOperation related to USB-BASIC-F/W tasks is shown below.Figure 2.5 Task-Related Operation (uITRON)R01AN0512EJ0110 Rev.1.10 Page 9 of 126Jun 10, 2011 10. USB Basic Firmware3. Using USB-BASIC-F/W 3.1OverviewUSB-BASIC-F/W is a USB driver that is adapted for the customers system by making changes to the non-OSscheduler macros or uITRON system control macros (r_usbc_cItron.h, r_usbc_cMacSystemcall.h), user information(r_usbc_cDefUsr.h, r_usb_cDefUsr.h), and non-OS settings (r_usbc_cKernelId.h, main.c, r_usb_PSMPL_apl.c,r_usb2_HSMPL_apl.c) to add HDCD and PDCD tasks. 3.2Changing USB-BASIC-F/WIn order to use USB-BASIC-F/W, it is necessary to make changes to the following program code and header files.1. It is necessary select the project and the build configuration in USB-BASIC-F/W. Select the project of the non-OS or uITRON from HEW project, and select the build configuration of theappropriate function (Host mode or Peripheral mode) for the system under development from HEW buildconfiguration in USB-BASIC-F/W and set the selected project in the active condition.2. Sample application source code for executing data transfer is provided. These should be changed as needed to match the system under development. Initialization of the control MCU, interrupt handlers, interrupt control, DTC or DMA control, etc. (See table3.1.) For the non-OS, adjustments to the duration of the specified wait time functions (usbc_cpu_DelayXms()function, usbc_cpu_Delay1us() function) For the non-OS, settings of functions that disable or enable USB-related interrupts in order to use the schedulerfunction (usb_cstd_IntDisable() function, usb_cstd_IntEnable() function)The USB interrupt disable function (usb_cstd_IntDisable() function) and USB interrupt enable function(usb_cstd_IntEnable() function) disable and enable, respectively. Make any necessary changes to the settings tomatch the MCU being used.3. For using R8A66597, it is necessary to make changes to the hardware settings in the usb_cstd_Pinconfig function in r_usb_cSignal.c to match the system under development. Make sure to refer to section 5 regarding the definitions for the settings. External bus operating voltage (set by user-defined information) FIFO access endian specification (common with CPU endian mode: set by user-defined information) Interrupt pin operation level DMA pin operation level BRDY interrupt operating mode SOF pin operating mode Low-power sleep operation specification (set by user-defined information)4. Some files must be customized by the customer. Refer to 5, User-Defined Information, and make appropriate changes to the user settings.5. Debug Information Output Function Make the appropriate settings in the file r_usbc_cMacPrint.h to enable or disable output of debug information.(Debug information can be output by creating a serial driver, or the like.)R01AN0512EJ0110 Rev.1.10Page 10 of 126Jun 10, 2011 11. USB Basic FirmwareTable 3.1List of FunctionsType FunctionDescriptionvoid usb_cstd_TargetInit(void) System initializationvoid usb_cstd_UsbIntHand(void) USB interrupt handlervoid usb_cstd_Dma0/1IntHand(void)DTC/DMA interrupt handlervoid usbc_cpu_UsbintInit(void) USB interrupt enablevoid usbc_cpu_DmaintInit(void) DTC/DMA interrupt enableuint16_t usb_cstd_D0fifo2BufStartDma(uint32_t SourceAddr)DTC/DMA read startuint16_t usb_cstd_Buf2D0fifoStartDma(uint32_t DistAddr)DTC/DMA write startvoid usb_cstd_StopDma(void)DTC/DMA stopvoid usb_cstd_IntEnable(void)USB interrupt enable for scheduler function of non-OSvoid usb_cstd_IntDisable(void) USB interrupt disable for scheduler function of non-OSvoid usbc_cpu_Delay1us(uint16_t time)1us delayvoid usbc_cpu_DelayXns(uint16_t time)1ms delay3.3Creating HDCD and PDCD TasksUSB-BASIC-F/W includes sample application source code for executing data transfer, it is necessary to create HDCDor PDCD tasks to match the system under development. It must also be configured to enable control of the schedulerfunction of the non-OS firmware.For the non-OS, HDCD or PDCD tasks should be configured to run USBC_TRCV_MSG at the start of processing, andin case of USBC_NG, to end the function.For the non-OS, the following processing routines must be added to HDCD to enable control by the scheduler function.Refer to the sample application function (usb2_hstd_MainTask() function).1. Class check processing (to check the class driver during enumeration)2. Initialization processing3. Enumeration waits processing (so that when multiple devices are attached, the other devices wait until enumeration of the current device ends) Note: RX62N does not require this processing.4. Task processing (created to match the system)For non-OS, the following processing routines must be added to PDCD to enable control by the scheduler function.Refer to the sample function (usb_pstd_MainTask() function).5. Task processing (created to match the system)R01AN0512EJ0110 Rev.1.10 Page 11 of 126Jun 10, 2011 12. USB Basic Firmware HDCD_TaskNo USBC_TRCV_MSG?YesR8A66597 onlyProcessing contentsUSB_MSGUSB_MSGUSB_MSGUSB_MSG_CLS__CLS_INIT_CLS_WAIT_CLS_TASKCHECKREQUEST1. Class check 2. Initialization 3. Enumeration4. Taskprocessing processingwait processing processing enumerationReturn PDCD_Task USBC_TRCV_MSG ?5. TaskprocessingReturn Figure 3.1 PDCD/HDCD Sequence for non-OS3.4 NoteThe customer will need to make a variety of customizations, for example designating classes, issuing vendor-specificrequests, making settings with regard to the communication speed or program capacity, or making individual settingsthat affect the user interface.Note: USB-BASIC-F/W is not guaranteed to provide USB communication operation. The customer should verifyoperation when utilizing it in a system and confirm the ability to connect to a variety of different types ofdevices.R01AN0512EJ0110 Rev.1.10Page 12 of 126Jun 10, 2011 13. USB Basic Firmware4. User-Defined Macros 4.1 OverviewUSB-BASIC-F/W includes macros for hardware register access (including FIFO access), so an executable filecustomized to the customers requirements can be generated by rewriting the macro header files. Make appropriatechanges to the macros for accessing the registers and FIFOs to match the system under development. The macroscomprise the six types listed below. Scheduler macros are defined in (r_usbc_cMacSystemcall.h), debug output macrosin (r_usbc_cMacPrint.h), and register access macros in (r_usb_cMacUsr.h).1. Non-OS scheduler macros2. uITRON system call macros3. Debug output macros4. Register and FIFO data register read/write macros5. Register bit set/clear/modify macros6. Status register bit clear macro7. Status register bit set macro4.1.1Non-OS Scheduler MacrosUSB-BASIC-F/W includes the file r_usbc_cScheduler.c, which contains functions for registering the scheduler macrosUSBC_SND_MSG, USBC_ISND_MSG, USBC_WAI_MSG, USBC_TRCV_MSG, USBC_PGET_BLK, andUSBC_REL_BLK. Functions are registered to scheduler macros in r_usbc_cMacSystemcall.h.[Function registration example] #define USBC_SND_MSG(ID, MESS)usbc_cstd_SndMsg((uint8_t)ID,(USBC_MSG_t*)MESS) #define USBC_ISND_MSG(ID, MESS) usbc_cstd_iSndMsg((uint8_t)ID,(USBC_MSG_t*)MESS) #define USBC_WAI_MSG(ID, MESS, TM)usbc_cstd_WaiMsg((uint8_t)ID, (USBC_MSG_t*)MESS, (uint16_t)TM) #define USBC_TRCV_MSG(ID, MESS, TM)usbc_cstd_RecMsg((uint8_t)ID,(USBC_MSG_t**)MESS,(USBC_TM_t)TM) #define USBC_PGET_BLK(ID, BLK)usbc_cstd_PgetBlk((uint8_t)ID,(USBC_MH_t*)BLK) #define USBC_REL_BLK(ID, BLK) usbc_cstd_RelBlk((uint8_t)ID,(USBC_MH_t)BLK)[USB_NG registration example] #define USBC_CRE_TSK(ID,INFO) USBC_NGR01AN0512EJ0110 Rev.1.10 Page 13 of 126Jun 10, 2011 14. USB Basic Firmware4.1.2 uITRON System Call MacroThe uITRON system call macro is shown below.Modify the code as necessary to match the ITRON version used.Note that ITRON macros are redefined for USB-BASIC-F/W in the file r_usbc_cMacSystemcall.h, so the ITRONmacros are defined by conditional compilation even when ITRON is not used. Therefore, this file should be also bemodified to match the ITRON version used.#defineUSBC_CRE_TSK(ID,INFO) cre_tsk( (USBC_ID_t)ID, (USBC_TSK_t*)INFO )#defineUSBC_DEL_TSK(ID)del_tsk( (USBC_ID_t)ID )#defineUSBC_STA_TSK(ID,CODE) sta_tsk( (USBC_ID_t)ID, (USBC_VI_t)CODE )#defineUSBC_ACT_TSK(ID)act_tsk( (USBC_ID_t)ID )#defineUSBC_TER_TSK(ID)ter_tsk( (USBC_ID_t)ID )#defineUSBC_EXT_TSK()ext_tsk( )#defineUSBC_REF_TST(ID, STS) ref_tst( (USBC_ID_t)ID, (USBC_RTST_t*)STS )#defineUSBC_DLY_TSK(TIME)dly_tsk( (USBC_RT_t)TIME )#defineUSBC_CRE_MBX(ID, INFO) cre_mbx( (USBC_ID_t)ID, (USBC_MBX_t*)INFO )#defineUSBC_DEL_MBX(ID) del_mbx( (USBC_ID_t)ID )#defineUSBC_SND_MSG(ID, MESS) snd_mbx( (USBC_ID_t)ID, (USBC_MSG_t*)MESS )#defineUSBC_ISND_MSG(ID, MESS)isnd_mbx( (USBC_ID_t)ID, (USBC_MSG_t*)MESS )#defineUSBC_RCV_MSG(ID, MESS) rcv_mbx( (USBC_ID_t)ID, (USBC_MSG_t**)MESS )#defineUSBC_PRCV_MSG(ID, MESS)prcv_mbx( (USBC_ID_t)ID, (USBC_MSG_t**)MESS )#defineUSBC_TRCV_MSG(ID, MESS, TM)trcv_mbx( (USBC_ID_t)ID, (USBC_MSG_t**)MESS,(USBC_TM_t)TM )#defineUSBC_CRE_MPL(ID, INFO)cre_mpf( (USBC_ID_t)ID, (USBC_MPL_t*)INFO )#defineUSBC_DEL_MPL(ID)del_mpf( (USBC_ID_t)ID )#defineUSBC_PGET_BLK(ID, BLK)pget_mpf( (USBC_ID_t)ID, (USBC_MH_t*)BLK )#defineUSBC_IPGET_BLK(ID, BLK) ipget_mpf( (USBC_ID_t)ID, (USBC_MH_t*)BLK )#defineUSBC_REL_BLK(ID, BLK) rel_mpf( (USBC_ID_t)ID, (USBC_MH_t)BLK )#defineUSBC_CRE_SEM(ID, INFO)cre_sem( (USBC_ID_t)ID, (USBC_SEM_t*)INFO )#defineUSBC_WAI_SEM(ID)wai_sem( (USBC_ID_t)ID )#defineUSBC_POL_SEM(ID)pol_sem( (USBC_ID_t)ID )#defineUSBC_SIG_SEM(ID)sig_sem( (USBC_ID_t)ID )#defineUSBC_CRE_ALM(ID, INFO)cre_alm( (USBC_ID_t)ID, (USBC_ALM_t*)INFO )#defineUSBC_STA_ALM(ID, TIME)sta_alm( (USBC_ID_t)ID, (USBC_RT_t)TIME )#defineUSBC_STP_ALM(ID)stp_alm( (USBC_ID_t)ID )#defineUSBC_DEL_ALM(ID)del_alm( (USBC_ID_t)ID )R01AN0512EJ0110 Rev.1.10Page 14 of 126Jun 10, 2011 15. USB Basic Firmware4.1.3 Debug Information Output MacrosThis type of macro outputs debug information to a UART or display device. A serial driver or display device driver isrequired.#define USBC_SPRINTF0(FORM)fprintf(stderr,FORM)#define USBC_SPRINTF1(FORM,x1) fprintf(stderr,FORM,x1)#define USBC_SPRINTF2(FORM,x1,x2)fprintf(stderr,FORM,x1,x2)#define USBC_SPRINTF3(FORM,x1,x2,x3) fprintf(stderr,FORM,x1,x2,x3)#define USBC_SPRINTF4(FORM,x1,x2,x3,x4)fprintf(stderr,FORM,x1,x2,x3,x4)#define USBC_SPRINTF5(FORM,x1,x2,x3,x4,x5) fprintf(stderr,FORM,x1,x2,x3,x4,x5)#define USBC_SPRINTF6(FORM,x1,x2,x3,x4,x5,x6) fprintf(stderr,FORM,x1,x2,x3,x4,x5,x6)#define USBC_SPRINTF7(FORM,x1,x2,x3,x4,x5,x6,x7) fprintf(stderr,FORM,x1,x2,x3,x4,x5,x6,x7)#define USBC_SPRINTF8(FORM,x1,x2,x3,x4,x5,x6,x7,x8) fprintf(stderr,FORM,x1,x2,x3,x4,x5,x6,x7,x8)#define USBC_PRINTF0(FORM) printf(FORM)#define USBC_PRINTF1(FORM,x1)printf(FORM,x1)#define USBC_PRINTF2(FORM,x1,x2) printf(FORM,x1,x2)#define USBC_PRINTF3(FORM,x1,x2,x3)printf(FORM,x1,x2,x3)#define USBC_PRINTF4(FORM,x1,x2,x3,x4) printf(FORM,x1,x2,x3,x4)#define USBC_PRINTF5(FORM,x1,x2,x3,x4,x5)printf(FORM,x1,x2,x3,x4,x5)#define USBC_PRINTF6(FORM,x1,x2,x3,x4,x5,x6) printf(FORM,x1,x2,x3,x4,x5,x6)#define USBC_PRINTF7(FORM,x1,x2,x3,x4,x5,x6,x7) printf(FORM,x1,x2,x3,x4,x5,x6,x7)#define USBC_PRINTF8(FORM,x1,x2,x3,x4,x5,x6,x7,x8) printf(FORM,x1,x2,x3,x4,x5,x6,x7,x8)If no debug information will be output, the following lines should be commented out as shown.//#define USBC_DEBUGSIO_PP/* enable serial out (printf) *///#define USBC_DEBUGLCD_PP/* enable display out (lprintf) */4.1.4 Register and FIFO Data Register Read/Write MacrosThis type of macro performs read or write access to registers or FIFO port registers.#define USB_RD( r, v ) do { (( v ) = ( USB_IP.r.WORD )); } while(0)#define USB_WR( r, v ) do { (( USB_IP.r.WORD ) = ( v )); } while(0)#define USB_RDW( r, v) do{ (( v ) = ( USB_IP.r )); } while(0)#define USB_WRW( r, v) do{ (( USB_IP.r ) = ( v )); } while(0)#define USB_RD_FF( r,v ) do{ (( v ) = ( USB_IP.r )); } while(0)#define USB_WR_FF( r,v ) do{ (( USB_IP.r ) = ( v )); } while(0)R01AN0512EJ0110 Rev.1.10Page 15 of 126Jun 10, 2011 16. USB Basic Firmware4.1.5Register Bit Set/Clear/Modify MacrosThis type of macro sets, clears, or modifies the value of bits in registers.Each macro is written to accommodate the RMW (Read Modify Write) instruction, and it uses a register and FIFO dataregister read/write macro of the type mentioned above.Notes: 1. These macros do not need to be modified by the customer. 2. Do not use the bit clear macro to clear bits in status registers./* set bit(s) of USB register *//* r : USB register *//* v : value to set */#define USB_SET_PAT( r, v ) do { (( USB_IP.r.WORD ) |= ( v )); } while(0)/* reset bit(s) of USB register *//* r : USB register *//* m : bit pattern to reset */#define USB_CLR_PAT( r, m ) do { (( USB_IP.r.WORD ) &= ( (uint16_t)(~(m)) )); }while(0)/* modify bit(s) of USB register*//* r : USB register *//* v : value to set *//* m : bit pattern to modify*/#define USB_MDF_PAT( r, v, m )do { uint16_t mtmp;USB_RD( r, mtmp );mtmp &= ( (uint16_t)(~(m)) ); mtmp |= ( (uint16_t)(v & m) );USB_WR( r, mtmp ); } while(0)4.1.6Status Register Bit Clear MacroThis macro clears bits in status registers.This macro is written to accommodate the RMW (Read Modify Write) instruction, and it uses a register and FIFO dataregister read/write macro of the type mentioned above. This macro is designed to avoid deleting status bits that havechanged during the execution of the RMW instruction.Notes: 1. This macro does not need to be modified by the customer. 2. This macro should only be used for status registers where writing 1 has no effect./* reset bit(s) of USB status *//* r : USB register *//* m : bit pattern to reset */#define USB_CLR_STS( r, m ) USB_WR( r, ( (uint16_t)(~(m)) ) )R01AN0512EJ0110 Rev.1.10 Page 16 of 126Jun 10, 2011 17. USB Basic Firmware5. User-Defined Information 5.1OverviewAn executable file customized to the customers requirements can be generated by rewriting the user system definitioninformation file (r_usbc_cDefUsr.h) and user-defined information file (r_usb_cDefUsr.h) included in USB-BASIC-F/W.The items listed below should be changed to match the system under development. 5.2User System Definition Information File (r_usbc_cDefUsr.h)1. Target device designation2. Installed USB-IP type designation3. 597IP function designation (number of Pipe)4. 597IP function designation (number of Device Address)5. 597IP function designation (buffer size)6. Transfer speed designation7. Bus width designation8. USB port designation9. External bus operating voltage designation10. Oscillating frequency of connected resonator11.Operating environment designation12.Create Systemcall designation (uITRON)13. CPU byte endian designation14. DTC/DMA designation15. Low Power Mode designation16. PID = NAK setting at transfer end enable designation (peripheral function mode)17. Software retry count at pipe no-response (host function mode)18. Control read data buffer size (host function mode)19. Device address initial value (host function mode)20. Hub down port count (host function mode)5.2.1 Target Device DesignationThe target device may be specified as either of the following two options.1) USBC_ASSP_PP: R8A665972) USBC_RX600_PP: RX62N or RX630Example: RX62N or RX630#define USBC_TARGET_CHIP_PPUSBC_RX600_PPThis setting is selected by the macro definition of HEW project in USB-BASIC-F/W.The macro definition is selected from option category in Standard toolchain of compiler tab.5.2.2 Installed USB-IP Type DesignationThe USB-IP type may be specified as either of the following three options.1) USBC_592IP_PP: Installed 592IP2) USBC_596IP_PP: Installed 596IP3) USBC_597IP_PP: Installed 597IPExample: Installed 597IP#define USBC_IPSEL_PP USBC_597IP_PPR01AN0512EJ0110 Rev.1.10 Page 17 of 126Jun 10, 2011 18. USB Basic Firmware5.2.3 597IP Function Designation (Number of Pipe)The number of pipe may be specified as either of the following two options.1) USBC_IP_PIPE_9_PP: 1-9 of PIPE use2) USBC_IP_PIPE_7_PP: 1-7 of PIPE useExample: 1-9 of PIPE use#define USBC_IP_PIPE_PPUSBC_IP_PIPE_9_PP5.2.4 597IP Function Designation (Number of Device Address)The number of device address may be specified as either of the following two options.1) USBC_IP_DEVADD_A_PP: 10 device address use2) USBC_IP_DEVADD_5_PP: 5 device address useExample: 5 device address use#define USBC_IP_DEVADD_PPUSBC_IP_DEVADD_5_PP5.2.5 597IP Function Designation (Buffer Size)The buffer type may be specified as either of the following two options.1) USBC_PIPEBUFF_FIX_PP: PIPEBUF is fixation2) USBC_PIPEBUFF_CHANGE_PP: PIPEBUF is changeableExample: PIPEBUF is fixation#define USBC_PIPEBUF_MODE_PP USBC_PIPEBUF_CHANGE_PP5.2.6 Transfer Speed DesignationThe target speed may be specified as either of the following two options.1) USBC_HS_PP: High-Speed support2) USBC_FS_PP: Full-Speed supportExample: Full-Speed support#define USBC_SPEEDSEL_PP USBC_FS_PP5.2.7 Bus Width DesignationThe bus width may be specified as either of the following two options.1) USBC_BUSSIZE_16_PP: 16 bits2) USBC_BUSSIZE_32_PP: 32 bitsExample: 16 bits#define USBC_BUSSIZE_PPUSBC_BUSSIZE_16_PPR01AN0512EJ0110 Rev.1.10 Page 18 of 126Jun 10, 2011 19. USB Basic Firmware5.2.8 USB Port DesignationThe USB port may be specified as either of the following two options.1) USBC_1PORT_PP: 1 USB Port use2) USBC_2PORT_PP: 2 USB Ports useExample: 1 USB Port use#define USBC_PORTSEL_PP USBC_1PORT_PP5.2.9 Operating Environment DesignationThe operating environment may be specified as either of the following two options.1) USBC_FW_OS_PP: OS support2) USBC_FW_NONOS_PP: No OS supportExample: No OS support#define USBC_FW_PP USBC_FW_NONOS_PPThis setting is selected by the macro definition of HEW project in USB-BASIC-F/W.The macro definition is selected from option category in Standard toolchain of compiler tab.5.2.10External Bus Operating Voltage DesignationThe external bus operating voltage may be specified as either of the following two options.1) USBC_VIF1: 1.8 V applied to external bus pins.2) USBC_VIF3: 3.3 V external bus pins.Example: 3.3 V#define USB_LDRVSELUSBC_VIF3For the RX62N and RX630, use the USBC_VIF3 setting.5.2.11Oscillating Frequency of Connected ResonatorOscillating frequency of connected resonator may be specified as one of the following three options.1) USBC_XTAL48: 48 MHz resonator connected.2) USBC_XTAL24: 24 MHz resonator connected.3) USBC_XTAL12: 12 MHz resonator connected.Example: 24 MHz resonator#define USBC_XINSEL USBC_XTAL24For the RX62N and RX630. Use the USBC_XTAL24 setting.R01AN0512EJ0110 Rev.1.10 Page 19 of 126Jun 10, 2011 20. USB Basic Firmware5.2.12Create System call Designation (uITRON)It may be specified as either of the following two options that the Task Creation System call is supported or notsupported.1) USBC_OS_CRE_USE_PP: Task Creation System call support2) USBC_OS_CRE_NOTUSE_PP: No Task Creation System call supportExample: No Task Creation System call support#define USBC_OS_CRE_MODE_PP USBC_OS_CRE_NOTUSE_PP5.2.13CPU Byte Endian DesignationThe CPU byte endian may be specified as either of the following two options.This setting is for CPU access to FIFO.1) USBC_BYTE_LITTLE_PP: Little Endian (Definition from upper byte)2) USBC_BYTE_BIG_PP: Big Endian (Definition from under byte)Example: Little endian#define USBC_CPUBYTE_PPUSBC_BYTE_LITTLE_PP5.2.14DTC/DMA DesignationThe DTC/DMA may be specified as either of the following two options.1) USBC_TRANS_DMA_PP: DMA2) USBC_TRANS_DTC_PP: DTCExample: DTC#define USBC_TRANS_MODE_PP USBC_TRANS_DTC_PPThe RX62N and RX630 support only DTC. Use the USBC_TRANS_DTC_PP setting.5.2.15Low Power Mode DesignationThe low power mode may be specified as either of the following two options.1) USBC_LPWR_NOT_USE_PP: Not low power mode2) USBC_ LPWR_USE_PP: Low power modeExample: Not low power mode#define USBC_LPWR_MODE_PPUSBC_LPWR_NOT_USE_PPFor the R8A66597, use the USBC_LPWR_NOT_USE_PP setting.5.2.16PID = NAK Setting at Transfer End Enable Designation (Peripheral Function Mode)It may be specified as either of the following two options that the PID = NAK set or not set at transfer end enable.1) USBC_NONPERIODIC_PP: PID = NAK2) USBC_PERIODIC_PP: No PID = NAKExample: PID = NAK#define USBC_PERIODIC_MODE_PP USBC_PERIODIC_PPR01AN0512EJ0110 Rev.1.10Page 20 of 126Jun 10, 2011 21. USB Basic Firmware5.2.17 Software Retry Count at Pipe No-Response (Host Function Mode)It is necessary to specify the number of software retries when a no-response condition occurs during a transfer.Example: Up to one retry by USB-BASIC-F/W at pipe no-response#define USBC_PIPEERR 1u5.2.18 Control Read Data Buffer Size (Host Function Mode)It is necessary to specify the data buffer size when a control read transfer is received.Example: 20-byte device descriptor, 256-byte configuration descriptor#define USBC_DEVICESIZE 20u#define USBC_CONFIGSIZE 256u5.2.19 Device Address (Host Function Mode)It is necessary to specify the device address of the device connected to PORT0.Example: Device address starts from 2.#define USBC_DEVICEADDR 2uFor the RX62N, addresses in the range 1 to 5 may be specified.For the R8A66597, addresses in the range 1 to 10 may be specified.5.2.20 Hub Down Port Count (Host Function Mode)It is necessary to specify the number of hub down ports that can be connected.Example: Connected hub has 4 down ports.#define USBC_HUBDOWNPORT4uR01AN0512EJ0110 Rev.1.10Page 21 of 126Jun 10, 2011 22. USB Basic Firmware5.2.21User System Definition Information for Each DevicesThe user system definition information for each device is shown below.Table 5.1For the RX62N, the user system definition information (r_usbc_cDefUsr.h)SectionFlag Set ObjectSet ValueRemarksNumber *(o: default setting)5.2.1-USBC_TARGET_CHIP_PP o USBC_RX600_PPThis setting is selected by the macro definition of HEW project.5.2.2-USBC_IPSEL_PP o USBC_597IP_PP5.2.3-USBC_IP_PIPE_PP o USBC_IP_PIPE_9_PP5.2.4-USBC_IP_DEVADD_PP o USBC_IP_DEVADD_5_PP5.2.5-USBC_PIPEBUF_MODE_PPo USBC_PIPEBUF_FIX_PP5.2.6-USBC_SPEEDSEL_PPo USBC_FS_PP5.2.7-USBC_BUSSIZE_PP o USBC_BUSSIZE_16_PP5.2.8-USBC_PORTSEL_PP o USBC_1PORT_PP5.2.9-USBC_LDRVSELo USBC_VIF3(NOT_USED)5.2.10 -USBC_XINSEL o USBC_XTAL245.2.11 OUSBC_FW_PPUSBC_FW_NONOS_PP This setting isUSBC_FW_OS_PPselected by the macro definition of HEW project.5.2.12 OUSBC_OS_CRE_MODE_PP o USBC_OS_CRE_NOTUSE_PPIfUSBC_OS_CRE_USE_PP USB_C_FW_NO NOS_PP setting in 5,2,11, use the default setting. If RI600 is used, use the default setting.5.2.13 OUSBC_CPUBYTE_PP o USBC_BYTE_LITTLE_PPUSBC_BYTE_BIG_PP5.2.14- USBC_TRANS_MODE_PPo USBC_TRANS_DTC_PP5.2.15O USBC_LPWR_MODE_PP o USBC_LPWR_NOT_USE_PPUSBC_LPWR_USE_PP5.2.16O USBC_PERIODIC_MODE_P o USBC_NONPERIODIC_PPP USBC_PERIODIC_PP5.2.17O USBC_PIPEERRORo 1u5.2.18O USBC_DEVICESIZE o 20uO USBC_CONFIGSIZE o 256u5.2.19O USBC_DEVICEADDR o 1u5.2.20O USBC_HUBDOWNPORTo 4u* : Flag - : Not selected(Use the default setting.), O: Select from Set Value.R01AN0512EJ0110 Rev.1.10Page 22 of 126Jun 10, 2011 23. USB Basic FirmwareTable 5.2For the RX630, the user system definition information (r_usbc_cDefUsr.h)SectionFlag Set ObjectSet ValueRemarksNumber *(o: default setting)5.2.1-USBC_TARGET_CHIP_PP o USBC_RX600_PPThis setting is selected by the macro definition of HEW project.5.2.2-USBC_IPSEL_PP o USBC_597IP_PP5.2.3-USBC_IP_PIPE_PP o USBC_IP_PIPE_9_PP5.2.4-USBC_IP_DEVADD_PP o USBC_IP_DEVADD_5_PP5.2.5-USBC_PIPEBUF_MODE_PPo USBC_PIPEBUF_FIX_PP5.2.6-USBC_SPEEDSEL_PPo USBC_FS_PP5.2.7-USBC_BUSSIZE_PP o USBC_BUSSIZE_16_PP5.2.8-USBC_PORTSEL_PP o USBC_1PORT_PP5.2.9-USBC_LDRVSELo USBC_VIF3(NOT_USED)5.2.10 -USBC_XINSEL o USBC_XTAL245.2.11 OUSBC_FW_PPUSBC_FW_NONOS_PP This setting isUSBC_FW_OS_PPselected by the macro definition of HEW project.5.2.12 OUSBC_OS_CRE_MODE_PP o USBC_OS_CRE_NOTUSE_PPIfUSBC_OS_CRE_USE_PP USB_C_FW_NO NOS_PP setting in 5,2,11, use the default setting. If RI600 is used, use the default setting.5.2.13 OUSBC_CPUBYTE_PP o USBC_BYTE_LITTLE_PPUSBC_BYTE_BIG_PP5.2.14- USBC_TRANS_MODE_PPo USBC_TRANS_DTC_PP5.2.15O USBC_LPWR_MODE_PP o USBC_LPWR_NOT_USE_PPUSBC_LPWR_USE_PP5.2.16O USBC_PERIODIC_MODE_P o USBC_NONPERIODIC_PPP USBC_PERIODIC_PP5.2.17- USBC_PIPEERRORo 1u5.2.18- USBC_DEVICESIZE o 20u- USBC_CONFIGSIZE o 256u5.2.19- USBC_DEVICEADDR o 1u5.2.20- USBC_HUBDOWNPORTo 4u* : Flag - : Not selected(Use the default setting.), O: Select from Set Value.R01AN0512EJ0110 Rev.1.10Page 23 of 126Jun 10, 2011 24. USB Basic FirmwareTable 5.3For the R8A66597, the user system definition information (r_usbc_cDefUsr.h)Section FlagSet ObjectSet Value RemarksNumber* (o: default setting)5.2.1 - USBC_TARGET_CHIP_PP o USBC_ASSP_PPThis setting isselected by themacro definitionof HEW project.5.2.2 - USBC_IPSEL_PP o USBC_597IP_PP5.2.3 - USBC_IP_PIPE_PP o USBC_IP_PIPE_9_PP5.2.4 - USBC_IP_DEVADD_PP o USBC_IP_DEVADD_A_PP5.2.5 - USBC_PIPEBUF_MODE_PPo USBC_PIPEBUF_CHANGE_PP5.2.6 - USBC_SPEEDSEL_PPo USBC_HS_PP5.2.7 - USBC_BUSSIZE_PP o USBC_BUSSIZE_16_PP5.2.8 O USBC_PORTSEL_PP o USBC_2PORT_PPUSBC_1PORT_PP5.2.9 O USBC_LDRVSELUSBC_VIF1(NOT_USED)o USBC_VIF35.2.10O USBC_XINSEL USBC_XTAL12o USBC_XTAL24USBC_XTAL485.2.11- USBC_FW_PPo USBC_FW_NONOS_PPThis setting isselected by themacro definitionof HEW project.5.2.12- USBC_OS_CRE_MODE_PP o USBC_OS_CRE_NOTUSE_PP5.2.13O USBC_CPUBYTE_PP o USBC_BYTE_LITTLE_PPUSBC_BYTE_BIG_PP5.2.14- USBC_TRANS_MODE_PPo USBC_TRANS_DTC_PP5.2.15- USBC_LPWR_MODE_PP o USBC_LPWR_NOT_USE_PP5.2.16O USBC_PERIODIC_MODE_P o USBC_NONPERIODIC_PPP USBC_PERIODIC_PP5.2.17O USBC_PIPEERRORo 1u5.2.18O USBC_DEVICESIZE o 20uO USBC_CONFIGSIZE o 256u5.2.19O USBC_DEVICEADDR o 1u5.2.20O USBC_HUBDOWNPORTo 4u* : Flag - : Not selected(Use the default setting.), O: Select from Set Value.R01AN0512EJ0110 Rev.1.10Page 24 of 126Jun 10, 2011 25. USB Basic Firmware 5.3 User-Defined Information File (r_usb_cDefUsr.h)1. USB Function designation2. Power Consumption Control Function designation3. Auto Clock Mode designation4. Sleep Mode designation5. Hardware address designation6. Hi-speed operation enable/disable5.3.1USB Function DesignationThe hardware function may be specified as one of the following three options.1) USBC_HOST_PP: Used as USB host.2) USBC_PERI_PP: Used as USB peripheral.3) USBC_HOST_PERI_PP: Used as both USB host and USB peripheral.Example: USB peripheral #define USBC_FUNCSEL_PP USBC_PERI_PP5.3.2Power Consumption Control Function DesignationIt is necessary to specify the power consumption control function.Reference: The power consumption control function may be specified as one of the following three options.1) USBC_NOT_STOP_PP: The power consumption control is not used (clock does not stop).2) USBC_XCKE_USE_PP: The power consumption control function is used with the clock in the stopped state.3) USBC_PCUT_USE_PP: The low-power sleep state is used. (This setting is for M66592 and M66596.)Example: The power consumption control is not used #define USBC_OSCSEL_PP USBC_CLK_NOT_STOP_PPThis function is not used by the RX62N and RX630. Use the USBC_CLK_NOT_STOP_PP setting.For the R8A66597, use the USBC_NOT_STOP_PP or the USBC_XCKE_USE_PP setting.5.3.3Auto Clock Mode DesignationThe hardware function may be specified as one of the following two options.1) USBC_ATCKM_NOT_USE_PP: No auto clock mode2) USBC_ATCKM_USE_PP: Auto clock mode (This setting is for M66592 and M66596.)Example: No auto clock mode #define USBC_ATCKMSEL_PPUSBC_ATCKM_NOT_USE_PPThis function is not used by the RX62N, RX630 and R8A66597. Use the USBC_ATCKM_NOT_USE_PP setting.R01AN0512EJ0110 Rev.1.10Page 25 of 126Jun 10, 2011 26. USB Basic Firmware5.3.4Sleep Mode DesignationThe sleep mode may be specified as one of the following two options.1) USBC_LPSM_DISABLE_PP: No sleep mode2) USBC_LPSM_ENABLE_PP: Sleep mode (The setting is for R8A66597.)Example: No sleep mode#define USBC_LPWRSEL_PP USBC_LPSM_DISABLE_PPThis function is not used by the RX62N and RX630. Use the USBC_LPSM_DISABLE_PP setting.5.3.5Hardware Address DesignationIt is necessary to specify the standard address for accessing the hardware.For each register, the address is specified as an offset from the designated standard address.Example: 0x05000000#define USBC_BASE (uint32_t)(0x05000000)This setting is not used by the RX62N and RX630.(#define USB0 specifies the address.)5.3.6Hi-Speed Operation Enable/DisableEither of the following two options may be selected for hi-speed operation.1) USBC_HS_DISABLE: Full- or low-speed operation will be selected automatically according to the connected device.2) USBC_HS_ENABLE: Hi-, full-, or low-speed operation will be selected automatically according to the connected device.Example: Disabled#define USBC_HSESEL USBC_HS_DISABLEFor the RX62N and RX630, select USBC_HS_DISABLE.R01AN0512EJ0110 Rev.1.10Page 26 of 126Jun 10, 2011 27. USB Basic Firmware5.3.7 User System Definition Information for Each DeviceThe user system definition information for each device is shown below.Table 5.4For the RX62N, the user system definition information (r_usb_cDefUsr.h)SectionFlagSet Object Set ValueRemarksNumber *(o: default setting)5.3.1O USBC_FUNCSEL_PPUSBC_HOST_PP This setting isUSBC_PERI_PP selected by theUSBC_HOST_PERI_PPmacro definition of HEW project.5.3.2 - USBC_OSCSEL_PPo USBC_CLK_NOT_STOP_PP5.3.3 - USBC_ATCKMSEL_PPo USBC_ATCKM_NOT_USE_PP5.3.4 - USBC_LPWRSEL_PP o USBC_LPWR_DISABLE_PP5.3.5 - USB_BASEo 0x000A00005.3.6 - USB_HSESELo USBC_HS_DISABLE* : Flag - : Not selected(Use the default setting.), O: Select from Set Value.Table 5.5For the RX630, the user system definition information (r_usb_cDefUsr.h)SectionFlagSet Object Set ValueRemarksNumber *(o: default setting)5.3.1- USBC_FUNCSEL_PPUSBC_PERI_PP This setting is selected by the macro definition of HEW project.5.3.2 - USBC_OSCSEL_PPo USBC_CLK_NOT_STOP_PP5.3.3 - USBC_ATCKMSEL_PPo USBC_ATCKM_NOT_USE_PP5.3.4 - USBC_LPWRSEL_PP o USBC_LPWR_DISABLE_PP5.3.5 - USB_BASEo 0x000A00005.3.6 - USB_HSESELo USBC_HS_DISABLE* : Flag - : Not selected(Use the default setting.), O: Select from Set Value.Table 5.6For the R8A66597, the user system definition information (r_usb_cDefUsr.h)SectionFlagSet Object Set ValueRemarksNumber *(o: default setting)5.3.1O USBC_FUNCSEL_PPUSBC_HOST_PP This setting isUSBC_PERI_PP selected by the macro definition of HEW project.5.3.2O USBC_OSCSEL_PP o USBC_CLK_NOT_STOP_PPUSBC_CLK_XCKE_USE_PP5.3.3 - USBC_ATCKMSEL_PPo USBC_ATCKM_NOT_USE_PP5.3.4 O USBC_LPWRSEL_PP o USBC_LPWR_DISABLE_PPUSBC_LPWR_ENABLE_PP5.3.5 O USB_BASEo 0x050000005.3.6 O USB_HSESELo USBC_HS_ENABLEUSBC_HS_DISABLE* : Flag - : Not selected(Use the default setting.), O: Select from Set Value.R01AN0512EJ0110 Rev.1.10 Page 27 of 126Jun 10, 2011 28. USB Basic Firmware6. Workspace 6.1OverviewThe workspace of USB-BASIC-F/W is described below.Workspace of USB-BASIC-F/W includes two projects.1. NonOS_StdFw: non-OS2. Itron_StdFw: uITRON (R8A66597 is not supported)And, USB-BASIC-F/W includes build configurations.[For the RX62N]1. PORT0_P: PORT0 is Peripheral mode2. PORT1_H: PORT1 is Host mode3. PORT0_P_PORT1_H:USB0 is Peripheral mode and USB1 is Host mode[For the RX630]4. RX630_PORT0_P: PORT0 is Peripheral mode[For the R8A66597]5. ASSP_PERI: PORT0 is Peripheral mode6. ASSP_HOST: PORT1 is Host modeEach configuration selects source files as compiled.In peripheral function mode, USB-BASIC-F/W comprises two tasks, PCD and sample application, and a scheduler. Inhost function mode, it comprises four tasks, HCD, MGR, HUB, and sample application, and a scheduler. Sampleapplication is run as tasks.R01AN0512EJ0110 Rev.1.10Page 28 of 126Jun 10, 2011 29. USB Basic Firmware6.2Structure of Files and folders6.2.1 Folder StructureThe folder structure in which the files are provided in USB-BASIC-F/W is shown below. These provided files in USB-BASIC-F/W include sample application and sample code of resource for hardware.< HEW workspace: USBSTDFW >(USB-BASIC-F/W)+ USBSTDFWFor USB0| + class| | + hubdSample hub driver| | + smplUSB standard request sample| + include Common header file| + USB20| + HCD Host control driver| + PCD Peripheral control driver| + LIB Common library+ USB2STDFW For USB1 (RX630 and R8A66597 are not used.) | Structure is same to USBSTDFW+ USBCSTDFW For USB0 and USB1 |+ include Common header file(The following is sample code)+ RI600_4 For uITRON |+ config_Pstd For PORT0_P and RX630_PORT0_P |+ config_Hstd For PORT1_H |+ config_Cstd For PORT0_P_PORT1_H+ HwResourceForUSBResource for hardware |+ RX62N For RX62N |+ RX630 For RX630 + SmplMain+ APL Sample application+ Project Each projectsR01AN0512EJ0110 Rev.1.10Page 29 of 126Jun 10, 2011 30. USB Basic Firmware6.2.2 List of FilesThe files provided in USB-BASIC-F/W are listed below. The files of USB2STDFW folder are left out.Table 6.1List of FilesFolder File NameDescription Project(O: Selected )1) 2) 3) 4) 5) 6)* * * * * *HCDr_usb_hControlRW.cControl read/write processingO OOHCDr_usb_hDriver.c HCD task O OOHCDr_usb_hDriverAPI.cHCD/MGR API functionsO OOHCDr_usb_hIntFIFO.cINTR, INTN, BEMP interrupt O OO processingHCDr_usb_hManager.cMGR task OOOHCDr_usb_hSignal.c USB signal control, oscillation controlOOO processingHCDr_usb_hStdFunction. USB function extension library OOO c functionsHCDr_usb_hLibUSBIP.c USB library functionsOOOPCDr_usb_pControlRW.c Control read/write processing OOO OPCDr_usb_pDriver.c PCD task OOO OPCDr_usb_pDriverAPI.cPCD API functionsOOO OPCDr_usb_pIntFIFO.cINTR, INTN, BEMP interrupt OOO O processingPCDr_usb_pSignal.c USB signal control, oscillation controlOOO O processingPCDr_usb_pStdRequest.c USB standard request responses OOO OPCDr_usb_pStdFunction. USB function extension library OOO O c functionsPCDr_usb_pLibUSBIP.c USB library functionsOOO OLIBr_usb_cDataIO.c Data read/write, FIFO access O OOO O O processingLIBr_usb_cIntFIFO.cINTR, INTN, BEMP interrupt O OOO O O processingLIBr_usb_cIntHandler.c USB interrupt handlerO OOO O OLIBr_usb_cLibUSBIP.c USB library functionsO OOO O OLIBr_usb_cSignal.c USB signal control, oscillation controlO OOO O O processingLIBr_usb_cStdFunction. USB function extension library O OOO O O c functions (host/peripheral mixed)USBCSTDFWr_usbc_cScheduler.c Scheduler controlO OOO O Oincluder_usbc_cDefUSBIP.h USB driver definitionsO OOO O Oincluder_usbc_cItron.h System header file O OOO O Oincluder_usbc_cKernelID.hID definitions (Task ID, etc.) O OOO O Oincluder_usbc_cMacSystem Macro definitions (scheduler macros) O OOO O O call.hincluder_usbc_cMacPrint.hMacro definitionsO OOO O O (macros for displaying debug information)includer_usbc_cTypedef.h Variable type definitionsO OOO O Oincluder_usbc_cDef592IP.hRegister definitions for 592IP (not used by RX62N)R01AN0512EJ0110 Rev.1.10Page 30 of 126Jun 10, 2011 31. USB Basic Firmware Project (O: Selected )include r_usbc_cDef596IP.hRegister definitions for 596IP(not used by RX62N)include r_usbc_cDef597IP.hRegister definitions for 597IP O O(not used by RX62N)include r_usbc_cUsbDefBitDUSB register definitions for RX600 O O O Oefine.h seriesinclude r_usb_cDefUsr.h User setting (hardware operation O O O O O Odesignation) definitionsinclude r_usbc_cDefUsrPp.hUSB driver definitions O O O O O Oinclude r_usb_cExtern.h USB-BASIC-F/W external reference O O O O O Odefinitionsinclude r_usb_cMacUsr.h Macro definitions (register access O O O O O Omacros)include r_usb_cRevision.h Common library revision designations O O O O O Ohubdr_usb_hHubsys.c HUBCD functions (non-OS) O O Ohubdr_usb_hHubsys_uitro HUBCD functions (uITRON) O On.cSMPLr_usb_pClassVendor. Peripheral class requestsO O O OcSMPLr_usb_smp_cSub.cCommon library functions O O O O O OSMPLr_usb_smp_hSub.cHost standard requests O O OSmplMainmain.cSample main programO O O O O OSmplMainRX62NRSK.cRX62N RSK processing O O O O OSmplMainRX630RSK.cRX630 RSK processing OSmplMainRX62NRSK_Extern.h RX62N RSK external reference O O O O OdefinitionsSmplMainRX630RSK_Extern.h RX630 RSK external reference OdefinitionsAPL r_usbc_PHSMPL_apl Host and Peripheral sample application O.cAPL r_usbc_PHSMPL_dat Data for Host and Peripheral sampleOa.c applicationAPL r_usbc_cdata.cData transfer data for port 0 and port 1 Osample applicationAPL r_usbc_cdata.hData transfer settings for port 0 andOport 1 sample applicationAPL r_usb2_HSMPL_apl. Host port 1 sample application OcAPL r_usb_HSMPL_apl.c Host sample application for R8A66597 OAPL r_usb2_cdata.cData transfer data for port 1 sample OapplicationAPL r_usb2_cdata.hData transfer settings for port 1 sample OapplicationAPL r_usb_PSMPL_apl.c Peripheral port 0 sample application O O OAPL r_usb_PSMPL_data. Data for peripheral port 0 sampleO O Oc applicationAPL r_usb_cdata.c Data transfer data for port 0 sample O O O OapplicationAPL r_usb_cdata.h Data transfer settings for port 0 sample O O O Oapplicationconfig_Pstd r_usb_RX62N.cfg Configuration file Oconfig_Pstd ritable_pstd.srcVector table setting OR01AN0512EJ0110 Rev.1.10 Page 31 of 126Jun 10, 2011 32. USB Basic FirmwareProject(O: Selected )config_Pstdr_usb_RX630.cfg Configuration file Oconfig_Pstdritable_rx630_pstd.sr Vector table setting O cconfig_Hstdr_usb_RX62N.cfg Configuration file Oconfig_Hstdritable_hstd.srcVector table setting Oconfig_Cstdr_usb_RX62N.cfg Configuration fileOconfig_Cstdritable_cstd.srcVector table settingOHwResourceFritable_rx62n.src Vector table setting for RX62N (non- O O OorUSBOS only)HwResourceF ritable_rx630.srcVector table setting for RX630 (non-OS OorUSBonly)HwResourceF ritable_assp.src Vector table setting for R8A66597 O OorUSB(non-OS only)HwResourceF dbsct.cSection settingO O O O O OorUSBHwResourceF resetprg.c Reset programO O O O O OorUSBHwResourceFOutput file of HEW O O O O O OorUSBRX62Niodefine.hIO definition file for RX62N O O OO ORX630iodefine.hIO definition file for RX630 O* 1): PORT0_P, 2): PORT1_H, 3): PORT0_P_PORT1_H, 4): RX630_PORT0_P , 5): ASSP_PERI , 6): ASSP_HOSTR01AN0512EJ0110 Rev.1.10Page 32 of 126Jun 10, 2011 33. USB Basic Firmware7. Sample Applications 7.1 Sample application for Data transfer (APL)USB-BASIC-F/W supports the sample application (APL) that can transfer data using pipes 1, 2, 6, and 7 in host orperipheral function mode as vendor specific class. When writing custom applications, refer to r_usb2_HSMPL_apl.cand r_usb_PSMPL_apl.c and make the applications.7.1.1 APL SequenceThe APL sequence in USB-BASIC-F/W is shown below.Host function mode Peripheral function mode APL APLR_usb2_hstd_ Initialize data SetPipeInfotransfer processingR_usb2_hstd_SetPipeRegistration Initialize datatransfer processing Data transfer ERRORcomplete ?R_usb2_hstd_ YESTransferStartReset data transfer processing Data transfer ERRORcomplete ? R_usb_pstd_ TransferStart YESCount down of data transfer counterreturn Data transfer NO counter is not 0 ?YESR_usb2_hstd_TransferStartAll data transferNO counter is 0 ?YESReset data transfer processingR_usb2_hstd_TransferStartFigure 7.1 APL sequenceR01AN0512EJ0110 Rev.1.10 Page 33 of 126Jun 10, 2011 34. USB Basic Firmware7.1.2APL Global AreaThe APL global area in USB-BASIC-F/W is shown below.Table 7.1 List of APL global area (Peripheral function mode) TypeVariable Description1USBC_UTR_tusb_gcstd_SmplTrnMsg[ ]Message area of pipes for data transferrequest2uint32_tusb_gcstd_SmplTrnCnt[ ]Data transfer counter of pipes3uint32_tusb_gcstd_SmplTrnSize[ ] Data transfer size of pipes4uint8_t * usb_gcstd_SmplTrnPtr[ ]Data address pointer of pipes for data transfer5uint8_t usb_gcstd_SmplTrnData1[ ]Data address of pipe1 for data transfer6uint8_t usb_gcstd_SmplTrnData2[ ]Data address of pipe2 for data transfer7uint8_t usb_gcstd_SmplTrnData3[ ]Data address of pipe3 for data transfer8uint8_t usb_gcstd_SmplTrnData4[ ]Data address of pipe4 for data transfer9uint8_t usb_gcstd_SmplTrnData5[ ]Data address of pipe5 for data transfer10 uint8_t usb_gcstd_SmplTrnData6[ ]Data address of pipe6 for data transfer11 uint8_t usb_gcstd_SmplTrnData7[ ]Data address of pipe7 for data transfer12 uint8_t usb_gcstd_SmplTrnData8[ ]Data address of pipe8 for data transfer13 uint8_t usb_gcstd_SmplTrnData9[ ]Data address of pipe9 for data transfer14 uint16_tusb_gpstd_SmplEpTbl1[ ]Pipe information table for data transferapplication15 uint16_tusb_gpstd_SmplEpTbl2[ ]Dummy of pipe information table16 uint16_tusb_gpstd_SmplEpTbl3[ ]Dummy of pipe information table17 uint16_tusb_gpstd_SmplEpTbl4[ ]Dummy of pipe information table18 uint16_tusb_gpstd_SmplEpTbl5[ ]Dummy of pipe information table19 uint16_t *usb_gpstd_SmplEpPtr[ ] Pointer table of pipe information table20 uint8_t usb_gpstd_SmplDeviceDescriptor[ ] Device descriptor for data transfer application21 uint8_t usb_gpstd_SmplQualifierDescriptor[ Qualifier descriptor for data transfer] application22 uint8_t usb_gpstd_SmplConfigurationH_1[Configuration descriptor of hi-speed for data ]transfer application23 uint8_t usb_gpstd_SmplConfigurationF_1[ ] Configuration descriptor of full-speed for datatransfer application24 uint8_t * usb_gpstd_SmplConPtr[ ]Pointer table of configuration descriptor fordata transfer application25 uint8_t * usb_gpstd_SmplConPtrOther[ ] Pointer table of other speed configurationdescriptor for data transfer application26 uint8_t usb_gpstd_StringDescriptor0[ ] String Descriptor0 for data transfer application27 uint8_t usb_gpstd_StringDescriptor1[ ] String Descriptor1 for data transfer application28 uint8_t usb_gpstd_StringDescriptor2[ ] String Descriptor2 for data transfer application29 uint8_t usb_gpstd_StringDescriptor3[ ] String Descriptor3 for data transfer application30 uint8_t usb_gpstd_StringDescriptor4[ ] String Descriptor4 for data transfer application31 uint8_t usb_gpstd_StringDescriptor5[ ] String Descriptor5 for data transfer application32 uint8_t * usb_gpstd_StrPtr[ ]Pointer table of string descriptor for datatransfer descriptorR01AN0512EJ0110 Rev.1.10 Page 34 of 126Jun 10, 2011 35. USB Basic FirmwareTable 7.2 List of APL global area (Host function mode) Type Variable Description1USBC_UTR_t usb2_gcstd_SmplTrnMsg[ ] Message area of pipes for data transfer request2uint32_t usb2_gcstd_SmplTrnCnt[ ] Data transfer counter of pipes3uint32_t usb2_gcstd_SmplTrnSize[ ]Data transfer size of pipes4uint8_t *usb2_gcstd_SmplTrnPtr[ ] Data address pointer of pipes for data transfer5uint8_tusb2_gcstd_SmplTrnData1[ ] Data address of pipe1 for data transfer6uint8_tusb2_gcstd_SmplTrnData2[ ] Data address of pipe2 for data transfer7uint8_tusb2_gcstd_SmplTrnData3[ ] Data address of pipe3 for data transfer8uint8_tusb2_gcstd_SmplTrnData4[ ] Data address of pipe4 for data transfer9uint8_tusb2_gcstd_SmplTrnData5[ ] Data address of pipe5 for data transfer10 uint8_tusb2_gcstd_SmplTrnData6[ ] Data address of pipe6 for data transfer11 uint8_tusb2_gcstd_SmplTrnData7[ ] Data address of pipe7 for data transfer12 uint8_tusb2_gcstd_SmplTrnData8[ ] Data address of pipe8 for data transfer13 uint8_tusb2_gcstd_SmplTrnData9[ ] Data address of pipe9 for data transfer14 uint16_t usb2_gpstd_SmplDefEpTbl[ ] Pipe information table for data transfer application15 uint16_t usb2_gpstd_SmplTmpEpTbl[ ] Pipe information table for data transfer application16 const uint16_t usb2_gpstd_SmplTpl[ ]Target peripheral list(TPL) for data transfer application17 uint16_t usb2_gpstd_SmplAdr Temporary area of device address for data transfer application18 uint16_t usb2_gpstd_SmplClassSeqSequence control data for data transfer application19 uint8_t *usb2_hcls_SmplDeviceTableTemporary area of pointer of device descriptor data for data transfer application20 uint8_t *usb2_hcls_SmplConfigTableTemporary area of pointer of configuration descriptor data for data transfer application21 uint8_t *usb2_hcls_SmplInterfaceTable Temporary area of pointer of interface descriptor data for data transfer application22 uint16_t usb2_hcls_SmplDevaddrTemporary area of pointer of device address data for data transfer application23 uint16_t usb2_hcls_SmplSpeedTemporary area of pointer of device speed data for data transfer applicationR01AN0512EJ0110 Rev.1.10Page 35 of 126Jun 10, 2011 36. USB Basic Firmware7.1.3APL Constant DefinitionThe APL constant definition in USB-BASIC-F/W is shown below.Table 7.3 List of APL constant definition (Peripheral function mode) Constant Name Value Description1Data length of descriptors USB_SMPLCONFLEN 46Data length of usb_gpstd_SmplConfigurationH_1[ ]/ usb_gpstd_SmplConfigurationF_1[ ] USB_SD1LEN32Data length of usb_gpstd_StringDescriptor1[ ] USB_SD2LEN28Data length of usb_gpstd_StringDescriptor2[ ]2Select using pipe for data transfer application USBC_USEPIPE_ALL_PP 1 Use pipe1 to pipe9 USBC_USEPIPE_1267_PP2 Use pipe 1,2,6 and 7 USBC_USEPIPE_MODE_PP2 Set to use pipe 1,2,6 and 73Table size of usb_gcstd_SmplTrnMsg[ ] usb_gcstd_SmplTrnCnt[ ] usb_gcstd_SmplTrnSize[ ] *usb_gcstd_SmplTrnPtr[ ] USB_TBL_MAX 10Use area between pipe0 and pipe9 (This value is index of the tables.)4Data transfer size USB_SMPL_TRNSIZE1 512 Data transfer size of pipe1 are 512 bytes USB_SMPL_TRNSIZE2 512 Data transfer size of pipe2 are 512 bytes USB_SMPL_TRNSIZE3 512 Data transfer size of pipe3 are 512 bytes USB_SMPL_TRNSIZE4 512 Data transfer size of pipe4 are 512 bytes USB_SMPL_TRNSIZE5 512 Data transfer size of pipe5 are 512 bytes USB_SMPL_TRNSIZE6 512 Data transfer size of pipe6 are 512 bytes USB_SMPL_TRNSIZE7 512 Data transfer size of pipe7 are 512 bytes USB_SMPL_TRNSIZE8 0 Data transfer size of pipe8 are 0 byte USB_SMPL_TRNSIZE9 0 Data transfer size of pipe9 are 0 byte5Data transfer times USB_SMPL_TRNCNT1512 Data transfer times of pipe1 are 512 times USB_SMPL_TRNCNT2512 Data transfer times of pipe2 are 512 times USB_SMPL_TRNCNT3512 Data transfer times of pipe3 are 512 times USB_SMPL_TRNCNT4512 Data transfer times of pipe4 are 512 times USB_SMPL_TRNCNT5512 Data transfer times of pipe5 are 512 times USB_SMPL_TRNCNT6512 Data transfer times of pipe6 are 512 times USB_SMPL_TRNCNT7512 Data transfer times of pipe7 are 512 times USB_SMPL_TRNCNT80 Pipe8 do not transfer USB_SMPL_TRNCNT90 Pipe9 do not transferR01AN0512EJ0110 Rev.1.10 Page 36 of 126Jun 10, 2011 37. USB Basic FirmwareTable 7.4 List of APL constant definition (Host function mode) Constant Name ValueDescription1Select using pipe for data transfer application USBC_USEPIPE_ALL_PP 1Use pipe1 to pipe9 USBC_USEPIPE_1267_PP2Use pipe 1,2,6 and 7 USBC_USEPIPE_MODE_PP2Set to use pipe 1,2,6 and 73Table size of usb2_gcstd_SmplTrnMsg[ ] usb2_gcstd_SmplTrnCnt[ ] usb2_gcstd_SmplTrnSize[ ] *usb2_gcstd_SmplTrnPtr[ ] USB2_TBL_MAX10 Use area between pipe0 and pipe9(This value is index of the tables.)4Data transfer size USB2_SMPL_TRNSIZE1512Data transfer size of pipe1 are 512 bytes USB2_SMPL_TRNSIZE2512Data transfer size of pipe2 are 512 bytes USB2_SMPL_TRNSIZE3512Data transfer size of pipe3 are 512 bytes USB2_SMPL_TRNSIZE4512Data transfer size of pipe4 are 512 bytes USB2_SMPL_TRNSIZE5512Data transfer size of pipe5 are 512 bytes USB2_SMPL_TRNSIZE6512Data transfer size of pipe6 are 512 bytes USB2_SMPL_TRNSIZE7512Data transfer size of pipe7 are 512 bytes USB2_SMPL_TRNSIZE80Data transfer size of pipe8 are 0 byte USB2_SMPL_TRNSIZE90Data transfer size of pipe9 are 0 byte5Data transfer times USB2_SMPL_TRNCNT1 512Data transfer times of pipe1 are 512 times USB2_SMPL_TRNCNT2 512Data transfer times of pipe2 are 512 times USB2_SMPL_TRNCNT3 512Data transfer times of pipe3 are 512 times USB2_SMPL_TRNCNT4 512Data transfer times of pipe4 are 512 times USB2_SMPL_TRNCNT5 512Data transfer times of pipe5 are 512 times USB2_SMPL_TRNCNT6 512Data transfer times of pipe6 are 512 times USB2_SMPL_TRNCNT7 512Data transfer times of pipe7 are 512 times USB2_SMPL_TRNCNT8 0Pipe8 do not transfer USB2_SMPL_TRNCNT9 0Pipe9 do not transfer7.1.4List of APL functionThe list of APL function in USB-BASIC-F/W is shown below.R01AN0512EJ0110 Rev.1.10Page 37 of 126Jun 10, 2011 38. USB Basic FirmwareTable 7.5 List of APL Function (Peripheral Function Mode) Function NameDescription1usb_pstd_PrAplTitleTitle output2usb_pstd_MainInitInitialize3usbc_cstd_MainTaskStartInitialize main task (uITRON only)4usbc_cstd_MainTask Main task5usb_pstd_MainLoopMain loop processing6usb_pstd_SetTaskPriSet task priority (nonOS only)7R_usb_pstd_SmplRegistrationRegister data transfer APL to PCD8R_usb_pstd_SmplOpenInitialize task of data transfer APL (uITRON) orInitialize data transfer APL (nonOS)9R_usb_pstd_SmplClose Cloze data transfer APL task (uITRON only)10 usb_pstd_MainTaskTask of data transfer APL11 usb_pstd_UserDataTrans Data transfer processing12 usb_pstd_SmplTransResult Callback function for data transfer completion13 usb_cstd_UsrCtrlTransFunctionCallback function for class request (empty function)14 usb_ptsd_UsrDataInit Initialize data of transfer15 usb_pstd_UsrDataTranStartStart data transfer (only 1st time, useusb_pstd_UserDataTrans() function since 2nd times )Table 7.6 List of APL Function (Host Function Mode) Function NameDescription1usb2_hstd_PrAplTitle Title output2usb2_hstd_MainInit Initialization processing3usbc_cstd_MainTaskStartInitialize main task (uITRON only)4usbc_cstd_MainTask Main task5usb2_hstd_MainLoop Main loop processing6usb2_hstd_SetTaskPri Set task priority (nonOS only)7R_usb2_hstd_SmplClassCheck Class check processing in enumeration (uITRON) orProcessing that change to class checkfunction(usb2_hcls_SmplEnue()function) (nonOS)8usb2_hcls_SmplEnue Class check processing in enumeration (nonOS only)9R_usb2_hstd_SmplOpen Initialize task of data transfer APL (uITRON) orInitialize data transfer APL (nonOS)10 R_usb2_hstd_SmplCloseCloze data transfer APL task (uITRON only)11 usb2_hcls_SmplInit Initialize data of transfer12 usb2_hstd_MainTask Task of data transfer APL13 usb2_hstd_SmplPipeTransfer Data transfer processing14 usb2_hstd_SmplPipeTransferResult Callback function for data transfer completion15 usb2_hstd_SmplPipeInfo Check information of pipes using16 usb2_hstd_HubRegistAll Register HUB driver to HCD17 R_usb2_hstd_SmplRegistration Register data transfer APL to HCD18 usb2_hcls_SmplTask Task of data transfer APL (nonOS only)19 usb2_hcls_SmplCheckRequest Processing that changes to next sequence to check standardrequest result in enumeration (nonOS only)20 usb2_hcls_SmplCheckResultCallback function for standard request completion inenumeration (nonOS only)21 usb2_hcls_SmplInitSetProcessing that changes to transfer data initialization (nonOSonly)R01AN0512EJ0110 Rev.1.10 Page 38 of 126Jun 10, 2011 39. USB Basic Firmware7.2 Power Consumption ControlSystem of RX62N and RX630 changes to low power consumption state of low power consumption function whenUSBC_LPWR_MODE = USBC_LPWR_USE_PP is set in peripheral function mode.A transition to the low-power state occurs when one of the following conditions is detected.1. Detached state: Deep software standby mode2. Suspend state: Sleep modeRefer to the RX62N Group Hardware Manual or RX630 Group Hardware Manual for information on the low-powerfunctions.7.2.1Sequence of Power Consumption ControlIn USB-BASIC-F/W, the Idle task is used to change to low power state in detached state or suspended state.When USBC_LPWR_MODE_PP = USBC_LPWR_USE_PP, the idle task is initialized in usbc_cstd_MainTask()function, and the idle task can be used. The priority of the idle task should lower most.The sequence of the idle task is shown below.usbc_cstd_IdleTask YESUSBC_TRCV_MSG?NOUSBC_SND_MSG R_usb_pstd_ (Idle task) DeviceInformation() nonOS only USB status?Detach Suspendelse usbc_cpu_GoLpwrusbc_cpu_GoLpwrDeepStby() Sleep() Figure 7.27.2.2Global area of Power Consumption ControlThe list of global area of the idle task is shown below.Table 7.7 List of global area of the idle taskType VariableDescription1 uint16_t usb_gcpu_RemoteProcessIn peripheral function mode, status flag for executing remote wakeup in suspended state (nonOS only)R01AN0512EJ0110 Rev.1.10 Page 39 of 126Jun 10, 2011 40. USB Basic Firmware7.2.3List of function of Power Consumption ControlThe list of functions of the idle task is shown below.Table 7.8 List of function of the idle taskFunction NameDescription1 usbc_cstd_IdleTaskStartStart idle task2 usbc_cstd_IdleTask Idle task3 usbc_cpu_GoLpwrDeepStbyProcessing for changing to the deep software standby mode4 usbc_cpu_GoLpwrSleep Processing for changing to the sleep modeR01AN0512EJ0110 Rev.1.10Page 40 of 126Jun 10, 2011 41. USB Basic Firmware8. Peripheral Driver (PCD) 8.1 Basic FunctionsPCD is a program for controlling the hardware. PCD analyzes requests from PDCD and controls the hardwareaccordingly. It also sends notification of control results using a call-back function as well as analyzing requests from thehardware and notifying PDCD accordingly. The functions of PCD are as follows.1. Control transfer (ControlRead, ControlWrite, NoDataControl)2. Data transfer (bulk, isochronous, interrupt) and result notification3. Data transfer suspension (all pipes)4. USB bus reset signal detection and reset handshake result notification5. Suspend/resume detection6. Attach/detach detection using VBUS interrupt7. Hardware control when entering and returning from the clock stopped (low-power sleep mode) state 8.2 Issuing Requests to PCDAPI functions are used when hardware control requests are issued to the PCD and when performing data transfers. APIfunctions and library functions can be used to obtain information for managing PCD.In response to a request from a higher level task, PCD sends a result notification by means of a call-back function.PCD has no API functions for control transfer (class/vendor requests). 8.3 USB RequestsWhen PCD receives a USB request, it executes the corresponding function for standard request as shown in table 8.1,and it executes the registered function to "ctrltrans" in R_usb_pstd_DriverRegistration() function for Device Classrequest and Vendor Class request. If it is necessary for PDCD to respond to device class (vendor class) requests, thecustomer should prepare the necessary program code for evaluating such requests and add it to the sample program.(See section 9 for more information.) When a valid request is received, the ControlRead function generates data for transmission to the host and writes itto the FIFO. When a valid request is received, the ControlWrite function enables data reception from the host. When a valid request is received, the NoDataControl function returns the status. The ControlRead/Write-Status function returns the status. The ControlTransferEnd function sends notification to PDCD of a request from the host.Table 8.1List of Control Transfer FunctionsClass Response toRequest Standard Device Class Vender Class HostControlRead usb_pstd_StandReq1() usb_pstd_ClassReq1() usb_pstd_VendorReq1()Transmit dataControlWriteusb_pstd_StandReq2() usb_pstd_ClassReq2() usb_pstd_VendorReq2()Receive dataNoDataControl usb_pstd_StandReq3() usb_pstd_ClassReq3() usb_pstd_VendorReq3()Return statusCR-Status usb_pstd_StandReq4() usb_pstd_ClassReq4() usb_pstd_VendorReq4()Return statusCW-Status usb_pstd_StandReq5() usb_pstd_ClassReq5() usb_pstd_VendorReq5()Return statusControlTransferEndusb_pstd_StandReq0() usb_pstd_ClassReq0() usb_pstd_VendorReq0()NoneR01AN0512EJ0110 Rev.1.10Page 41 of 126Jun 10, 2011 42. USB Basic Firmware8.4Starting PDCDPCD notifies PDCD of the configuration by means of the call-back function registered when the configuration wasestablished with the host (SET_CONFIGURATION request response). PDCD generates the tasks, mailboxes, andmemory pools, and starts the task. PDCD enables data communication if operation will commence with data reception.8.5PCD Task Start SequenceThe start sequence of the PCD task is shown below.Main_Task Hardware Wait for hardwareusb_cstd_WaitUsbip() readyusb_cstd_AsspConfig() Pin control 1usb_cstd_SwReset()Software resetusb_cstd_IntialClock()Start oscillatorusb_cstd_Pinconfig() Pin control 2usb_pstd_PcdOpen()Start PCD task PCDR_usb_pstd_SmplRegistraion()Register driversusb_cstd_SetHwFunction(USB_PERI) Set PERI functionMainPERI Norcv msg?MainPERI Command processingApplicationReturn Figure 8.1 PCD Start SequenceR01AN0512EJ0110 Rev.1.10 Page 42 of 126Jun 10, 2011 43. USB Basic Firmware8.6PCD Sequence OutlineThe PCD sequence outline is shown below. PDCD PCD Interrupt HardwareUSB interrupt PCDAPI USB interrupt Clear statusnotificationrcv_msg?No usb_pstd_Interrupt()USB interrupt R_usb_pstd_TransferStart()Transfer data usb_pstd_RemoteWakeup() Wakeup R_usb_pstd_PcdChangeDeviceState() Clear toggleR_usb_cstd_SetStall() Set stallusb_cstd_DataEnd() Suspend transferFigure 8.2 PCD Sequence OutlineR01AN0512EJ0110 Rev.1.10 Page 43 of 126Jun 10, 2011 44. USB Basic Firmware 8.7 PCD API FunctionsPDCD implements hardware control requests by using API functions. The API functions are contained in the filer_usb_pDriverAPI.c, and the return values of each API function correspond to scheduler macro error codes. Thenumber 8 in table 8.2, R_usb_cstd_ClearHwFunction() function is in r_usb_cSignal.c file.Table 8.2List of PCD API Functions Function NameDescription1R_usb_pstd_PcdOpen() Start PCD task2R_usb_pstd_PcdClose()End PCD task3R_usb_pstd_TransferStart() Data transfer execution request4R_usb_pstd_SetStall()Pipe stall setting request5R_usb_pstd_TransferEnd() Data transfer forced end request6R_usb_pstd_DriverRegistration()Register PDCD7R_usb_pstd_DriverRelease() Release PDCD8R_usb_cstd_ClearHwFunction() USB-Related Register Initialization Request9R_usb_pstd_PcdChangeDeviceState()USB device state change request10 R_usb_pstd_DeviceInformation() Get USB device state information11 R_usb_pstd_SetPipeRegister() Set pipe configuration12 R_usb_pstd_ControlRead() FIFO access execution request for control read transfer13 R_usb_pstd_ControlWrite()FIFO access execution request for control write transfer14 R_usb_pstd_ControlEnd()Control transfer end request8.7.1 Details of PCD API FunctionsTable 8.3R_usb_pstd_PcdOpen()NameStart PCD TaskCall format USBC_ER_t R_usb_pstd_PcdOpen(void)Arguments void Return values USBC_ER_t Error codeThis function starts the PCD task.It initializes the global variables, generates the tasks, mailboxes, and memory pools, andDescriptionstarts the task.The PCD task waits for requests from the hardware and PDCD.Notes Calling this function starts the PCD task. Do not call it after the PCD task has started.Table 8.4R_usb_pstd_PcdClose()NameEnd PCD TaskCall format USBC_ER_t R_usb_pstd PcdClose(void)Arguments void Return values USBC_ER_t Error codeThis function stops the PCD task.DescriptionIt releases the mailboxes and memory pools, and ends the task.Notes Calling this function ends the PCD task. Do not call it after the PCD task has ended.R01AN0512EJ0110 Rev.1.10 Page 44 of 126Jun 10, 2011 45. USB Basic FirmwareTable 8.5 R_usb_pstd_TransferStart()Name Data Transfer RequestCall formatUSBC_ER_t R_usb_pstd_TransferStart(USBC_UTR_t *utr_table)ArgumentsUSBC_UTR_t*utr_tableTransfer information. See structure definitions.Return valuesUSBC_ER_t Error code This function transfers data via the pipes. When data transfer ends (specified data size reached, short packet received, error occurred), notification of the remaining transmit/receive data length, status, error count,Description and transfer end is made by means of the call-back function argument (utr_table). The data transfer information indicated in the utr_table is transmitted to PCD as a message, and PCD executes the appropriate processing. The structure members indicated by the argument include pipe number, transfer data startNotesaddress, transfer data length, status, call-back function at end, and error count. This function does not support control transfer.Table 8.6 R_usb_pstd_SetStall()Name Stall Setting RequestCall formatUSBC_ER_t R_usb_pstd_SetStall(USBC_CB_INFO_t complete, uint16_t pipe) USBC_CB_INFO_ complete Call-back functionArgumentst uint16_tpipe Pipe numberReturn valuesUSBC_ER_t Error code This function puts pipes into the stall state. When processing ends, it sends notification of the stall setting by means of a call-backDescription function. This is transmitted to PCD as a message, and PCD executes the appropriate processing.NotesCanceling the stall state is accomplished by using a standard request.Table 8.7 R_usb_pstd_TransferEnd()Name Data Transfer Forced End RequestCall formatUSBC_ER_t R_usb_pstd_TransferEnd(uint16_t pipe , uint16_t status) uint16_t pipe Pipe numberArguments uint16_t status StatusReturn valuesUSBC_ER_tError code This function forces data transfer via the pipes to end. When data transfer is forced to end, notification of the remaining transmit/receive dataDescriptionlength, status, error count, and forced end is made by means of the submit call-back function argument (utr_table). It is transmitted to PCD as a message, and PCD executes the appropriate processing.NotesThe submit call-back function is executed.Table 8.8 R_usb_pstd_DriverRegistration()Name Register PDCDCall formatvoid R_usb_pstd_DriverRegistration(USBC_PCDREG_t *callback) USBC_PCDREG_Arguments *callback Driver information tReturn valuesvoid This function registers a PDCD.Description After registration, the initialization call-back function is executed.NotesIn peripheral function mode, only one device can be registered.R01AN0512EJ0110 Rev.1.10Page 45 of 126Jun 10, 2011 46. USB Basic FirmwareTable 8.9 R_usb_pstd_DriverRelease()Name Release PDCDCall formatvoid R_usb_pstd_DriverRelease(void)Argumentsvoid Return valuesvoid This function cancels the registration of a PDCD registered in PCD.Description The released driver area becomes an empty area.NotesTable 8.10 R_usb_cstd_ClearHWfunction()Name USB-Related Register Initialization RequestCall formatvoid R_usb_cstd_ClearHWfunction(void)Argumentsvoid Return valuesvoid DescriptionThis function initializes USB-related registers. This function is common to the host and peripheral function modes, so it is listed in theNotes HCD API Functions section as well.Table 8.11 R_usb_pstd_PcdChangeDeviceStateName USB Device State Change Request USBC_ER_t R_usb_pstd_PcdChangeDeviceState(uint16_t msginfo, uint16_t member,Call format USBC_CB_INFO_t complete) uint16_t msginfo Device state to be transitioned to uint16_t memberPort numberArguments USBC_CB_INFO_completeCall-back function executed at end of PCD processing tReturn valuesUSBC_ER_t Error code This function sends a request to PCD to change the USB device state. One of the following requests is designated by an argument (msginfo), and then this function is called.USBC_DO_REMOTEWAKEUP:Remote wakeup execution request to PCD (request to recover from suspend status to a state inDescription which USB communication is enabled)USBC_DP_ENABLE: D+ line pull-up request to PCD (request to transition from disconnected to connected state)USBC_DP_DISABLE: D+ line pull-up cancel request to PCD (request to transition from connected to disconnected state)NotesR01AN0512EJ0110 Rev.1.10 Page 46 of 126Jun 10, 2011 47. USB Basic FirmwareTable 8.12 R_usb_pstd_DeviceInformationNameGet USB Device State Information RequestCall format void R_usb_pstd_DeviceInformation(uint16_t *tbl)Arguments uint16_t *tblAddress of table where fetched information is storedReturn values This function gets USB device state information.It stores the following information at the address designated by the argument (*tbl).[0] USB device stateDescription[1] USB transfer speed[2] Configuration number used[3] Interface number usedNotesTable 8.13 R_usb_pstd_SetPipeRegister()NameSet Pipe Configuration RequestCall format void R_usb_pstd_SetPipeRegister(uint16_t pipe_number, uint16_t *tbl) pipe_numbeuint16_tPipe numberArgumentsruint16_t *tbl Pipe information tableReturn values void Description This function performs pipe configuration settings.NotesTable 8.14 R_usb_pstd_ControlRead()NameFIFO Access Execution Request for Control Read TransferCall format void R_usb_pstd_ControlRead(uint32_t bsize, uint8_t *table)uint32_t bsize Transmit data buffer size for control read transferArgumentsuint8_t*tableTransmit data buffer address for control read transferReturn values void This function issues a FIFO access execution request for control read transfer.Description PCD reads data from the area indicated by the argument (*table) and writes it to the FIFObuffer of the hardware.NotesTable 8.15 R_usb_pstd_ControlWrite()NameFIFO Access Execution Request for Control Write TransferCall format void R_usb_pstd_ControlWrite(uint32_t bsize, uint8_t *table)uint32_t bsize Receive data buffer size for control write transferArgumentsuint8_t*tableReceive data buffer address for control write transferReturn values void This function issues a FIFO access execution request for control read transfer.Description PCD reads data from the FIFO buffer of the hardware and writes it to the area indicated bythe argument (*table).NotesR01AN0512EJ0110 Rev.1.10Page 47 of 126Jun 10, 2011 48. USB Basic FirmwareTable 8.16 R_usb_pstd_ControlEnd()Name Control Transfer End RequestCall formatvoid R_usb_pstd_ControlEnd(uint16_t status)Argumentsuint16_t statusStatusReturn valuesvoid This function issues a request for control transfer status stage execution. Set the argument (status) to one of the following four options.USBC_CTRL_END: Status stage normal endDescriptionUSBC_DATA_ERR: Return STALL to host at status stageUSBC_DATA_OVR: Return STALL to host at status stageUSBC_DATA_STOP: Return NAK to host at status stageNotes8.8 PCD Call-Back FunctionsTable 8.17 R_usb_pstd_TransferStart Call-BackName Data Transfer Request Call-Back FunctionCall format(*USBC_CB_t)(USBC_UTR_t *);ArgumentsUSBC_UTR_t *Submitted USBC_UTR_t pointerReturn values This function is executed at data transfer end (a transfer end condition at the end of a data transfer of the size specified by the transfer application, when a short packet is received,Description etc.). The remaining transmit/receive data length and the error count are updated.NotesTable 8.18 Call-Back of control transferName Call-back function of control transfer without standard requestCall format(*USBC_CB_TRN_t)(USBC_REQUEST_t *, uint16_t); USBC_REQUEST Information of requestArguments_t * uint16_tInformation of stageReturn values DescriptionThis call-back is called by USB interrupt in control transfer without standard request.NotesTable 8.19 Other Call-BacksName Other Call-Back FunctionsCall format(*USBC_CB_INFO_t)(uint16_t,uint16_t) uint16_t NOARGUMENT: Not usedArguments uint16_t NOARGUMENT: Not usedReturn values usb_pstd_Remote: Executed at end of remote wakeup processing. usb_pstd_ClearSeqbit: Executed when the sequence toggle bit is cleared.Description R_usb_pstd_SetStall: Executed when the sequence toggle bit is set to the stall state. R_usb_pstd_TransferEnd: Executed at data transfer end.NotesR01AN0512EJ0110 Rev.1.10 Page 48 of 126Jun 10, 2011 49. USB Basic Firmware8.9Structure Definitions8.9.1 USBC_PCDINFO_t StructureThe structure used by the R_usb_pstd_PcdDeviceState(), R_usb_pstd_SetStall(), and R_usb_pstd_TransferEnd()functions to transmit messages to PCD is described below.typedef struct {USBC_MH_tmsghead;// Message header used by the OSuint16_t msginfo;// Message information used by USB-BASIC-F/Wuint16_t keyword;// Sub-information (port number, pipe number, etc.)USBC_CB_INFO_t Complete; // Call-back function at end of processing}USBC_PCDINFO_t;Table 8.20 Members of USBC_PCDINFO_t StructureVariable NameDescriptionmsgheadThis message header is used by the OS, so the client should not make use of it.msginfoIs used by USB-BASIC-F/W, so the client should not make use of it.keywordThis differs depending on the message, as shown below. Pipe number: R_usb_pstd_SetStal, R_usb_pstd_TransferEnd Port number: R_usb_pstd_PcdChangeDeviceStateComplete This specifies the address of the function to be executed when PCD processing ends. The call-back function should have a void (*USBC_CB_INFO_t) (uint16_t,uint16_t) type declaration. When call-back occurs, it means that processing has ended.8.9.2 Information Registered in PCD (USBC_PCDREG_t Structure)The structure used to register information in PDCD is described below. The call-back function is executed when thedevice state changes, etc.typedef struct {uint16_t **pipetbl;/* Pipe Define Table address */uint8_t*devicetbl; /* Device descriptor address */uint8_t*qualitbl;/* Qualifier descriptor address */uint8_t**configtbl;/* Configuration descriptor address */uint8_t**othertbl; /* Other speed descriptor address */uint8_t**stringtbl;/* String descriptor address */USBC_CB_INFO_t classinit;/* Driver init */USBC_CB_INFO_t devdefault; /* Device default */USBC_CB_INFO_t devconfig;/* Device configured */USBC_CB_INFO_t devdetach;/* Device detach */USBC_CB_INFO_t devsuspend; /* Device suspend */USBC_CB_INFO_t devresume;/* Device resume */USBC_CB_INFO_t interface ; /* Interface changed */USBC_CB_TRN_tctrltrans;/* Control Transfer */}USBC_PCDREG_t;R01AN0512EJ0110 Rev.1.10 Page 49 of 126Jun 10, 2011 50. USB Basic FirmwareTable 8.21 Members of USBC_PCDREG_t StructureVariable Name Description**pipetbl Register the address of the pipe information table.*devicetRegister the device descriptor address.*qualitbl Register the device qualifier descriptor address.**configtbl Register the address of the configuration descriptor address table.**othertblRegister the address of the other speed descriptor address table.**stringtbl Register the address of the string descriptor address table.classinit Register the function to be started when initializing PDCD.It is called at registration.devdefaultRegister the function to be started when transitioning to the default state.It is called when a USB reset is detected.devconfig Register the function to be started when transitioning to the configured state.It is called in the SET_CONFIGURATION request status stage.devdetach Register the function to be started when transitioning to the detach state.It is called when a detached condition is detected.devsuspendRegister the function to be started when transitioning to the suspend state.It is called when a suspend condition is detected.devresume Register the function to be started when transitioning to the resume state.It is called when a resume condition is detected.interface Register the function to be started when an interface change occurs.It is called in the SET_INTERFACE request status stage.ctrltrans Register the function to be started when a user-initiated control transfer occurs.8.9.3USBC_PCDREQUEST_t StructureThe structure is used as arguments of call-back of control transfer without standard request. The call-back is registeredby ctrltrans in USB_PCDREG_t structure (refer to 8.9.2).typedef struct {uint16_tReqType;/* Request type */uint16_tReqTypeType;/* Request type TYPE */uint16_tReqTypeRecip; /* Request type RECIPIENT */uint16_tReqRequest; /* Request */uint16_tReqValue; /* Value */uint6_t ReqIndex; /* Index */uint16_tReqLength;/* Length */}USBC_REQUEST_t;R01AN0512EJ0110 Rev.1.10Page 50 of 126Jun 10, 2011 51. USB Basic FirmwareTable 8.22 Members of USBC_REQUEST_t StructureVariable NameDescriptionReqTypeThe value is bmRequestType[D7-D0] of request. (The value is BMREQUESTTYPE of USBREQ register.) When this value is used, mask with USBC_BMREQUESTTYPE(0x00FFu).ReqTypeTypeThe value is Type of bmRequestType[D6-D5] of request. (The value is b6-5 of BMREQUESTTYPE of USBREQ register.) When this value is used, mask with USBC_BMREQUESTTYPETYPE(0x0060u).ReqTypeRecip The value is Recipient of bmRequestType[D4-D0] of request. (The value is b4-0 of BMREQUESTTYPE of USBREQ register.) When this value is used, mask with USBC_BMREQUESTTYPERECIP(0x001Fu).ReqRequest The value is bRequest of request. (The value is BREQUEST of USBREQ register.) When this value is used, mask with USBC_BREQUEST(0xFF00u).ReqValue The value is wValue of request. (The value is USBVAL register.)ReqIndex The value is wIndex of request. (The value is USBINDEX register.)ReqLengthThe value is wLength of request. (The value is USBLENG register.)8.10OverviewIn order for USB-BASIC-F/W to operate in peripheral function mode, it is necessary to create a descriptor table thatmatches the system under development. (A sample table is included in r_usb_PSMPL_data.c.)The descriptor definitions comprise the following four types.1. Standard Device Descriptoruint8_t usb_gpstd_SmplDeviceDescriptor[]2. Device Qualifier Descriptoruint8_t usb_gpstd_SmplQualifierDescriptor[]10. Configuration/Other_Speed_Configuration/Interface/Endpointuint8_t usb_gpstd_SmplConfigurationH_1[]uint8_t usb_gpstd_SmplConfigurationF_1[]10. String Descriptoruint8_t usb_gpstd_StringDescriptor1[]uint8_t usb_gpstd_StringDescriptor2[]uint8_t usb_gpstd_StringDescriptor3[]uint8_t usb_gpstd_StringDescriptor4[]uint8_t usb_gpstd_StringDescriptor5[]Notes: 1. For details of each descriptor, see chapter 9 of the USB revision 2.0 specification. 10. When making changes to descriptor definitions, it is also necessary to make changes to the pipe information table to match the endpoint descriptors. (A sample table is included in r_usb_PSMPL_data.c.)R01AN0512EJ0110 Rev.1.10Page 51 of 126Jun 10, 2011 52. USB Basic Firmware8.11 Descriptor Generation ExamplePDCD must generate Configuration/Other_Speed_ConfigurationDescriptor when a USB reset is detected. In the sampletable the portions changes by the program are indicated by the designation USBC_SOFT_CHANGE. R_usb_pstd_SmplDescriptorChange Full-speed Hi-speed connection?Hi-speedusb_gpstd_SmplConfigurationH_1[1] = USB_DT_CONFIGURATION;usb_gpstd_SmplConfigurationF_1[1] = USB_DT_OTHER_SPEED_CONF;usb_gpstd_SmplConPtr[0] = usb_gpstd_SmplConfigurationH_1;usb_gpstd_SmplConPtrOther[0]= usb_gpstd_SmplConfigurationF_1;usb_gpstd_SmplEpTbl1[(USB_EPL * 0) + 3] = 512;usb_gpstd_SmplEpTbl1[(USB_EPL * 1) + 3] = 512;usb_gpstd_SmplEpTbl1[(USB_EPL * 2) + 3] = 512;usb_gpstd_SmplEpTbl1[(USB_EPL * 3) + 3] = 512;usb_gpstd_SmplEpTbl1[(USB_EPL * 4) + 3] = 512;usb_gpstd_SmplConfigurationF_1[1] = USB_DT_CONFIGURATION;usb_gpstd_SmplConfigurationH_1[1] = USB_DT_OTHER_SPEED_CONF;usb_gpstd_SmplConPtr[0] = usb_gpstd_SmplConfigurationF_1;usb_gpstd_SmplConPtrOther[0]= usb_gpstd_SmplConfigurationH_1;usb_gpstd_SmplEpTbl1[(USB_EPL * 0) + 3] = 64;usb_gpstd_SmplEpTbl1[(USB_EPL * 1) + 3] = 64;usb_gpstd_SmplEpTbl1[(USB_EPL * 2) + 3] = 64;usb_gpstd_SmplEpTbl1[(USB_EPL * 3) + 3] = 64;usb_gpstd_SmplEpTbl1[(USB_EPL * 4) + 3] = 64; ReturnFigure 8.3 Descriptor Table Generation ExampleR01AN0512EJ0110 Rev.1.10 Page 52 of 126Jun 10, 2011 53. USB Basic Firmware9. Peripheral Control Transfer 9.1OverviewThe following standard requests are supported by PCD.GET_STATUSGET_DESCRIPTORGET_CONFIGURATIONGET_INTERFACECLEAR_FEATURESET_FEATURESET_ADDRESSSET_CONFIGURATIONSET_INTERFACEPCD answers requests other than the above with a STALL response.In the HID class, the usb_cstd_GetDescriptorInterface() function is called by the GET_DESCRIPTOR processingbecause it is necessary to notify a peculiar descriptor of the class by using a standard request.To simplify providing support for class or vendor requests, dummy functions are provided for the various stages. APIfunctions for data transmit/receive are also provided in the data stage.9.1.1 Basic SpecificationsThe API functions that can be used in the control transfer data stage divide the transfer into transaction (FIFO buffersize/packet size) units and access the FIFO buffer.The BRDY interrupt is used for data reception, so this interrupt must be enabled when starting data reception.The BEMP interrupt is used for data transmission, so this interrupt must be enabled when starting data transmission.Make sure that the capacity of the user buffer exceeds the transmit/receive data size in the data stage.The R_usb_pstd_ControlRead() and R_usb_pstd_ControlWrite() functions are CPU access functions.9.1.2 Detailed SpecificationsA user buffer is provided between PCD and the customers program, and PCD uses CPU access to perform data transferbetween the user buffer and FIFO port registers. The customers application should make use of the R_usb_pstd_ControlRead() and R_usb_pstd_ControlWrite()functions. The data stage transfer direction is determined by the usb_pstd_BrdyPipe () and usb_pstd_BempPipe() functions. Interrupts are used for data transfers that exceed the FIFO buffer size. The usb_cstd_Buf2Fifo() and usb_cstd_Cfifo2Buf() functions perform continuous data transfer. To successfully end the status stage, set PID to BUF and CCPI to 1. The R_usb_pstd_ControlEnd(USBC_CTRL_END) function ends a control transfer. Generation of the data for the data stage is performed by the customers program.Generation case 1: Generation by request determination in interrupt (same as standard request)Generation case 2: Generation by application (notification to customers application by interrupt)The arguments are as follows.uint32_t bsize: Transfer data sizeuint8_t *table: User buffer address for transfer dataR01AN0512EJ0110 Rev.1.10 Page 53 of 126Jun 10, 2011 54. USB Basic FirmwareThe return values are as follows.USBC_WRITEEND: Data write end (no additional data/transmission of packet with data length 0)USBC_WRITESHRT: Data write end (short packet data write)USBC_WRITING: Data write in progress (additional data present)USBC_READEND: Data read end (no additional data)USBC_READSHRT: Data read end (short packet data read)USBC_READING: Data read in progress (additional data present)USBC_READOVR: Data read end (exceeds buffer size)USBC_FIFOERROR: FIFO access error9.2 Example of Control Transfer in a Customers Program9.2.1 Control Read1. The R_usb_pstd_ControlRead () function is called in the control read data stage (usb_pstd_ClassReq1() function).2. Additional transmit data is transferred to the FIFO buff