コード例 #1
0
void main(void)
#endif
#endif
{
  VCom_Configuration();

  /* CDC layer initialization */
  USB_CDC_Init(Buffer, 1, SET);

  Setup_CPU_Clock();
  Setup_USB();

  /* Main loop */
  while (1)
  {
  }

}
コード例 #2
0
ファイル: HW_USB.c プロジェクト: TivonFeng/LPLG_GPS
void LPLD_USB_Init(void)
{ 
  MPU->CESR=0; //MPU 配置 
  SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK |   //选择PLL/FLL作为时钟源
               SIM_SOPT2_PLLFLLSEL_MASK; //用PLL作为USB的时钟源,此时的PLL的频率为96Mhz 
#if(CORE_CLK_MHZ == PLL_96)
  SIM->CLKDIV2 = 0x02;                    //设置分频系数USB时钟 = 96Mhz/2 =48Mhz
#endif 
  SIM->SCGC4 |= (SIM_SCGC4_USBOTG_MASK);  //使能USB外设时钟  
  USB0->USBTRC0 = 0x40;                   //按照文档所述,此位必须设置为1
  SIM->SOPT1 |= SIM_SOPT1_USBREGEN_MASK;  //配置USB设备稳压源
  
  /* NVIC模块配置 */
  enable_irq(USB0_IRQn);                 //使能NVIC中的USB OTG中断
  USB_ISR[0] = USB_DEVICE_ISR;           //将USB协议处理函数添加到中断处理函数数组中
  
#if(USB_DEVICE_CLASS == USB_DEVICE_CLASS_CDC)
  USB_CDC_Init();                        //初始化CDC类
#elif(USB_DEVICE_CLASS == USB_DEVICE_CLASS_HID)
  USB_HID_Mouse_Init();                  //初始化HID类
#endif
  
  
}
コード例 #3
0
/*******************************************************************************
* Function Name  : VCOMFunc
* Description    : Demonstration of USB-to-UART VCOM bridge.
*                : Displays prompt on LCD, enables the bridge and waits for
*                : joystick SEL key pressed to stop bridging and return
*                : to main menu.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void VCOMFunc(void) {
  uint32_t key;

  /* Display prompt */
  VCOMHelp();

  /* Save current CPU CLOCK configuration */
  temp_CPU_CLOCK   = MDR_RST_CLK->CPU_CLOCK;
  temp_PLL_CONTROL = MDR_RST_CLK->PLL_CONTROL;

  Setup_CPU_Clock();

  UARTConfiguration();

  /* CDC layer initialization */
  USB_CDC_Init(SendBuffer, 1, SET);

  /* UART configuration */
  UARTInitStructure.UART_BaudRate                = 14400;
  UARTInitStructure.UART_WordLength              = UART_WordLength8b;
  UARTInitStructure.UART_StopBits                = UART_StopBits1;
  UARTInitStructure.UART_Parity                  = UART_Parity_No;
  UARTInitStructure.UART_FIFOMode                = UART_FIFO_OFF;
  UARTInitStructure.UART_HardwareFlowControl     = UART_HardwareFlowControl_RXE | \
                                                   UART_HardwareFlowControl_TXE;
  /* With LBE bit set, output line of UARTTXD transmitter becomes to be bound to
   * UARTRXD receiver input. In order to run this example with UART physically
   * connected to PC, just comment this line */
/*  UARTInitStructure.UART_HardwareFlowControl     |= UART_HardwareFlowControl_LBE; */

  UART_Init (UART,&UARTInitStructure);

#ifdef USB_CDC_LINE_CODING_SUPPORTED
  /* Set line coding initial settings accordingly to UART ones above */
  LineCoding.dwDTERate = UARTInitStructure.UART_BaudRate;
  LineCoding.bCharFormat = USB_CDC_STOP_BITS1;
  LineCoding.bParityType = USB_CDC_PARITY_NONE;
  LineCoding.bDataBits = USB_CDC_DATA_BITS8;
#endif /* USB_CDC_LINE_CODING_SUPPORTED */

  /* Set interrupt handlers */
  pfUARTReceiverFunc = ReceiverFunc;
  pfUARTSenderFunc = SenderFunc;
#ifdef USB_CDC_STATE_REPORTING_SUPPORTED
  pfUARTLineStateFunc = LineStateFunc;
#endif /* USB_CDC_STATE_REPORTING_SUPPORTED */

  /* Enable sender, receiver and line state interrupts */
  UART_ITConfig (UART, UART_IT_TX | UART_IT_RX
#ifdef USB_CDC_STATE_REPORTING_SUPPORTED
              | UART_LINE_STATE_EVENTS
#endif /* USB_CDC_STATE_REPORTING_SUPPORTED */
              , ENABLE);

  /* Enable bridge */
  UART_Cmd(UART, ENABLE);
  Setup_USB();

  /* Wait for SEL to quit */
  key = GetKey();
  for (; key != SEL; key = GetKey())
  {
  }
  WAIT_UNTIL_KEY_RELEASED(SEL);

  /* Disable bridge */
  UART_Cmd(UART, DISABLE);
#if defined (USE_MDR32F9Q2_Rev0) || defined (USE_MDR32F9Q2_Rev1)
  PORTBRestoreConfig();
#endif /* defined (USE_MDR32F9Q2_Rev0) || defined (USE_MDR32F9Q2_Rev1) */
  USB_CDC_ReceiveStop();
  USB_DevicePowerOff();

  /* Restore original CPU CLOCK configuration */
  MDR_RST_CLK->CPU_CLOCK   = temp_CPU_CLOCK;
  MDR_RST_CLK->PLL_CONTROL = temp_PLL_CONTROL;

  DisplayMenu();
}