From 52d5dd46fccc0b353301c755836b0eaf91e0846b Mon Sep 17 00:00:00 2001 From: Gabriel Tenma White <48361922+gabriel-tenma-white@users.noreply.github.com> Date: Mon, 15 Feb 2021 21:55:05 +1100 Subject: [PATCH 1/5] Update README.md --- README.md | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7add08d..c04b504 100644 --- a/README.md +++ b/README.md @@ -78,20 +78,11 @@ git checkout -- gd32f303cc_with_bootloader_plus4.ld The GD32F303 processor does not support [USB DFU](https://www.usb.org/sites/default/files/DFU_1.1.pdf) mode like the STM32 chips do. Instead, a serial bootloader program is installed. Please do not attempt to use a standard USB DFU tool. -The [bootloader](bootloader/binary.bin) should be loaded at address 0x8000000, the start of the GD32F303 flash section. -To install the bootloader on a new GD32F303, you will need to use an [ST-Link](https://www.st.com/en/development-tools/st-link-v2.html) device, of which many inexpensive clones are available. -Some reports indicate that the NanoVNAv2 cannot be powered via the 3.2v supply from the ST-Link, but should be powered from its own battery. - -The NanoVNA V2 firmware is installed at address 0x8004000. -You can upload the firmware binary to that address using an ST-Link. +All V2 devices contain a USB serial bootloader, and you can upload the firmware through USB without needing extra hardware. -If your device already has a working serial bootloader, you can upload the firmware without needing extra hardware. +## Updating firmware using the USB serial bootloader -## Updating firmware using the serial bootloader - -If you have an intact bootloader already installed in your NanoVNAv2, there are several ways to update the firmware. - -You can update the firmware using (NanoVNAv2-QT](https://github.com/nanovna-v2/NanoVNA-QT). Restart your NanoVNA as described below and follow the instructions in NanoVNAv2-QT. +You can update the firmware using [NanoVNAv2-QT](https://github.com/nanovna-v2/NanoVNA-QT). Restart your NanoVNA as described below and follow the instructions in NanoVNAv2-QT. Otherwise, you can update your firmware using Python and the [bootload_firmware.py](bootload_firmware.py) script. Ensure you have Python version 3, and install [pyserial](https://github.com/pyserial/pyserial). @@ -129,3 +120,14 @@ Note that depending on your installation's *udev* rules, the new serial device i and it will not create the /dev/ttyACM0 port. After a while the modem manager will give up and you can access the port. If this is too much of a burden, you can add udev rules to block modem manager from trying to control this port. +## Updating the firmware using an ST-Link + +### WARNING: It is imperative to back up the entire flash memory of the GD32 before updating the firmware using this method. Some devices have factory calibration data stored between the bootloader and application. + +The NanoVNA V2 firmware is installed at address 0x8004000 (V2/V2Plus) and 0x8008000 (V2Plus4). +You can upload the firmware binary to that address using an ST-Link. + +The [bootloader](bootloader/binary.bin) is located at address 0x8000000, the start of the GD32F303 flash section. + +You can flash the firmware image using an [ST-Link](https://www.st.com/en/development-tools/st-link-v2.html) device, of which many inexpensive clones are available. +Some reports indicate that the NanoVNAv2 cannot be powered via the 3.2v supply from the ST-Link, but should be powered from its own battery. From 6208ee90807910963b93bc2c6b2fbca49028fc11 Mon Sep 17 00:00:00 2001 From: Gabriel Tenma White <48361922+gabriel-tenma-white@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:01:52 +1100 Subject: [PATCH 2/5] Update README.md --- README.md | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c04b504..874436e 100644 --- a/README.md +++ b/README.md @@ -82,20 +82,8 @@ All V2 devices contain a USB serial bootloader, and you can upload the firmware ## Updating firmware using the USB serial bootloader -You can update the firmware using [NanoVNAv2-QT](https://github.com/nanovna-v2/NanoVNA-QT). Restart your NanoVNA as described below and follow the instructions in NanoVNAv2-QT. - -Otherwise, you can update your firmware using Python and the [bootload_firmware.py](bootload_firmware.py) script. -Ensure you have Python version 3, and install [pyserial](https://github.com/pyserial/pyserial). - -On a Debian based system, you can get pyserial using: - -``` -sudo apt install python3-serial -``` - -## Updating the firmware - You must restart the device in BOOTLOAD mode: + ``` Switch the device off. Press and hold down the left button (the one closest to the Port 1 or the On/Off switch). @@ -104,7 +92,29 @@ Switch the device on (screen stays white), release the button. You will see a blank white screen. This indicates that it is waiting for new firmware. Check for the existence of the USB serial port device. This should be the device-special file /dev/ttyACM0 -On a *nix system, the current user probably needs to be part of the dialout group to allow access to ths device. +On a *nix system, the current user probably needs to be part of the dialout group to allow access to the device. + +Note that depending on your installation's *udev* rules, the new serial device initially appear as an Mobile Modem (3G/4G/etc) +and it will not create the /dev/ttyACM0 port. After a while the modem manager will give up and you can access the port. +If this is too much of a burden, you can add udev rules to block modem manager from trying to control this port. + + +Once the device is in BOOTLOAD mode, you can update the firmware using either [NanoVNA-QT](https://github.com/nanovna-v2/NanoVNA-QT) or the [bootload_firmware.py](bootload_firmware.py) Python script. + + + +## Upload firmware using NanoVNA-QT + +Select the serial port device /dev/ttyACM0 under the Device menu in NanoVNA-QT. A dialog will appear asking asking if you would like to flash a new firmware. Click yes, and select the firmware .bin file to flash. + + +### Upload firmware using bootload_firmware.py +Ensure you have Python version 3, and install [pyserial](https://github.com/pyserial/pyserial). + +On a Debian based system, you can get pyserial using: +``` +sudo apt install python3-serial +``` Flashing can be done by running: ``` @@ -116,9 +126,6 @@ On some systems you may need to explicitly invoke python3 instead: python3 bootload_firmware.py -f binary.bin ``` -Note that depending on your installation's *udev* rules, the new serial device initially appear as an Mobile Modem (3G/4G/etc) -and it will not create the /dev/ttyACM0 port. After a while the modem manager will give up and you can access the port. -If this is too much of a burden, you can add udev rules to block modem manager from trying to control this port. ## Updating the firmware using an ST-Link From d8585258568c081ac14b1e1d7477d1ea83321cc9 Mon Sep 17 00:00:00 2001 From: Gabriel Tenma White <48361922+gabriel-tenma-white@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:02:26 +1100 Subject: [PATCH 3/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 874436e..472b2b5 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Once the device is in BOOTLOAD mode, you can update the firmware using either [N -## Upload firmware using NanoVNA-QT +### Upload firmware using NanoVNA-QT Select the serial port device /dev/ttyACM0 under the Device menu in NanoVNA-QT. A dialog will appear asking asking if you would like to flash a new firmware. Click yes, and select the firmware .bin file to flash. From 0ed5bae973fadb67370e3fc4630c7567429bca9d Mon Sep 17 00:00:00 2001 From: Gabriel Tenma White <48361922+gabriel-tenma-white@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:04:44 +1100 Subject: [PATCH 4/5] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 472b2b5..245171a 100644 --- a/README.md +++ b/README.md @@ -102,13 +102,12 @@ If this is too much of a burden, you can add udev rules to block modem manager f Once the device is in BOOTLOAD mode, you can update the firmware using either [NanoVNA-QT](https://github.com/nanovna-v2/NanoVNA-QT) or the [bootload_firmware.py](bootload_firmware.py) Python script. - -### Upload firmware using NanoVNA-QT +#### Option 1: Upload firmware using NanoVNA-QT Select the serial port device /dev/ttyACM0 under the Device menu in NanoVNA-QT. A dialog will appear asking asking if you would like to flash a new firmware. Click yes, and select the firmware .bin file to flash. -### Upload firmware using bootload_firmware.py +#### Option 2: Upload firmware using bootload_firmware.py Ensure you have Python version 3, and install [pyserial](https://github.com/pyserial/pyserial). On a Debian based system, you can get pyserial using: From e9d2238ac1e9722e5b4f451a4faded0d469e14df Mon Sep 17 00:00:00 2001 From: OwO Date: Mon, 15 Feb 2021 12:09:42 +0000 Subject: [PATCH 5/5] fix build errors and averaging bugs --- README.md | 4 ++-- main2.cpp | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 245171a..8547b96 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ cd NanoVNA-V2-firmware Now you can build the firmware by running make in the firmware sources directory: ``` cd NanoVNA-V2-firmware -make BOARDNAME=board_v2_2 EXTRA_CFLAGS="-DSWEEP_POINTS_MAX=201 -DSAVEAREA_MAX=7" +make -j4 BOARDNAME=board_v2_plus EXTRA_CFLAGS="-DSWEEP_POINTS_MAX=201 -DSAVEAREA_MAX=7" LDSCRIPT=./gd32f303cc_with_bootloader.ld ``` Note that `SWEEP_POINTS_MAX` and `SAVEAREA_MAX` can be customized depending on hardware target. Since Plus4 ECAL is no longer needed, and the extra RAM can be used to increase `SWEEP_POINTS_MAX` to 301 points (warning: experimental! there may not be enough stack space if ram usage is near full). @@ -64,7 +64,7 @@ Since Plus4 ECAL is no longer needed, and the extra RAM can be used to increase For Plus4, a different linker script and display driver needs to be used. The build command line for the Plus4 is: ``` -make BOARDNAME=board_v2_plus4 EXTRA_CFLAGS="-DSWEEP_POINTS_MAX=201 -DSAVEAREA_MAX=7 -DDISPLAY_ST7796" LDSCRIPT=./gd32f303cc_with_bootloader_plus4.ld +make -j4 BOARDNAME=board_v2_plus4 EXTRA_CFLAGS="-DSWEEP_POINTS_MAX=201 -DSAVEAREA_MAX=7 -DDISPLAY_ST7796" LDSCRIPT=./gd32f303cc_with_bootloader_plus4.ld ``` The first time you build the firmware on a fresh repository, there is a libopencm3 bug that sometimes causes the linker script to be overwritten with one that will not work. If the built firmware does not boot, try running the following commands, then rebuild: diff --git a/main2.cpp b/main2.cpp index 44f4e6b..1c5363a 100644 --- a/main2.cpp +++ b/main2.cpp @@ -834,6 +834,8 @@ static void setVNASweepToUSB() { setFrequency((freqHz_t)*(uint64_t*)(registers + 0x00)); } #else + currTimingsArgs.nAverage = 1; + sys_syscall(5, &currTimingsArgs); setHWSweep(sys_setSweep_args { (freqHz_t)*(uint64_t*)(registers + 0x00), (freqHz_t)*(uint64_t*)(registers + 0x10), @@ -987,6 +989,9 @@ static void measurementDataSmooth(complexf *data, int points, int count){ data[j] = (data[j] + data[j] + prev)/3.0f; } } +int currDPCnt = 0; +int lastFreqIndex = -1; +VNAObservation currDP; #define USE_FIXED_CORRECTION // callback called by VNAMeasurement when an observation is available. @@ -1155,10 +1160,10 @@ static void setVNASweepToUI() { vnaMeasurement.setSweep(start, step, current_props._sweep_points, current_props._avg); ecalState = ECAL_STATE_MEASURING; #else - currTimingsArgs.nAverage = current_props._avg; + currTimingsArgs.nAverage = 1; sys_syscall(5, &currTimingsArgs); setHWSweep(sys_setSweep_args { - start, step, current_props._sweep_points, 1 + start, step, current_props._sweep_points, current_props._avg }); #endif update_grid(); @@ -1867,7 +1872,7 @@ namespace UIActions { vnaMeasurement.measurement_mode = MEASURE_MODE_FULL; collectMeasurementCB = [type]() { #if BOARD_REVISION >= 4 - sys_setTimings_args args {0, current_props._avg}; + sys_setTimings_args args {0, 1}; sys_syscall(5, &args); #else vnaMeasurement.ecalIntervalPoints = MEASUREMENT_ECAL_INTERVAL; @@ -1876,9 +1881,7 @@ namespace UIActions { current_props._cal_status |= (1 << type); ui_cal_collected(); }; - uint32_t avgMult = current_props._avg; - if(avgMult < BOARD_MEASUREMENT_MIN_CALIBRATION_AVG) avgMult = BOARD_MEASUREMENT_MIN_CALIBRATION_AVG; - if(avgMult > BOARD_MEASUREMENT_MAX_CALIBRATION_AVG) avgMult = BOARD_MEASUREMENT_MAX_CALIBRATION_AVG; + uint32_t avgMult = 2; #if BOARD_REVISION >= 4 __sync_synchronize(); sys_setTimings_args args {0, avgMult};