ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Вторник
26 ноября
1017103 Топик полностью
BlackMorda, мудак (10.07.2020 13:09, просмотров: 506) ответил POV_ на Example_USB_Virtual_Com_Port...
Я использовал вот этот 

Функция USB_ConnectRes() управляет резистором 1,5к на D+.

/*************************************************************************
 * Function Name: USB_HwInit
 * Parameters: none
 *
 * Return: none
 *
 * Description: Init USB
 *
 *************************************************************************/
void USB_HwInit(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

  // Reset USB Engine
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_USB,ENABLE);
  // Init USB Clock
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB,ENABLE);
  // Release reset USB Engine
  RCC_APB1PeriphResetCmd(RCC_APB1Periph_USB,DISABLE);
  // Enable 48MHz clock
  RCC_USBCLKConfig(USB_DIVIDER);

  // Force USB Reset & Disable USB interrupts
  USB_CNTR = 1;

  // GPIO assign to the USB engine
  RCC_APB2PeriphResetCmd( RCC_APB2Periph_GPIOA
                         | RCC_APB2Periph_GPIOC
                         | RCC_APB2Periph_AFIO, DISABLE);
  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA
                         | RCC_APB2Periph_GPIOC
                         | RCC_APB2Periph_AFIO, ENABLE);

    
  // CAN interact with USB
 GPIO_PinRemapConfig(GPIO_Remap1_CAN1,ENABLE); // xxx
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,DISABLE); // xxx

  // Configure PA11, PA12 as USB lines
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  // Disconnect device
  USB_ConnectRes(FALSE);

  // Init controls endpoints
  USB_HwReset();

  // Clear spurious pending interrupt
  USB_ISTR = 0;

  // USB interrupt connect to NVIC
#if USB_HIGH_PRIORITY_EVENT > 0
  NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = USB_INTR_HIGH_PRIORITY;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
#endif // USB_HIGH_PRIORITY_EVENT > 0

  NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = USB_INTR_LOW_PRIORITY;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

}