/* * Code for initalizing USB CDC via the SYSINIT mechanism. */ #include #include #include #include static void usb_cdc_init(const void *foo) { /* * 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); MX_USB_DEVICE_Init(); } extern PCD_HandleTypeDef hpcd_USB_FS; void USB_LP_IRQHandler(void) { HAL_PCD_IRQHandler(&hpcd_USB_FS); } SYSINIT(usb_cdc_init, SI_SUB_CONSOLE, SI_ORDER_FIRST, usb_cdc_init, NULL);