stlink: add STLINK_F_HAS_JTAG_SET_FREQ

Change-Id: I591543f218c6bb30aaeb6321ba8a9425a2b5b6e2
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4710
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Tested-by: Spencer Oliver <spen@spen-soft.co.uk>
This commit is contained in:
Antonio Borneo 2018-09-23 15:20:30 +02:00 committed by Spencer Oliver
parent d705389f67
commit 85223bb500
1 changed files with 9 additions and 6 deletions

View File

@ -279,6 +279,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)
/* aliases */
#define STLINK_F_HAS_TARGET_VOLT STLINK_F_HAS_TRACE
@ -679,6 +680,10 @@ static int stlink_usb_version(void *handle)
if (h->version.jtag >= 22)
flags |= STLINK_F_HAS_SWD_SET_FREQ;
/* API to set JTAG frequency from J24 */
if (h->version.jtag >= 24)
flags |= STLINK_F_HAS_JTAG_SET_FREQ;
break;
default:
break;
@ -758,8 +763,7 @@ static int stlink_usb_set_jtagclk(void *handle, uint16_t clk_divisor)
assert(handle != NULL);
/* only supported by stlink/v2 and for firmware >= 24 */
if (h->version.stlink == 1 || h->version.jtag < 24)
if (!(h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ))
return ERROR_COMMAND_NOTFOUND;
stlink_usb_init_buffer(handle, h->rx_ep, 2);
@ -2142,8 +2146,8 @@ static int stlink_speed_jtag(void *handle, int khz, bool query)
int speed_index;
struct stlink_usb_handle_s *h = handle;
/* only supported by stlink/v2 and for firmware >= 24 */
if (h->version.stlink == 1 || h->version.jtag < 24)
/* old firmware cannot change it */
if (!(h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ))
return khz;
speed_index = stlink_match_speed_map(stlink_khz_to_speed_map_jtag,
@ -2395,8 +2399,7 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
}
if (h->transport == HL_TRANSPORT_JTAG) {
/* jtag clock speed only supported by stlink/v2 and for firmware >= 24 */
if (h->version.stlink >= 2 && h->version.jtag >= 24) {
if (h->version.flags & STLINK_F_HAS_JTAG_SET_FREQ) {
stlink_dump_speed_map(stlink_khz_to_speed_map_jtag, ARRAY_SIZE(stlink_khz_to_speed_map_jtag));
stlink_speed(h, param->initial_interface_speed, false);
}