/* * Code for reseting USB via the SYSINIT mechanism. * * Note: This works for both Node151 and BluePill (F1) as PA12 is * USB_DP on both. */ #include #include #include static void usb_reset(void) { /* * pretend that the device was newly plugged in * see: https://stackoverflow.com/a/67336535 */ GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure = (GPIO_InitTypeDef){ .Pin = GPIO_PIN_11|GPIO_PIN_12, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, }; __HAL_RCC_GPIOA_CLK_ENABLE(); HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); //HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); HAL_Delay(10); } SYSINIT_VF(usb_reset, SI_SUB_USB, SI_ORDER_FIRST, usb_reset);