From 66f26f3093a985ed18caa6dd3771d327faaf049f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 11 Mar 2021 11:20:09 +0100 Subject: [PATCH] application: improve target show display, and show signal voltages --- application.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/application.c b/application.c index 10ea65c..636cd7b 100644 --- a/application.c +++ b/application.c @@ -131,6 +131,24 @@ static float* measure_voltages(void) return voltages; } +/** measure and print target voltage */ +static void print_voltage_target(void) +{ + gpio_set(GPIO_PORT(SIGNAL_PU_PIN), GPIO_PIN(SIGNAL_PU_PIN)); // ensure we are not pulling up the signal + gpio_set(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // ensure we are not pulling down the signal + gpio_set(GPIO_PORT(TARGET_EN), GPIO_PIN(TARGET_EN)); // ensure the level shifters pulling up the signals are not enabled + float* voltages = measure_voltages(); // measure voltages + puts("target voltage: "); + print_voltage(voltages[1], 2); + puts(" V"); + if (voltages[1] > 3.25) { + puts(" (warning: signal voltage may exceed 3.30 V limit)"); + } else if (voltages[1] < 1.0) { + puts(" (warning: target voltage seems not connected)"); + } + putc('\n'); +} + /** select channel of multiplexer * @param[in] channel channel to select, or -1 to disable multiplexer */ @@ -199,15 +217,15 @@ static void command_swd_scan(void* argument) static void command_voltages(void* argument) { (void)argument; // we won't use the argument - float* voltages = measure_voltages(); // measure voltages - puts("voltages:\n"); - puts("- target: "); - print_voltage(voltages[1], 2); - puts(" V\n"); - if (voltages[2] >= 3.25) { - puts("- signal: >= 3.30 V\n"); - } else { - puts("- signal: "); + float* voltages; + print_voltage_target(); // print target voltage (also sets measurement conditions) + puts("signal voltages:\n"); + for (uint8_t i = 0; i < SIGNAL_NUMBERS; i++) { + puts("- "); + puts(signal_names[i]); + mux_select(i); // select the channel + voltages = measure_voltages(); // measure raw voltages + puts(" "); print_voltage(voltages[2], 2); puts(" V\n"); }