USB: fix disconnect

This commit is contained in:
King Kévin 2020-01-03 20:16:02 +01:00
parent 3242c6ba5c
commit c7d0244f72
2 changed files with 10 additions and 4 deletions

View File

@ -262,13 +262,16 @@ static void usb_disconnect(void)
// enable USB D+ pull-up
rcc_periph_clock_enable(RCC_GPIOB);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
gpio_set(GPIOB, GPIO6);
gpio_clear(GPIOB, GPIO6);
#endif
// pull USB D+ low for a short while
rcc_periph_clock_enable(RCC_GPIOA);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
gpio_clear(GPIOA, GPIO12);
sleep_ms(50); // USB disconnected must be at least 10 ms long, at most 100 ms
// USB disconnected must be at least 10 ms long, at most 100 ms
for (uint32_t i = 0; i < 0x2000; i++) {
__asm__("nop");
}
}
/** DFU detach (disconnect USB and perform core reset)

View File

@ -143,13 +143,16 @@ static void usb_disconnect(void)
// enable USB D+ pull-up
rcc_periph_clock_enable(RCC_GPIOB);
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO6);
gpio_set(GPIOB, GPIO6);
gpio_clear(GPIOB, GPIO6);
#endif
// pull USB D+ low for a short while
rcc_periph_clock_enable(RCC_GPIOA);
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
gpio_clear(GPIOA, GPIO12);
sleep_ms(50); // USB disconnected must be at least 10 ms long, at most 100 ms
// USB disconnected must be at least 10 ms long, at most 100 ms
for (uint32_t i = 0; i < 0x2000; i++) {
__asm__("nop");
}
}
/** flash downloaded data block