From 2d1b2fcfbda63b9bf3594d22da1ddf17fc76ff3c Mon Sep 17 00:00:00 2001 From: cho45 Date: Thu, 5 Sep 2019 20:58:10 +0900 Subject: [PATCH 1/6] fix backspace rendering --- ui.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui.c b/ui.c index 9e7f090..976d04f 100644 --- a/ui.c +++ b/ui.c @@ -1119,6 +1119,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 From 39b7fdf95eabd7aa5ea8ed25c7fbb2080c32796f Mon Sep 17 00:00:00 2001 From: cho45 Date: Thu, 5 Sep 2019 22:14:44 +0900 Subject: [PATCH 2/6] append version info screen to UI --- ili9341.c | 28 ++++++++++++++++++++++++++++ main.c | 3 --- nanovna.h | 2 ++ ui.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) 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 7947fc6..a381155 100644 --- a/main.c +++ b/main.c @@ -390,8 +390,6 @@ static void cmd_capture(BaseSequentialStream *chp, int argc, char *argv[]) (void)argc; (void)argv; - chMtxLock(&mutex); - // pause sweep stop_the_world = TRUE; @@ -419,7 +417,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..6837ee4 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); diff --git a/ui.c b/ui.c index 9e7f090..a8fbed0 100644 --- a/ui.c +++ b/ui.c @@ -383,6 +383,36 @@ 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(); +} // type of menu item @@ -490,6 +520,11 @@ menu_config_cb(int item) menu_move_back(); ui_mode_normal(); break; + case 3: + show_version(); + redraw_frame(); + request_to_redraw_grid(); + draw_menu(); } } @@ -867,6 +902,7 @@ 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_CANCEL, S_LARROW" BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; From 496b41fa1c985c44922aaa1add1a4bda99a87608 Mon Sep 17 00:00:00 2001 From: TT Date: Fri, 6 Sep 2019 08:52:56 +0900 Subject: [PATCH 3/6] minor fix --- ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui.c b/ui.c index 6b78965..010c1db 100644 --- a/ui.c +++ b/ui.c @@ -403,7 +403,7 @@ show_version(void) 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("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); From 5e9756e4e0ef819c9ba5913d2cc3c48eb04fde4e Mon Sep 17 00:00:00 2001 From: cho45 Date: Fri, 6 Sep 2019 20:46:39 +0900 Subject: [PATCH 4/6] append `reset dfu` command and `CONFIG` -> `ENTER DFU` --- NANOVNA_STM32_F072/board.c | 11 +++++++++++ NANOVNA_STM32_F072/board.h | 5 +++++ main.c | 8 ++++++++ nanovna.h | 1 + ui.c | 19 +++++++++++++++++++ 5 files changed, 44 insertions(+) diff --git a/NANOVNA_STM32_F072/board.c b/NANOVNA_STM32_F072/board.c index bcf8f8a..5613c91 100644 --- a/NANOVNA_STM32_F072/board.c +++ b/NANOVNA_STM32_F072/board.c @@ -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(); } 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/main.c b/main.c index a381155..b10de07 100644 --- a/main.c +++ b/main.c @@ -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); diff --git a/nanovna.h b/nanovna.h index 6837ee4..4ddebe4 100644 --- a/nanovna.h +++ b/nanovna.h @@ -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 diff --git a/ui.c b/ui.c index 010c1db..f1d129d 100644 --- a/ui.c +++ b/ui.c @@ -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 { @@ -525,6 +541,8 @@ menu_config_cb(int item) redraw_frame(); request_to_redraw_grid(); draw_menu(); + case 4: + enter_dfu(); } } @@ -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 }; From 73e0c19e8e10d6bdfd29e7fd8e490b3580f23761 Mon Sep 17 00:00:00 2001 From: cho45 Date: Fri, 6 Sep 2019 21:04:47 +0900 Subject: [PATCH 5/6] move `enter dfu` to submenu of config --- NANOVNA_STM32_F072/board.c | 4 ++++ ui.c | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/NANOVNA_STM32_F072/board.c b/NANOVNA_STM32_F072/board.c index 5613c91..f7d2f0e 100644 --- a/NANOVNA_STM32_F072/board.c +++ b/NANOVNA_STM32_F072/board.c @@ -73,12 +73,16 @@ 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(); diff --git a/ui.c b/ui.c index f1d129d..0012db5 100644 --- a/ui.c +++ b/ui.c @@ -421,11 +421,12 @@ enter_dfu(void) 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, please reset device yourself.", 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 + // see __early_init in ./NANOVNA_STM32_F072/board.c *((unsigned long *)BOOT_FROM_SYTEM_MEMORY_MAGIC_ADDRESS) = BOOT_FROM_SYTEM_MEMORY_MAGIC; NVIC_SystemReset(); } @@ -541,7 +542,14 @@ menu_config_cb(int item) redraw_frame(); request_to_redraw_grid(); draw_menu(); - case 4: + } +} + +static void +menu_dfu_cb(int item) +{ + switch (item) { + case 0: enter_dfu(); } } @@ -916,12 +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_CALLBACK, "ENTER DFU", menu_config_cb }, + { MT_SUBMENU, S_RARROW"DFU", menu_dfu }, { MT_CANCEL, S_LARROW" BACK", NULL }, { MT_NONE, NULL, NULL } // sentinel }; From ec8c53bde3f05d2541d6ffec69f030711162468c Mon Sep 17 00:00:00 2001 From: TT Date: Sat, 7 Sep 2019 09:08:43 +0900 Subject: [PATCH 6/6] add target dfu in Makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) 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