AnsweredAssumed Answered

CubeMX bug: USB devices wrongly enable host power switch on Discovery boards

Question asked by Chinzei.Tsuneo on Jun 30, 2016
Latest reply on Oct 6, 2016 by STM32Cube-T
As the USB host power switch, most of Discovery boards mount STMPS2141STR, whose Enable pin is active low. For USB device-only applications, CubeMX generates bad initialization code, which wrongly enables this power switch, in MX_GPIO_Init() (main.c)

- 5V rail of the board is supplied to the USB connector, at the VBUS pin. It conflicts with host 5V supply.
- USB device application can't detect unplug from host.

Discovery boards
- STM32F4 Discovery
- 32F401C Discovery
- 32F411E Discovery
- 32F429I Discovery
- 32L476G Discovery
- 32F746G Discovery (OTG_FS port)
- maybe, more

CubeMX: v4.15.1 (latest)
CubeF7: v1.4.0
CubeF4: v1.12.0
CubeL4: v1.5.1

static void MX_GPIO_Init(void)
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_RESET);
    // <--- GPIO_PIN_SET, instead of GPIO_PIN_RESET, to disable the power switch