fix: 'reset dfu' on the tinySA ULTRA

- 'reset dfu' and enter_dfu() are now also built for the tinySA4 (the
  DFU menu stays tinySA3 only); the reply is sent before the reset
- F303 __early_init(): the jump to the system bootloader failed and the
  bootloader reset the MCU. crt0 calls __early_init() on the process
  stack with interrupts disabled, so switch to the main stack
  (CONTROL = 0) and enable interrupts before the jump, as in the F072
  board.c. Also enable the SYSCFG clock for the system memory remap and
  replace the logical || that made it write 1 to SYSCFG_CFGR1

Tested on HW V0.4.5.1: 'reset dfu' enters the STM32 BOOTLOADER and
dfu-util can flash it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
copilot/add-multi-platform-rf-scan-exports
erikkaashoek 1 month ago
parent d32b6ca410
commit b6699cfdb9

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

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

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

Loading…
Cancel
Save

Powered by TurnKey Linux.