Skip to content

Commit

Permalink
Merge pull request #41 from r2axz/r2axz-re-enumerate-on-reset
Browse files Browse the repository at this point in the history
Force USB re-enumeration on device reset
  • Loading branch information
r2axz authored Aug 24, 2021
2 parents 13f7657 + 7e30bd0 commit a1b6948
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ cppcheck: $(SRCS)

.PHONY: flash
flash: $(TARGET).hex
$(STFLASH) --format ihex write $<
$(STFLASH) --reset --format ihex write $<

.PHONY: size
size: $(TARGET).elf
Expand Down
10 changes: 10 additions & 0 deletions usb_io.c
Original file line number Diff line number Diff line change
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 a1b6948

Please sign in to comment.