cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] STM32F4 USB works intermittently

Zang Man
Associate III

0690X00000BvWGOQA3.pngI'm using an STM32F411RET6 MCU to make a keyboard. Attached is the full schematic. Using CubeMX to generate the USB code. I'm a hobby-ist and I apologize in advance if there's a very basic issue that I've overlooked.

The problem is it works sometimes but most times it doesn't. I get the error in Windows "USB Device has malfunctioned". Looking in USB Device Viewer, i see the following error:

[Port2] FailedEnumeration :  Unknown USB Device (Device Descriptor Request Failed)
 
 
Is Port User Connectable:         yes
Is Port Debug Capable:            no
Companion Port Number:            0
Companion Hub Symbolic Link Name: 
Protocols Supported:
 USB 1.1:                         yes
 USB 2.0:                         yes
 USB 3.0:                         no
 
       ---===>Device Information<===---
 
ConnectionStatus:                  FailedEnumeration
Current Config Value:              0x00  -> Device Bus Speed: Low
Device Address:                    0x00
Open Pipes:                           0
*!*ERROR:  No open pipes!
 
          ===>Device Descriptor<===
*!*ERROR:  bLength of 0 incorrect, should be 18
bLength:                           0x00
bDescriptorType:                   0x00
bcdUSB:                          0x0000
bDeviceClass:                      0x00
*!*ERROR:  Device enumeration failure

A few points about the setup:

  • The MCU has an internal pull-up for USB. I assume I shouldn't have to do anything special to enable it i.e. it is automatically handled when I have USB enabled. Is that correct? Or is it better to add an external pull up for USB?

  • I'm using an 8MHz external crystal. The configuration code is below. Is there anything wrong with the way I'm doing it? This has been generated by CubeMX after resolving clock errors. Code pasted below
void SystemClock_Config(void) {
  RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
  RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
 
  /** Configure the main internal regulator output voltage
   */
  __HAL_RCC_PWR_CLK_ENABLE()
  ;
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  /** Initializes the CPU, AHB and APB busses clocks
   */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 4;
  RCC_OscInitStruct.PLL.PLLN = 96;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV6;
  RCC_OscInitStruct.PLL.PLLQ = 4;
  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_DIV2;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) {
    Error_Handler();
  }
}

Any suggestions will be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Zang Man
Associate III

Okay found the issue. The problem is with the location of the standoff. It is too close to the USB connector. So every time I tighten the screws the leads either come out or get shorted and it stops working.

I re-soldered the usb connector leads and made sure to not tighten the screws and just let them gently stop in place. I'll fix this in the next design. Thanks for your help Barry! 🙂

0690X00000BvY4jQAF.png

View solution in original post

4 REPLIES 4
Zang Man
Associate III

A follow up question - I just noticed that I'm completely ignoring the VBUS pin (PA9). But I found this attached image which says VBUS needs to be connected to the 5V from the connector. Does a HID qualify as a peripheral-only connection?

0690X00000BvWN5QAN.png

Barry Richards
Associate II

I worked on a USB keyboard emulator and also had very intermittent results, mostly not working.

The design was on a 2 layer board and the power trace to the VDD pin that was closest to the USB + and - signals was very far from the power source. I increased the capacitor size on that VDD pin and it started working without any problems.

Probably not your problem but it might be worth trying a larger cap close to the USB signals.

Thanks for the suggestion! I'll give that a try. Right now I have 400nF close to the pins on the MCU, but really far from the USB connector. I'll try bumping it up to 1uF and see if that helps. I'm also wondering if there's some loose connection on the micro-usb connector, will try re-soldering the leads again.

Zang Man
Associate III

Okay found the issue. The problem is with the location of the standoff. It is too close to the USB connector. So every time I tighten the screws the leads either come out or get shorted and it stops working.

I re-soldered the usb connector leads and made sure to not tighten the screws and just let them gently stop in place. I'll fix this in the next design. Thanks for your help Barry! 🙂

0690X00000BvY4jQAF.png