Skip to content

Commit

Permalink
ADD: force USB re-enumeration on device reset
Browse files Browse the repository at this point in the history
  • Loading branch information
r2axz committed Aug 1, 2021
1 parent 13f7657 commit 591550d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions usb_io.c
Expand Up @@ -53,6 +53,16 @@ void usb_io_reset() {
}

void usb_io_init() {
/* Force USB re-enumeration */
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
GPIOA->CRH &= ~GPIO_CRH_CNF12;
GPIOA->CRH |= GPIO_CRH_MODE12_1;
for (int i=0; i<0xFFFF; i++) {
__NOP();
}
GPIOA->CRH &= ~GPIO_CRH_MODE12;
GPIOA->CRH |= GPIO_CRH_CNF12_0;
/* Initialize USB */
NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn);
if (SystemCoreClock != RCC_MAX_FREQUENCY) {
RCC->CFGR |= RCC_CFGR_USBPRE;
Expand Down

0 comments on commit 591550d

Please sign in to comment.