This is an automated email from Gerrit.

Spencer Oliver ([email protected]) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/980

-- gerrit

commit d13e7fc667e15d7b9df5121e6dfd6cf814bec58b
Author: Spencer Oliver <[email protected]>
Date:   Wed Nov 14 17:49:30 2012 +0000

    stlink: print target voltage if supported
    
    The stlink/v2 has the ability to check the target voltage if the firmware
    is recent enough.
    
    Change-Id: I98e251f3880e31049c4307051c30bedd3451cf87
    Signed-off-by: Spencer Oliver <[email protected]>

diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c
index b92fb1c..80173bf 100644
--- a/src/jtag/drivers/stlink_usb.c
+++ b/src/jtag/drivers/stlink_usb.c
@@ -107,6 +107,7 @@ struct stlink_usb_handle_s {
 #define STLINK_DFU_COMMAND                             0xF3
 #define STLINK_SWIM_COMMAND                            0xF4
 #define STLINK_GET_CURRENT_MODE                        0xF5
+#define STLINK_GET_TARGET_VOLTAGE              0xF7
 
 #define STLINK_DEV_DFU_MODE                            0x00
 #define STLINK_DEV_MASS_MODE                   0x01
@@ -424,6 +425,40 @@ static int stlink_usb_version(void *handle)
        return ERROR_OK;
 }
 
+static int stlink_usb_check_voltage(void *handle)
+{
+       struct stlink_usb_handle_s *h;
+       uint32_t adc_results[2];
+
+       h = (struct stlink_usb_handle_s *)handle;
+
+       /* only supported by stlink/v2 and for firmware >= 13 */
+       if (h->version.stlink == 1 || h->version.jtag < 13)
+               return ERROR_OK;
+
+       stlink_usb_init_buffer(handle, STLINK_RX_EP, 8);
+
+       h->cmdbuf[h->cmdidx++] = STLINK_GET_TARGET_VOLTAGE;
+
+       int result = stlink_usb_xfer(handle, h->databuf, 8);
+
+       if (result != ERROR_OK)
+               return result;
+
+       /* convert result */
+       adc_results[0] = le_to_h_u32(h->databuf);
+       adc_results[1] = le_to_h_u32(h->databuf + 4);
+
+       float target_voltage = 0;
+
+       if (adc_results[0])
+               target_voltage = 2 * ((float)adc_results[1]) * (float)(1.2 / 
adc_results[0]);
+
+       LOG_INFO("Target voltage: %f", (double)target_voltage);
+
+       return ERROR_OK;
+}
+
 /** */
 static int stlink_usb_current_mode(void *handle, uint8_t *mode)
 {
@@ -1260,6 +1295,14 @@ static int stlink_usb_open(struct 
stlink_interface_param_s *param, void **fd)
                goto error_open;
        }
 
+       /* check target voltage (if supported) */
+       err = stlink_usb_check_voltage(h);
+
+       if (err != ERROR_OK) {
+               LOG_ERROR("voltage check failed");
+               goto error_open;
+       }
+
        *fd = h;
 
        return ERROR_OK;

-- 

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to