diff --git a/Makefile b/Makefile index 9c597a3..39a09f3 100644 --- a/Makefile +++ b/Makefile @@ -228,6 +228,9 @@ include $(RULESPATH)/rules.mk flash: build/ch.bin dfu-util -d 0483:df11 -a 0 -s 0x08000000:leave -D build/ch.bin +dfu: + printf "reset dfu\r" >/dev/cu.usbmodem401 + TAGS: Makefile @etags *.[ch] NANOVNA_STM32_F072/*.[ch] $(shell find ChibiOS/os/hal/ports/STM32/STM32F0xx ChibiOS/os -name \*.\[ch\] -print) @ls -l TAGS diff --git a/NANOVNA_STM32_F072/board.c b/NANOVNA_STM32_F072/board.c index bcf8f8a..f7d2f0e 100644 --- a/NANOVNA_STM32_F072/board.c +++ b/NANOVNA_STM32_F072/board.c @@ -70,6 +70,21 @@ 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(); + // reset magic bytes + *((unsigned long *)BOOT_FROM_SYTEM_MEMORY_MAGIC_ADDRESS) = 0; + // remap memory. unneeded for F072? + // RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; + // SYSCFG->CFGR1 = 0x01; + // set msp for system memory + __set_MSP(SYSTEM_BOOT_MSP); + // jump to system memory + ( (void (*)(void)) (*((uint32_t *)(STM32F072xB_SYSTEM_MEMORY+4))) )(); + while (1); + } + //si5351_setup(); stm32_clock_init(); } diff --git a/NANOVNA_STM32_F072/board.h b/NANOVNA_STM32_F072/board.h index 5c9e0e4..7ab4c29 100644 --- a/NANOVNA_STM32_F072/board.h +++ b/NANOVNA_STM32_F072/board.h @@ -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 */ diff --git a/ili9341.c b/ili9341.c index 6fbb2c4..e42d6de 100644 --- a/ili9341.c +++ b/ili9341.c @@ -360,6 +360,34 @@ ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg) } } +void +ili9341_drawchar_size(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg, uint8_t size) +{ + uint16_t *buf = spi_buffer; + uint16_t bits; + int c, r; + for(c = 0; c < 7*size; c++) { + bits = x5x7_bits[(ch * 7) + (c / size)]; + for (r = 0; r < 5*size; r++) { + *buf++ = (0x8000 & bits) ? fg : bg; + if (r % size == (size-1)) { + bits <<= 1; + } + } + } + ili9341_bulk(x, y, 5*size, 7*size); +} + +void +ili9341_drawstring_size(const char *str, int x, int y, uint16_t fg, uint16_t bg, uint8_t size) +{ + while (*str) { + ili9341_drawchar_size(*str, x, y, fg, bg, size); + x += 5 * size; + str++; + } +} + #define SWAP(x,y) do { int z=x; x = y; y = z; } while(0) void diff --git a/main.c b/main.c index 6312d04..06ef386 100644 --- a/main.c +++ b/main.c @@ -130,6 +130,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); @@ -400,8 +408,6 @@ static void cmd_capture(BaseSequentialStream *chp, int argc, char *argv[]) (void)argc; (void)argv; - chMtxLock(&mutex); - // pause sweep stop_the_world = TRUE; @@ -429,7 +435,6 @@ static void cmd_capture(BaseSequentialStream *chp, int argc, char *argv[]) //*/ stop_the_world = FALSE; - chMtxUnlock(&mutex); } #if 0 diff --git a/nanovna.h b/nanovna.h index ba5a947..4ddebe4 100644 --- a/nanovna.h +++ b/nanovna.h @@ -254,6 +254,8 @@ void ili9341_bulk(int x, int y, int w, int h); void ili9341_fill(int x, int y, int w, int h, int color); void ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg); void ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg); +void ili9341_drawchar_size(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg, uint8_t size); +void ili9341_drawstring_size(const char *str, int x, int y, uint16_t fg, uint16_t bg, uint8_t size); void ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg); void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t* out); void ili9341_read_memory_continue(int len, uint16_t* out); @@ -337,6 +339,7 @@ void handle_touch_interrupt(void); void touch_cal_exec(void); void touch_draw_test(void); +void enter_dfu(void); /* * adc.c diff --git a/ui.c b/ui.c index 9e7f090..0012db5 100644 --- a/ui.c +++ b/ui.c @@ -383,6 +383,53 @@ touch_position(int *x, int *y) } +void +show_version(void) +{ + int status; + int x = 5, y = 5; + int i; + + adc_stop(ADC1); + ili9341_fill(0, 0, 320, 240, 0); + + ili9341_drawstring_size(BOARD_NAME, x, y, 0xffff, 0x0000, 4); + y += 25; + + ili9341_drawstring_5x7("2016-2019 Copyright @edy555", x, y += 10, 0xffff, 0x0000); + ili9341_drawstring_5x7("Licensed under GPL. See: https://github.com/ttrftech/NanoVNA", x, y += 10, 0xffff, 0x0000); + ili9341_drawstring_5x7("Version: " VERSION, x, y += 10, 0xffff, 0x0000); + ili9341_drawstring_5x7("Build Time: " __DATE__ " - " __TIME__, x, y += 10, 0xffff, 0x0000); + y += 5; + ili9341_drawstring_5x7("Kernel: " CH_KERNEL_VERSION, x, y += 10, 0xffff, 0x0000); + ili9341_drawstring_5x7("Compiler: " PORT_COMPILER_NAME, x, y += 10, 0xffff, 0x0000); + ili9341_drawstring_5x7("Architecture: " PORT_ARCHITECTURE_NAME " Core Variant: " PORT_CORE_VARIANT_NAME, x, y += 10, 0xffff, 0x0000); + ili9341_drawstring_5x7("Port Info: " PORT_INFO, x, y += 10, 0xffff, 0x0000); + ili9341_drawstring_5x7("Platform: " PLATFORM_NAME, x, y += 10, 0xffff, 0x0000); + + do { + status = touch_check(); + } while(status != EVT_TOUCH_PRESSED); + + touch_start_watchdog(); +} + +void +enter_dfu(void) +{ + adc_stop(ADC1); + + int x = 5, y = 5; + + // leave a last message + 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 mode, 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 @@ -490,6 +537,20 @@ menu_config_cb(int item) menu_move_back(); ui_mode_normal(); break; + case 3: + show_version(); + redraw_frame(); + request_to_redraw_grid(); + draw_menu(); + } +} + +static void +menu_dfu_cb(int item) +{ + switch (item) { + case 0: + enter_dfu(); } } @@ -863,10 +924,18 @@ const menuitem_t menu_recall[] = { { MT_NONE, NULL, NULL } // sentinel }; +const menuitem_t menu_dfu[] = { + { MT_CALLBACK, "\2RESET AND\0ENTER DFU", menu_dfu_cb }, + { MT_CANCEL, S_LARROW"CANCEL", NULL }, + { MT_NONE, NULL, NULL } // sentinel +}; + const menuitem_t menu_config[] = { { MT_CALLBACK, "TOUCH CAL", menu_config_cb }, { MT_CALLBACK, "TOUCH TEST", menu_config_cb }, { MT_CALLBACK, "SAVE", menu_config_cb }, + { MT_CALLBACK, "VERSION", menu_config_cb }, + { MT_SUBMENU, S_RARROW"DFU", menu_dfu }, { MT_CANCEL, S_LARROW" BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; @@ -1119,6 +1188,9 @@ draw_numeric_input(const char *buf) x += xsim[i]; } } + if (i < 10) { + ili9341_fill(x, 208+4, 20*(10-i), 24, 0xffff); + } } static int