cancel
Showing results for 
Search instead for 
Did you mean: 

USB HID device on STM32G473 shows error (USB_ISTR_ERR) after reset in usb irq handler

gjaczet
Associate II

I am trying to make a USB HID self powered device with STM32G473 without VBUS. I understand that I will require VBUS sensing on reconnection but even when I have already connected the USB then power up my device I only get reset request from host after that it only raises the USB error interrupt. where could be the problem? Is VBUS sensing required in this case as well ?

This is my clock configuration:

RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  /** Configure the main internal regulator output voltage 
  */
  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
  /** Initializes the CPU, AHB and APB busses clocks 
  */
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV2;
  RCC_OscInitStruct.PLL.PLLN = 12;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV16;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the peripherals clocks 
  */
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USB;
  PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;//RCC_USBCLKSOURCE_PLL;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    Error_Handler();
  }
5 REPLIES 5
gjaczet
Associate II

I have generated the entire code with cube mx with HSE clock and PLL for USB. The direct code from cube mx is not working. is vbus sensing required even if USB port is connected to the pc even before my board is powered up? Does vbus serve any other purpose on the host side? Kindly help

also the usb port is not detected by cube programmer in DFU mode. but uart programming is working

gjaczet
Associate II

on further observing I get resume, suspend and reset callback but instead of SOF callback I get only usb error callback

@gjaczet, did you ever figure out what was happening?  I am encountering a similar issue, but when trying to create a VCP interface.  I did see the errata entry that talked about the USB peripheral prematurely causing a suspend event.  Possibly this is what you figured out was the problem?  If so, perhaps you could share your workaround?

 

ST Support,

It appears that the current CubeMX USB stack does not handle masking the SUSP interrupt that was discussed in the errata?  Please advise.  Perhaps you could generate a stock CubeMX VCP or HID usb device project for the appropriate dev board and verify that it can enumerates correctly on a Windows 11 pc?

@gjaczet / ST Support:

Never mind, I had an issue where I accidentally kept interrupts disabled for longer than desired.  Once this was corrected, USB VCP appears to be working fine.