From 89c3b1462b8c4b96e2071a87883aed5e030bbef9 Mon Sep 17 00:00:00 2001 From: Maxime Coquelin Date: Thu, 10 Mar 2016 16:39:26 +0100 Subject: [PATCH] stlink_target_voltage: Check for libusb error _stlink_usb_target_voltage already returns an error value. If value return is positive, this is a voltage, if negative this is an error. Check the return on callers side to inform there is an error in reading the voltage, instead of notifying of a too low voltage. Signed-off-by: Maxime Coquelin --- src/stlink-common.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/stlink-common.c b/src/stlink-common.c index 6839593..204491c 100644 --- a/src/stlink-common.c +++ b/src/stlink-common.c @@ -1609,7 +1609,10 @@ int write_loader_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size) { sl->chip_id == STM32_CHIPID_F4_LP || sl->chip_id == STM32_CHIPID_F4_HD || (sl->chip_id == STM32_CHIPID_F411RE) || (sl->chip_id == STM32_CHIPID_F446) || (sl->chip_id == STM32_CHIPID_F4_DSI)){ int voltage = stlink_target_voltage(sl); - if (voltage > 2700) { + if (voltage == -1) { + printf("Failed to read Target voltage\n"); + return voltage; + } else if (voltage > 2700) { loader_code = loader_code_stm32f4; loader_size = sizeof(loader_code_stm32f4); } else { @@ -1829,7 +1832,10 @@ int stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t* base, uint32_t if (sl->chip_id != STM32_CHIPID_L4) { /* set parallelisim to 32 bit*/ int voltage = stlink_target_voltage(sl); - if (voltage > 2700) { + if (voltage == -1) { + printf("Failed to read Target voltage\n"); + return voltage; + } else if (voltage > 2700) { printf("enabling 32-bit flash writes\n"); write_flash_cr_psiz(sl, 2); } else { @@ -1839,7 +1845,10 @@ int stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t* base, uint32_t } else { /* L4 does not have a byte-write mode */ int voltage = stlink_target_voltage(sl); - if (voltage < 1710) { + if (voltage == -1) { + printf("Failed to read Target voltage\n"); + return voltage; + } else if (voltage < 1710) { printf("Target voltage (%d mV) too low for flash writes!\n", voltage); return -1; }