@@ -24,6 +24,7 @@ static void usage(void) {
2424 puts ("st-info --sram [--connect-under-reset] [--hot-plug] [--freq=<kHz>]" );
2525 puts ("st-info --chipid [--connect-under-reset] [--hot-plug] [--freq=<kHz>]" );
2626 puts ("st-info --descr [--connect-under-reset] [--hot-plug] [--freq=<kHz>]" );
27+ puts ("st-info --voltage [--connect-under-reset] [--hot-plug] [--freq=<kHz>]" );
2728}
2829
2930static void stlink_print_version (stlink_t * sl ) {
@@ -49,6 +50,17 @@ static void stlink_print_info(stlink_t *sl) {
4950
5051 params = stlink_chipid_get_params (sl -> chip_id );
5152 if (params ) { printf (" dev-type: %s\n" , params -> dev_type ); }
53+
54+ // Print target voltage if supported
55+ int32_t voltage_mv = -1 ;
56+ if (sl -> version .stlink_v != 1 ) {
57+ voltage_mv = stlink_target_voltage (sl );
58+ }
59+ if (voltage_mv >= 0 ) {
60+ printf (" voltage: %d mV\n" , voltage_mv );
61+ } else {
62+ printf (" voltage: n/a\n" );
63+ }
5264}
5365
5466static void stlink_probe (enum connect_type connect , int32_t freq ) {
@@ -127,6 +139,21 @@ static int32_t print_data(int32_t ac, char **av) {
127139 if (params == NULL ) { return (-1 ); }
128140
129141 printf ("%s\n" , params -> dev_type );
142+ } else if (strcmp (av [1 ], "--voltage" ) == 0 ) {
143+ int32_t voltage_mv = -1 ;
144+ if (sl -> version .stlink_v != 1 ) {
145+ voltage_mv = stlink_target_voltage (sl );
146+ }
147+ if (voltage_mv >= 0 ) {
148+ printf ("%d\n" , voltage_mv );
149+ } else {
150+ fprintf (stderr , "Failed to read target voltage\n" );
151+ if (sl ) {
152+ stlink_exit_debug_mode (sl );
153+ stlink_close (sl );
154+ }
155+ return (-1 );
156+ }
130157 }
131158
132159 if (sl ) {
0 commit comments