Skip to content

Commit

Permalink
append reset dfu command and CONFIG -> ENTER DFU
Browse files Browse the repository at this point in the history
  • Loading branch information
cho45 committed Sep 6, 2019
1 parent 496b41f commit 5e9756e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions NANOVNA_STM32_F072/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ const PALConfig pal_default_config = {
* any other initialization.
*/
void __early_init(void) {
if ( *((unsigned long *)BOOT_FROM_SYTEM_MEMORY_MAGIC_ADDRESS) == BOOT_FROM_SYTEM_MEMORY_MAGIC ) {
// require irq
__enable_irq();
*((unsigned long *)BOOT_FROM_SYTEM_MEMORY_MAGIC_ADDRESS) = 0;
// remap memory. unneeded for F072?
// RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
// SYSCFG->CFGR1 = 0x01;
__set_MSP(SYSTEM_BOOT_MSP);
( (void (*)(void)) (*((uint32_t *)(STM32F072xB_SYSTEM_MEMORY+4))) )();
}

//si5351_setup();
stm32_clock_init();
}
Expand Down
5 changes: 5 additions & 0 deletions NANOVNA_STM32_F072/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
*/
#define STM32F072xB

#define STM32F072xB_SYSTEM_MEMORY 0x1FFFC800
#define BOOT_FROM_SYTEM_MEMORY_MAGIC_ADDRESS 0x20003FF0
#define BOOT_FROM_SYTEM_MEMORY_MAGIC 0xDEADBEEF
#define SYSTEM_BOOT_MSP 0x20002250

/*
* IO pins assignments
*/
Expand Down
8 changes: 8 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ static void cmd_reset(BaseSequentialStream *chp, int argc, char *argv[])
(void)argc;
(void)argv;

if (argc == 1) {
if (strcmp(argv[0], "dfu") == 0) {
chprintf(chp, "Performing reset to DFU mode\r\n");
enter_dfu();
return;
}
}

chprintf(chp, "Performing reset\r\n");

rccEnableWWDG(FALSE);
Expand Down
1 change: 1 addition & 0 deletions nanovna.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ void handle_touch_interrupt(void);

void touch_cal_exec(void);
void touch_draw_test(void);
void enter_dfu(void);

/*
* adc.c
Expand Down
19 changes: 19 additions & 0 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,22 @@ show_version(void)
touch_start_watchdog();
}

void
enter_dfu(void)
{
adc_stop(ADC1);

int x = 5, y = 5;

ili9341_fill(0, 0, 320, 240, 0);
ili9341_drawstring_5x7("DFU: Device Firmware Update Mode", x, y += 10, 0xffff, 0x0000);
ili9341_drawstring_5x7("To exit DFU, please reset device yourself.", x, y += 10, 0xffff, 0x0000);

// see __early_init in NANOVNA_STM32_F072/board.c
*((unsigned long *)BOOT_FROM_SYTEM_MEMORY_MAGIC_ADDRESS) = BOOT_FROM_SYTEM_MEMORY_MAGIC;
NVIC_SystemReset();
}


// type of menu item
enum {
Expand Down Expand Up @@ -525,6 +541,8 @@ menu_config_cb(int item)
redraw_frame();
request_to_redraw_grid();
draw_menu();
case 4:
enter_dfu();
}
}

Expand Down Expand Up @@ -903,6 +921,7 @@ const menuitem_t menu_config[] = {
{ MT_CALLBACK, "TOUCH TEST", menu_config_cb },
{ MT_CALLBACK, "SAVE", menu_config_cb },
{ MT_CALLBACK, "VERSION", menu_config_cb },
{ MT_CALLBACK, "ENTER DFU", menu_config_cb },
{ MT_CANCEL, S_LARROW" BACK", NULL },
{ MT_NONE, NULL, NULL } // sentinel
};
Expand Down

0 comments on commit 5e9756e

Please sign in to comment.