mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-14 04:18:56 +00:00
add board_reset_to_bootloader(), try to implement that for ch32v203 but not working yet
This commit is contained in:
parent
13dedddd19
commit
8d5dbb9577
@ -119,6 +119,26 @@ static void cdc_task(void) {
|
||||
}
|
||||
}
|
||||
|
||||
// Invoked when cdc when line state changed e.g connected/disconnected
|
||||
// Use to reset to DFU when disconnect with 1200 bps
|
||||
void tud_cdc_line_state_cb(uint8_t instance, bool dtr, bool rts) {
|
||||
(void)rts;
|
||||
|
||||
// DTR = false is counted as disconnected
|
||||
if (!dtr) {
|
||||
// touch1200 only with first CDC instance (Serial)
|
||||
if (instance == 0) {
|
||||
cdc_line_coding_t coding;
|
||||
tud_cdc_get_line_coding(&coding);
|
||||
if (coding.bit_rate == 1200) {
|
||||
if (board_reset_to_bootloader) {
|
||||
board_reset_to_bootloader();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// BLINKING TASK
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -72,6 +72,9 @@ void board_init(void);
|
||||
// Init board after tinyusb is initialized
|
||||
void board_init_after_tusb(void) TU_ATTR_WEAK;
|
||||
|
||||
// Jump to bootloader
|
||||
void board_reset_to_bootloader(void) TU_ATTR_WEAK;
|
||||
|
||||
// Turn LED on or off
|
||||
void board_led_write(bool state);
|
||||
|
||||
|
@ -6,7 +6,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define LED_PORT GPIOA
|
||||
#define LED_PIN GPIO_Pin_15
|
||||
#define LED_PIN GPIO_Pin_0
|
||||
#define LED_STATE_ON 0
|
||||
|
||||
#define UART_DEV USART1
|
||||
|
@ -7,7 +7,7 @@ extern "C" {
|
||||
|
||||
#define LED_PORT GPIOA
|
||||
#define LED_PIN GPIO_Pin_0
|
||||
#define LED_STATE_ON 1
|
||||
#define LED_STATE_ON 0
|
||||
|
||||
#define UART_DEV USART2
|
||||
#define UART_CLOCK_EN() RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE)
|
||||
|
@ -139,6 +139,34 @@ void board_init(void) {
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void board_reset_to_bootloader(void) {
|
||||
board_led_write(true);
|
||||
|
||||
__disable_irq();
|
||||
|
||||
#if CFG_TUD_ENABLED
|
||||
tud_deinit(0);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USB, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USB, DISABLE);
|
||||
#endif
|
||||
|
||||
SysTick->CTLR = 0;
|
||||
for (int i = WWDG_IRQn; i< DMA1_Channel8_IRQn; i++) {
|
||||
NVIC_DisableIRQ(i);
|
||||
}
|
||||
|
||||
__enable_irq();
|
||||
|
||||
// define function pointer to BOOT ROM address
|
||||
void (*bootloader_entry)(void) = (void (*)(void))0x1FFF8000;
|
||||
|
||||
bootloader_entry();
|
||||
|
||||
board_led_write(false);
|
||||
|
||||
// while(1) { }
|
||||
}
|
||||
|
||||
void board_led_write(bool state) {
|
||||
GPIO_WriteBit(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
|
||||
}
|
||||
@ -166,3 +194,7 @@ int board_uart_write(void const *buf, int len) {
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Neopixel
|
||||
//--------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user