add board_reset_to_bootloader(), try to implement that for ch32v203 but not working yet

This commit is contained in:
hathach
2024-07-05 15:40:02 +07:00
parent 13dedddd19
commit 8d5dbb9577
5 changed files with 57 additions and 2 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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)

View File

@@ -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
//--------------------------------------------------------------------