From 861730f73230d764e0309422556bc5f7ab33e94f Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 23 Sep 2018 15:28:05 +0200 Subject: [PATCH] stlink: add STLINK_F_HAS_MEM_16BIT Change-Id: I51a160a105342ddbab99c4182d89650a436f5945 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4711 Reviewed-by: Spencer Oliver Tested-by: Spencer Oliver --- src/jtag/drivers/stlink_usb.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index 852fa59a59..5e0411ff60 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -280,6 +280,7 @@ enum stlink_mode { #define STLINK_F_HAS_TRACE (1UL << 0) #define STLINK_F_HAS_SWD_SET_FREQ (1UL << 1) #define STLINK_F_HAS_JTAG_SET_FREQ (1UL << 2) +#define STLINK_F_HAS_MEM_16BIT (1UL << 3) /* aliases */ #define STLINK_F_HAS_TARGET_VOLT STLINK_F_HAS_TRACE @@ -684,6 +685,10 @@ static int stlink_usb_version(void *handle) if (h->version.jtag >= 24) flags |= STLINK_F_HAS_JTAG_SET_FREQ; + /* API to read/write memory at 16 bit from J26 */ + if (h->version.jtag >= 26) + flags |= STLINK_F_HAS_MEM_16BIT; + break; default: break; @@ -1746,9 +1751,7 @@ static int stlink_usb_read_mem16(void *handle, uint32_t addr, uint16_t len, assert(handle != NULL); - /* only supported by stlink/v2 and for firmware >= 26 */ - if (h->jtag_api == STLINK_JTAG_API_V1 || - (h->jtag_api == STLINK_JTAG_API_V2 && h->version.jtag < 26)) + if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT)) return ERROR_COMMAND_NOTFOUND; /* data must be a multiple of 2 and half-word aligned */ @@ -1785,9 +1788,7 @@ static int stlink_usb_write_mem16(void *handle, uint32_t addr, uint16_t len, assert(handle != NULL); - /* only supported by stlink/v2 and for firmware >= 26 */ - if (h->jtag_api == STLINK_JTAG_API_V1 || - (h->jtag_api == STLINK_JTAG_API_V2 && h->version.jtag < 26)) + if (!(h->version.flags & STLINK_F_HAS_MEM_16BIT)) return ERROR_COMMAND_NOTFOUND; /* data must be a multiple of 2 and half-word aligned */ @@ -1899,8 +1900,7 @@ static int stlink_usb_read_mem(void *handle, uint32_t addr, uint32_t size, count *= size; /* switch to 8 bit if stlink does not support 16 bit memory read */ - if (size == 2 && (h->jtag_api == STLINK_JTAG_API_V1 || - (h->jtag_api == STLINK_JTAG_API_V2 && h->version.jtag < 26))) + if (size == 2 && !(h->version.flags & STLINK_F_HAS_MEM_16BIT)) size = 1; while (count) { @@ -1985,8 +1985,7 @@ static int stlink_usb_write_mem(void *handle, uint32_t addr, uint32_t size, count *= size; /* switch to 8 bit if stlink does not support 16 bit memory read */ - if (size == 2 && (h->jtag_api == STLINK_JTAG_API_V1 || - (h->jtag_api == STLINK_JTAG_API_V2 && h->version.jtag < 26))) + if (size == 2 && !(h->version.flags & STLINK_F_HAS_MEM_16BIT)) size = 1; while (count) { -- 2.30.2