Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-tenma-white committed Feb 25, 2021
2 parents e3e55bd + e9d2238 commit ebc366e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
66 changes: 37 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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:
Expand All @@ -78,43 +78,43 @@ 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.
All V2 devices contain a USB serial bootloader, and you can upload the firmware through USB without needing extra hardware.

The NanoVNA V2 firmware is installed at address 0x8004000.
You can upload the firmware binary to that address using an ST-Link.
## Updating firmware using the USB serial bootloader

If your device already has a working serial bootloader, you can upload the firmware without needing extra hardware.
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).
Switch the device on (screen stays white), release the button.
```

## Updating firmware using the serial bootloader
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 the device.

If you have an intact bootloader already installed in your NanoVNAv2, there are several ways to update the firmware.
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.

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

On a Debian based system, you can get pyserial using:

```
sudo apt install python3-serial
```
#### Option 1: Upload firmware using NanoVNA-QT

## Updating the firmware
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.

You must restart the device in BOOTLOAD mode:

#### 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:
```
Switch the device off.
Press and hold down the left button (the one closest to the Port 1 or the On/Off switch).
Switch the device on (screen stays white), release the button.
sudo apt install python3-serial
```

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.

Flashing can be done by running:
```
python bootload_firmware.py -f binary.bin
Expand All @@ -125,7 +125,15 @@ 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

### 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.
15 changes: 9 additions & 6 deletions main2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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};
Expand Down

0 comments on commit ebc366e

Please sign in to comment.