diff --git a/NANOVNA_STM32_F303/board.c b/NANOVNA_STM32_F303/board.c index 6ca71af..677c9b7 100644 --- a/NANOVNA_STM32_F303/board.c +++ b/NANOVNA_STM32_F303/board.c @@ -114,11 +114,15 @@ void __early_init(void) { bootloader(); while(1); #else - __disable_irq(); - uint32_t foo = SYSCFG->CFGR1; - foo = (foo & ~SYSCFG_CFGR1_MEM_MODE) || SYSCFG_CFGR1_MEM_MODE_0; - SYSCFG->CFGR1 = foo; + // Map the system memory at 0 so interrupts use the bootloader vectors (SYSCFG needs its clock) + RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; + SYSCFG->CFGR1 = (SYSCFG->CFGR1 & ~SYSCFG_CFGR1_MEM_MODE) | SYSCFG_CFGR1_MEM_MODE_0; __DSB(); + __ISB(); + // The bootloader needs interrupts, crt0 disabled them (as in the F072 board.c) + __enable_irq(); + // and the main stack, crt0 switched to the process stack + __set_CONTROL(0); __ISB(); __set_MSP(*((uint32_t *)(STM32F303xC_SYSTEM_MEMORY))); diff --git a/main.c b/main.c index fe6eb85..97a438e 100644 --- a/main.c +++ b/main.c @@ -578,15 +578,14 @@ VNA_SHELL_FUNCTION(cmd_reset) { (void)argc; (void)argv; -#ifndef TINYSA4 if (argc == 1) { if (get_str_index(argv[0], "dfu") == 0) { shell_printf("Performing reset to DFU mode\r\n"); + chThdSleepMilliseconds(100); // let USB send the text enter_dfu(); return; } } -#endif shell_printf("Performing reset\r\n"); rccEnableWWDG(FALSE); WWDG->CFR = 0x60; diff --git a/ui.c b/ui.c index 63744a0..979a164 100644 --- a/ui.c +++ b/ui.c @@ -750,22 +750,21 @@ extern const char *states[]; lcd_set_font(FONT_SMALL); } -#ifdef __HAS_DFU__ +// Also used by "reset dfu" on the tinySA4, which has no DFU menu (__HAS_DFU__) void enter_dfu(void) { int x = 5, y = 5; ili9341_set_foreground(LCD_FG_COLOR); ili9341_set_background(LCD_BG_COLOR); - // leave a last message + // leave a last message ili9341_clear_screen(); ili9341_drawstring_7x13("DFU: Device Firmware Update Mode\n" "To exit DFU mode, please reset device yourself.", x, y); - // see __early_init in ./NANOVNA_STM32_F072/board.c + // see __early_init in ./NANOVNA_STM32_F072/board.c and ./NANOVNA_STM32_F303/board.c *((unsigned long *)BOOT_FROM_SYTEM_MEMORY_MAGIC_ADDRESS) = BOOT_FROM_SYTEM_MEMORY_MAGIC; NVIC_SystemReset(); } -#endif static void select_lever_mode(int mode)