Use case: STM32F103C8T6, STM32CubeIDE
USB_DEVICE/App/usb_device.c (mostly copy-pasted from MX_GPIO_Init():
...
void MX_USB_DEVICE_Init(void)
{
  /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
  /* Rendering hardware reset harmless (no need to replug USB cable): */
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOA_CLK_ENABLE();
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
  /*Configure GPIO pin : PA12, a.k.a. USB_DP */
  GPIO_InitStruct.Pin = GPIO_PIN_12;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  HAL_Delay(5);
  /* Hardware reset rendered harmless! */
  /* USER CODE END USB_DEVICE_Init_PreTreatment */
  ...
}
...
Inspired by a blog post about the not quite right (10k instead of 1.5k) R10 on certain noname Blue Pills.