diff --git a/README.md b/README.md index 5159ee4..f9070aa 100644 --- a/README.md +++ b/README.md @@ -27,23 +27,26 @@ Use github issue list only for firmware bugs and preferrably cross post to: http ## Prepare ARM Cross Tools -**UPDATE**: Recent gcc version works to build tinySA, no need old version. +The released firmware is built with **Arm GNU Toolchain 11.3.Rel1** (arm-none-eabi-gcc 11.3.1 20220712), on Windows the "GNU Tools ARM Embedded\11.3 2022.08" toolchain of ChibiStudio. Use exactly this version. Parts of the firmware depend on how fast the compiled code runs, and firmware built with other gcc versions is known to show noise or fail the self test (issues #70 and #152). + +All versions are on the [Arm GNU Toolchain downloads](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) page. Check the version in use with + + $ arm-none-eabi-gcc --version ### MacOSX -Install cross tools and firmware updating tool. +Install the cross tools and the firmware updating tool. - $ brew tap px4/px4 - $ brew install gcc-arm-none-eabi-80 + $ curl -LO https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/arm-gnu-toolchain-11.3.rel1-darwin-x86_64-arm-none-eabi.tar.xz + $ sudo tar xfJ arm-gnu-toolchain-11.3.rel1-darwin-x86_64-arm-none-eabi.tar.xz -C /usr/local + $ PATH=/usr/local/arm-gnu-toolchain-11.3.rel1-darwin-x86_64-arm-none-eabi/bin:$PATH $ brew install dfu-util ### Linux (ubuntu) -Download arm cross tools from [here](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads). - - $ wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2 - $ sudo tar xfj gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2 -C /usr/local - $ PATH=/usr/local/gcc-arm-none-eabi-8-2018-q4-major/bin:$PATH + $ wget https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi.tar.xz + $ sudo tar xfJ arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi.tar.xz -C /usr/local + $ PATH=/usr/local/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin:$PATH $ sudo apt install -y dfu-util ## Fetch source code @@ -66,7 +69,7 @@ For tinySA Ultra use this command ### Build firmware using docker -Using [this docker image](https://hub.docker.com/r/edy555/arm-embedded) and without installing arm toolchain, you can build the firmware. +Using [this docker image](https://hub.docker.com/r/edy555/arm-embedded) and without installing arm toolchain, you can build the firmware. Note that this image has gcc 8.2, not the release toolchain (see above). $ cd tinySA $ docker run -it --rm -v $(PWD):/work edy555/arm-embedded:8.2 make diff --git a/changelog.txt b/changelog.txt index 4226340..f756ed3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,12 @@ +V1.4311 2026-11-11 For all tinySA models +- Console: "measure {mode} [value]..." starts a measurement of the MEASURE menu, the values the menu asks for are the arguments, e.g. "measure channel_power 5800M 20M". Modes: off|harmonic|oip3|phase_noise|snr|3db_width|occupied_width|am|fm|thd|channel_power|linear, on the Ultra also nf_tinysa|nf_store|nf_validate|nf_amp +- Console: "recall defaults" loads the factory settings in low input mode, as PRESET > LOAD DEFAULTS, but does not store them as the startup preset +- Console: "freq {frequency}" sets zero span at the frequency, as "sweep cw" (it only paused the sweep) +- Console: after "scan {start} {stop}" the sweep is back on its own frequencies and points, the frequencies of the scan stayed and following commands such as "frequencies" and "scan" used wrong frequencies +- Console: with MULTI BAND on, "scan {start} {stop}" scans the given range instead of the bands. The next scan took about 30 s and "sweep" showed a wrong stop frequency (Ultra only) +- Console: "hop {start} {stop} {points}" measures exactly that number of points, the last one at stop (it measured one more), and an invalid range no longer leaves the sweep paused (Ultra only) +- Console: the usage text of "if" and "sd_read" showed "usage:" twice + V1.4305 2026-11-10 For all tinySA Ultra models - Signal generator: BURST modulation switches the output on and off: ON TIME of every PERIOD, continuously or COUNT bursts. With MODULATION > BURST selected the FREQ, AM DEPTH and FM DEVIATION buttons set PERIOD (2us..89s), ON TIME and COUNT (0 = continuous) and START SWEEP becomes START BURST, which starts the COUNT bursts or restarts the continuous bursts. The frequency is not changed during a burst. Burst works up to 1.13 GHz and above it with OUTPUT "Highest accuracy", not with "Cleanest signal" (MOD: BURST N/A) - Console: "modulation burst|period|ontime|count|trigger", e.g. "modulation period 1m", "modulation ontime 100u", "modulation count 5", "modulation trigger" diff --git a/main.c b/main.c index 59a0f98..de5e6a1 100644 --- a/main.c +++ b/main.c @@ -609,12 +609,6 @@ VNA_SHELL_FUNCTION(cmd_reset) ; } -int set_frequency(freq_t freq) -{ - (void) freq; - return 1; -} - // Use macro, std isdigit more big #define _isdigit(c) (c >= '0' && c <= '9') // Rewrite universal standart str to value functions to more compact @@ -737,15 +731,10 @@ my_atof(const char *p) VNA_SHELL_FUNCTION(cmd_freq) { if (argc != 1 || argv[0][0] == '?') { - goto usage; + usage_printf("freq {frequency(Hz)}\r\n"); + return; } - freq_t freq = my_atoui(argv[0]); - - pause_sweep(); - set_frequency(freq); - return; -usage: - usage_printf("freq {frequency(Hz)}\r\n"); + set_sweep_frequency(ST_CW, my_atoui(argv[0])); // same as sweep cw } #ifdef __USE_RTC__ @@ -1311,7 +1300,7 @@ VNA_SHELL_FUNCTION(cmd_sd_read) char *buf = (char *)spi_buffer; if (argc != 1 || argv[0][0] == '?') { - usage_printf("usage: sd_read {filename}\r\n"); + usage_printf("sd_read {filename}\r\n"); return; } const char *filename = argv[0]; @@ -1690,11 +1679,13 @@ void set_sweep_points(uint16_t points){ VNA_SHELL_FUNCTION(cmd_scan) { - freq_t start = get_sweep_frequency(ST_START); - freq_t stop = get_sweep_frequency(ST_STOP); + freq_t start, stop; uint32_t old_points = sweep_points; uint32_t i; int repeat = 1; +#ifdef __BANDS__ + uint8_t old_multi_band = setting.multi_band; +#endif if (argc == 0) goto do_scan; if (argc == 1) { @@ -1720,6 +1711,9 @@ VNA_SHELL_FUNCTION(cmd_scan) } sweep_points = points; } +#ifdef __BANDS__ + setting.multi_band = false; // scan start..stop, not the bands +#endif set_frequencies(start, stop, sweep_points); do_scan: pause_sweep(); @@ -1742,60 +1736,57 @@ do_scan: } } } - sweep_points = old_points; + if (argc >= 2) { // back to the frequencies of the sweep +#ifdef __BANDS__ + setting.multi_band = old_multi_band; +#endif + sweep_points = old_points; + update_frequencies(); + } } #ifdef TINYSA4 VNA_SHELL_FUNCTION(cmd_hop) { - freq_t start, stop, step = 0; if (argc < 1 || argc > 4) { usage_printf("hop {start(Hz)} {stop(Hz)} {step(Hz) | points} [outmask]\r\n"); return; } - start = my_atoui(argv[0]); - if (argc > 1) - stop = my_atoui(argv[1]); - else { - stop = start; - step = 1; // just to stop the loop - } - - if (argc >= 3) { - step = my_atoui(argv[2]); - if (step <= POINTS_COUNT && step > 0) { - step = (stop - start) / step; - } - } else - step = 1; - if (step == 0) - step = 1; - int old_sweep = sweep_mode; - if (old_sweep & SWEEP_ENABLE) - pause_sweep(); - else - dirty = true; + freq_t start = my_atoui(argv[0]), stop = start, step = 1; // Output data after if set (faster data recive) uint16_t mask = 3; - if (argc == 4) { - mask = my_atoui(argv[3]); - } - - if (argc==2) { - mask = stop; - stop = start; + if (argc == 2) // hop {frequency} {outmask} + mask = my_atoui(argv[1]); + if (argc >= 3) { + stop = my_atoui(argv[1]); + step = my_atoui(argv[2]); } - + if (argc == 4) + mask = my_atoui(argv[3]); if (start > stop) { shell_printf("frequency range is invalid\r\n"); return; } + // point i of n is at start + mul * i / div + freq_t mul = stop - start; + uint32_t n = step, div = n > 1 ? n - 1 : 1; // a number of points, the last one at stop + if (step > POINTS_COUNT) { // a step in Hz + n = mul / step + 1; + mul = step; + div = 1; + } + int old_sweep = sweep_mode; + if (old_sweep & SWEEP_ENABLE) + pause_sweep(); + else + dirty = true; freq_t old_frequency_step = setting.frequency_step; setting.frequency_step = setting.rbw_x10*100; if (mask) { int old_vbwSteps = vbwSteps; // vbwSteps = 1; - for (freq_t f = start; f <= stop; f += step) { + for (uint32_t i = 0; i < n; i++) { + freq_t f = start + mul * i / div; if (mask & 1) shell_printf("%U ", f); float v = PURE_TO_float(perform(false, 0, f, false)); if (mask & 2) shell_printf("%f ", v); @@ -2185,17 +2176,24 @@ VNA_SHELL_FUNCTION(cmd_recall) if (argc != 1 || argv[0][0] == '?') goto usage; - int id = my_atoi(argv[0]); - if (id < 0 || id >= SAVEAREA_MAX) - goto usage; - // Check for success - if (caldata_recall(id) == -1) - shell_printf("Err, default load\r\n"); + if (get_str_index(argv[0], "defaults") == 0) { + reset_settings(M_LOW); // as PRESET > LOAD DEFAULTS, but the startup preset stays + set_refer_output(-1); + menu_move_top(); + ui_mode_normal(); + } else { + int id = my_atoi(argv[0]); + if (id < 0 || id >= SAVEAREA_MAX) + goto usage; + // Check for success + if (caldata_recall(id) == -1) + shell_printf("Err, default load\r\n"); + } update_frequencies(); redraw_request |= REDRAW_CAL_STATUS; return; usage: - shell_printf("recall {id}\r\n"); + shell_printf("recall {id}|defaults\r\n"); } VNA_SHELL_FUNCTION(cmd_channel) @@ -2819,6 +2817,7 @@ static const VNAShellCommand commands[] = {"trigger" , cmd_trigger , CMD_RUN_IN_LOAD}, {"marker" , cmd_marker , CMD_RUN_IN_LOAD}, {"channel" , cmd_channel , CMD_WAIT_MUTEX }, + {"measure" , cmd_measure , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD}, #ifdef __DRAW_LINE__ {"line" , cmd_line , CMD_RUN_IN_LOAD}, #endif diff --git a/nanovna.h b/nanovna.h index 46a7c5a..e49a30f 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1654,6 +1654,7 @@ void menu_invoke(int item); extern char kp_buf[]; void ui_set_keypad_text(const char *text); void set_numeric_value(void); +void ui_measure(int m, int argc, char *argv[]); void ui_mode_normal(void); void ui_mode_menu(void); diff --git a/sa_cmd.c b/sa_cmd.c index 56a2eab..8d462fc 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -176,6 +176,29 @@ VNA_SHELL_FUNCTION(cmd_calc ) set_average(t, m); } +VNA_SHELL_FUNCTION(cmd_measure) +{ + // The modes of the MEASURE menu in M_xxx order, the values are the ones its keypads ask for + static const char cmd_meas[] = "off|harmonic|oip3|phase_noise|snr|3db_width|occupied_width|am|fm|thd|channel_power|" +#ifdef __NOISE_FIGURE__ + "nf_tinysa|nf_store|nf_validate|nf_amp|" +#endif + "linear"; + static const uint8_t meas_values[] = {0, 1, 2, 2, 2, 0, 1, 2, 3, 0, 2, +#ifdef __NOISE_FIGURE__ + 1, 0, 0, 1, +#endif + 0}; + int m = argc && !MODE_OUTPUT(setting.mode) ? get_str_index(argv[0], cmd_meas) : -1; // only in the spectrum analyzer, as the menu + if (m < 0 || argc - 1 < meas_values[m]) { + usage_printf("measure %s [value]..\r\n", cmd_meas); + return; + } + if (m == sizeof(meas_values) - 1) + m = M_LINEARITY; + ui_measure(m, argc - 1, argv + 1); +} + int generic_option_cmd( const char *cmd, const char *cmd_list, int argc, char *argv) { if (argc != 1) { @@ -630,9 +653,9 @@ VNA_SHELL_FUNCTION(cmd_if) #ifdef TINYSA4 if (hw_if) t = "1067M..1073M"; - usage_printf("usage: if {%s}\r\n%QHz\r\n", t, setting.frequency_IF); + usage_printf("if {%s}\r\n%QHz\r\n", t, setting.frequency_IF); #else - usage_printf("usage: if {433M..435M}\r\n%QHz\r\n", setting.frequency_IF); + usage_printf("if {433M..435M}\r\n%QHz\r\n", setting.frequency_IF); #endif return; } diff --git a/ui.c b/ui.c index bf60a74..305b206 100644 --- a/ui.c +++ b/ui.c @@ -3012,6 +3012,24 @@ static UI_FUNCTION_CALLBACK(menu_clearconfig_cb) float nf_gain; const char * const averageText[] = { "OFF", "MINH", "MAXH", "MAXD", " AVER4", "A16", "AVER", "QUASI", "TABLE", "DECONV"}; +// measure console command: the values the MEASURE menu asks with a keypad come from its arguments +static char **measure_argv; +static int measure_argc; + +static void measure_keypad(int mode, char *help) +{ + if (measure_argv == NULL) { + kp_help_text = help; + ui_mode_keypad(mode); + return; + } + char *arg = measure_argc-- > 0 ? *measure_argv++ : "0"; // only an optional value can be missing + keypad_mode = mode; // as if typed on the keypad + uistat.value = my_atof(arg); + uistat.freq_value = my_atoui(arg); + set_numeric_value(); +} + static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) { (void)item; @@ -3050,12 +3068,10 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) for (int i = 1; i< MARKERS_MAX; i++) { markers[i].mtype = M_DELTA; } - kp_help_text = "Frequency of fundamental"; - ui_mode_keypad(KM_CENTER); + measure_keypad(KM_CENTER, "Frequency of fundamental"); freq_t fundamental = uistat.value; #ifdef __BANDS__ - kp_help_text = "Span (0=full span)"; - ui_mode_keypad(KM_CENTER); + measure_keypad(KM_CENTER, "Span (0=full span)"); freq_t half_span = uistat.value/2; if (half_span > fundamental/2) half_span = fundamental/2; @@ -3085,11 +3101,9 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) markers[i].enabled = M_ENABLED; } markers[1].mtype = M_TRACKING; - kp_help_text = "Frequency of left signal"; - ui_mode_keypad(KM_CENTER); + measure_keypad(KM_CENTER, "Frequency of left signal"); freq_t left = uistat.value; - kp_help_text = "Right signal"; - ui_mode_keypad(KM_CENTER); + measure_keypad(KM_CENTER, "Right signal"); freq_t right = uistat.value; set_sweep_frequency(ST_CENTER, (left+right)/2); freq_t local_span = (right - left)*10; @@ -3108,10 +3122,8 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) reset_settings(setting.mode); markers[1].enabled = M_ENABLED; markers[1].mtype = M_DELTA | M_NOISE; - kp_help_text = "Frequency of signal"; - ui_mode_keypad(KM_CENTER); - kp_help_text = "Frequency offset"; - ui_mode_keypad(KM_SPAN); + measure_keypad(KM_CENTER, "Frequency of signal"); + measure_keypad(KM_SPAN, "Frequency offset"); set_sweep_frequency(ST_SPAN, uistat.value*4); // set_measurement(M_PHASE_NOISE); set_average(0,AV_4); @@ -3119,10 +3131,8 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) break; case M_SNR: // STop band measurement reset_settings(setting.mode); - kp_help_text = "Frequency of signal"; - ui_mode_keypad(KM_CENTER); - kp_help_text = "Bandwidth"; - ui_mode_keypad(KM_SPAN); + measure_keypad(KM_CENTER, "Frequency of signal"); + measure_keypad(KM_SPAN, "Bandwidth"); set_sweep_frequency(ST_SPAN, uistat.value*3); // set_measurement(M_SNR); set_average(0,AV_4); @@ -3145,8 +3155,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) // reset_settings(setting.mode); markers[1].enabled = M_ENABLED; markers[2].enabled = M_ENABLED; - kp_help_text = "dBc"; - ui_mode_keypad(KM_LEVEL); + measure_keypad(KM_LEVEL, "dBc"); set_measurement(M_WIDTH); // SetAverage(4); @@ -3173,17 +3182,15 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) freq_t center, span; markers[0].mtype = M_NORMAL; // M_REFERENCE | M_TRACKING; // Not M_TRACKING!!!! #endif - kp_help_text = "Frequency of signal"; - ui_mode_keypad(KM_CENTER); + measure_keypad(KM_CENTER, "Frequency of signal"); #ifdef TINYSA3 center = uistat.value; #endif #ifdef TINYSA4 - kp_help_text = "Modulation frequency: 500hz .. 10kHz"; + measure_keypad(KM_SPAN, "Modulation frequency: 500hz .. 10kHz"); #else - kp_help_text = "Modulation frequency: 3 .. 10kHz"; + measure_keypad(KM_SPAN, "Modulation frequency: 3 .. 10kHz"); #endif - ui_mode_keypad(KM_SPAN); span = uistat.value; #ifdef TINYSA4 if (span < 500 || span > 10000) @@ -3208,31 +3215,27 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) markers[i].enabled = M_ENABLED; } markers[0].mtype = M_NORMAL; /// Not M_TRACKING !!!! - kp_help_text = "Frequency of signal"; - ui_mode_keypad(KM_CENTER); + measure_keypad(KM_CENTER, "Frequency of signal"); set_marker_frequency(0, uistat.value); #ifdef TINYSA4 - kp_help_text = "Modulation frequency: 50Hz .. 20kHz"; - ui_mode_keypad(KM_SPAN); + measure_keypad(KM_SPAN, "Modulation frequency: 50Hz .. 20kHz"); if (uistat.value < 50 || uistat.value > 20000) goto no_measurement; set_RBW(uistat.value/300); #else - kp_help_text = "Modulation frequency: 1 .. 2.5kHz"; - ui_mode_keypad(KM_SPAN); + measure_keypad(KM_SPAN, "Modulation frequency: 1 .. 2.5kHz"); if (uistat.value < 1000 || uistat.value > 2500) goto no_measurement; set_RBW(uistat.value/100); #endif // actual_rbw_x10 #ifdef TINYSA4 - kp_help_text = "Frequency deviation: 3 .. 500kHz"; + measure_keypad(KM_SPAN, "Frequency deviation: 3 .. 500kHz"); #define MINIMUM_DEVIATION 1500 #else - kp_help_text = "Frequency deviation: 500Hz .. 500kHz"; + measure_keypad(KM_SPAN, "Frequency deviation: 500Hz .. 500kHz"); #define MINIMUM_DEVIATION 12000 #endif - ui_mode_keypad(KM_SPAN); if (uistat.value < MINIMUM_DEVIATION) uistat.value = MINIMUM_DEVIATION; // minimum span set_sweep_frequency(ST_SPAN, uistat.value*4); @@ -3246,10 +3249,8 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) case M_CP: // channel power reset_settings(setting.mode); markers[0].enabled = M_DISABLED; - kp_help_text = "Channel frequency"; - ui_mode_keypad(KM_CENTER); - kp_help_text = "Channel width"; - ui_mode_keypad(KM_SPAN); + measure_keypad(KM_CENTER, "Channel frequency"); + measure_keypad(KM_SPAN, "Channel width"); set_sweep_frequency(ST_SPAN, uistat.value*3); // set_measurement(M_CP); break; @@ -3280,9 +3281,8 @@ validate: reset_settings(setting.mode); set_refer_output(-1); #endif - kp_help_text = "Amplifier Gain "; float old_gain = setting.external_gain; - ui_mode_keypad(KM_EXT_GAIN); + measure_keypad(KM_EXT_GAIN, "Amplifier Gain "); nf_gain = setting.external_gain; setting.external_gain = old_gain; noise_figure: @@ -3291,8 +3291,7 @@ validate: set_extra_lna(true); set_attenuation(0); if (data == M_NF_TINYSA) { - kp_help_text = "Noise center frequency"; - ui_mode_keypad(KM_CENTER); + measure_keypad(KM_CENTER, "Noise center frequency"); set_marker_frequency(0, uistat.value); #if 0 kp_help_text = "Noise span"; @@ -3332,6 +3331,16 @@ leave: // draw_cal_status(); } +void ui_measure(int m, int argc, char *argv[]) +{ + ui_mode_normal(); + menu_current_level = 0; + measure_argc = argc; + measure_argv = argv; + menu_measure_acb(0, m, NULL); + measure_argv = NULL; +} + static UI_FUNCTION_ADV_CALLBACK(menu_atten_acb) { (void)item;