STM32F072C8 - Problema de comunicación USB

0

Estoy intentando usar el USB incorporado para implementar un dispositivo HID simple en STM32F072. Por supuesto, no está funcionando. Esta es mi primera experiencia con USB, por lo que necesitaba ayuda para descubrir qué podría estar yendo mal.

Estoy usando la biblioteca de dispositivos USB FS STM32F0x2xx y en este momento estoy probando con su ejemplo HID.

Cuando conecto el cable USB a mi dispositivo y computadora, no pasa nada. Ni siquiera "Dispositivo desconocido" o "Exclamación amarilla", lo que me lleva a creer que se está arruinando en la etapa de enumeración en sí.

Haciendo un volcado de USB con Wireshark muestra alguna transferencia de datos, que incluye muchos "paquetes mal formados".

Noestoysegurodeloquepodríaestarmal.Algunascosasquecreoquepuedenirmal...

  1. ¿NecesitoresistenciasdeterminaciónenlaslíneasDMyDP?NosegúnelmanualdereferenciaSTM32F072;nolosnecesitamos

  2. ¿Necesitounaresistenciadepull-upexternaenlalíneaDP?No,segúnelmanualdereferencia,F072tieneresistenciaspull-upincorporadasparaeso.

  3. Según la hoja de datos F072, hay una línea USB_NOE en el pin PA13 que he dejado desconectada. No estoy seguro, pero no creo que este pin deba estar conectado.

  4. En la biblioteca USB del STM32, en el archivo usb_bsp.c (donde se tratan todos los pines, etc.), no veo que los pines DP y DM se estén inicializando o configurando en sus funciones USB alternativas. Lo único que hacen es habilitar el reloj USB.

    anular USB_BSP_Init (USB_CORE_HANDLE * pdev) {       GPIO_InitTypeDef GPIO_InitStructure;

      #
      if defined USB_DEVICE_LOW_PWR_MGMT_SUPPORT
      EXTI_InitTypeDef EXTI_InitStructure;#
      endif
    
      /* Enable all GPIO clock */
      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOF, ENABLE);
    
      /* Configure all GPIOs in AN mode to disable current to flow into or out of GPIOs when in suspend mode  */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
      GPIO_Init(GPIOB, & GPIO_InitStructure);
      GPIO_Init(GPIOC, & GPIO_InitStructure);
      GPIO_Init(GPIOD, & GPIO_InitStructure);
      GPIO_Init(GPIOE, & GPIO_InitStructure);
      GPIO_Init(GPIOF, & GPIO_InitStructure);
    
      /* Disable all GPIO clock */
      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOF, DISABLE);
    
      /* Enable USB clock */
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
    
      #
      if defined USB_CLOCK_SOURCE_CRS
      /*For using CRS, you need to do the following:
      - Enable HSI48 (managed by the SystemInit() function at the application startup)
        - Select HSI48 as USB clock
        - Enable CRS clock
        - Set AUTOTRIMEN
        - Set CEN
        */
    
      /* Select HSI48 as USB clock */
      RCC_USBCLKConfig(RCC_USBCLK_HSI48);
    
      /* Configure the Clock Recovery System */
      CRS_Config();#
      else
      /* Configure PLL to be used as USB clock:
         - Enable HSE external clock (for this example the system is clocked by HSI48
             managed by the SystemInit() function at the application startup)
           - Enable PLL
           - Select PLL as USB clock */
      /* Enable HSE */
        RCC_HSEConfig(RCC_HSE_ON);
    
      /* Wait till HSE is ready */
      while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) {}
    
      /* Enable PLL */
      RCC_PLLCmd(ENABLE);
    
      /* Wait till PLL is ready */
      while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {}
    
      /* Configure USBCLK from PLL clock */
      RCC_USBCLKConfig(RCC_USBCLK_PLLCLK);
    
      #
      endif /*USB_CLOCK_SOURCE_CRS */
    
      /*JoyStick IOs Configuration*/
      //  STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_GPIO);
      //  STM_EVAL_PBInit(BUTTON_LEFT, BUTTON_MODE_GPIO);
      //  STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_GPIO);
      //  STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_GPIO);
    
      /* Configure the Tamper button in EXTI mode */
      //  STM_EVAL_PBInit(BUTTON_TAMPER, Mode_EXTI);
    
      /* Clear the Tamper EXTI line pending bit */
      //  EXTI_ClearITPendingBit(TAMPER_BUTTON_EXTI_LINE);
    
      # ifdef USB_DEVICE_LOW_PWR_MGMT_SUPPORT
    
      /* Enable the PWR clock */
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
    
      /* EXTI line 18 is connected to the USB Wakeup from suspend event   */
      EXTI_ClearITPendingBit(EXTI_Line18);
      EXTI_InitStructure.EXTI_Line = EXTI_Line18;
      /*Must Configure the EXTI Line 18 to be sensitive to rising edge*/
      EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
      EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
      EXTI_InitStructure.EXTI_LineCmd = ENABLE;
      EXTI_Init( & EXTI_InitStructure);#
      endif /*USB_DEVICE_LOW_PWR_MGMT_SUPPORT */
    }
    

Apreciaría si alguien pudiera sugerir cuál podría ser el problema aquí.

    
pregunta Ankit

1 respuesta

-1

Es necesario establecer los pines a sus funciones alternativas. Vea los ejemplos a continuación (esto es para la serie stm32f7, por lo que probablemente no pueda usarlo directamente):

Dispositivo de velocidad completa

void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
{
    GPIO_InitTypeDef GPIO_Init;

    /* Configure USB FS GPIOs */
    __HAL_RCC_GPIOA_CLK_ENABLE();

    GPIO_Init.Mode = GPIO_MODE_AF_PP;
    GPIO_Init.Pull = GPIO_NOPULL;
    GPIO_Init.Speed = GPIO_SPEED_HIGH;
    GPIO_Init.Alternate = GPIO_AF10_OTG_FS;

    /* Configure DM DP Pins */
    GPIO_Init.Pin = GPIO_PIN_11 | /* OTG_FS_DM */
                    GPIO_PIN_12;  /* OTG_FS_DP */
    HAL_GPIO_Init(GPIOA, &GPIO_Init); 

    /* Enable USB FS Clock */
    __HAL_RCC_USB_OTG_FS_CLK_ENABLE();

    /* Set USBFS Interrupt priority */
    HAL_NVIC_SetPriority(OTG_FS_IRQn, 6, 0);

    /* Enable USBFS Interrupt */
    HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
}

Host de alta velocidad

void  HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)
{
    GPIO_InitTypeDef GPIO_Init;

    /* Enable GPIOs clock */
    __HAL_RCC_GPIOB_CLK_ENABLE();

    GPIO_Init.Mode = GPIO_MODE_AF_PP;
    GPIO_Init.Pull = GPIO_PULLUP;
    GPIO_Init.Speed = GPIO_SPEED_HIGH;
    GPIO_Init.Alternate = GPIO_AF12_OTG_HS_FS;

    GPIO_Init.Pin = GPIO_PIN_14 |    /* OTG_HS_DM */
                    GPIO_PIN_15;     /* OTG_HS_DP */
    HAL_GPIO_Init(GPIOB, &GPIO_Init);

    /* Enable USB HS Clocks */
    __HAL_RCC_USB_OTG_HS_CLK_ENABLE();

    /* Set USBHS Interrupt to the lowest priority */
    HAL_NVIC_SetPriority(OTG_HS_IRQn, 5, 0);

    /* Enable USBHS Interrupt */
    HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
}

Normalmente, se llamará a las funciones anteriores al inicializar la función usb con:

HAL_PCD_Init(&hpcd); // USBH_HandleTypeDef
HAL_HCD_Init(&hhcd); // USBD_HandleTypeDef
    
respondido por el staringlizard

Lea otras preguntas en las etiquetas