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/2335
-- gerrit commit ccd2295734f8d05574a2981fd8812d34be654d37 Author: Spencer Oliver <[email protected]> Date: Mon Oct 6 23:14:11 2014 +0100 stlink: add reconfigurable speed support The ability to change the speed has been added to firmware versions J22 and above. Any attempt to change on earlier versions will be ignored without error, as the existing code does. For supported firmware versions the driver will attempt to get as close as possible to supported speeds. The default stlink speed on power up is 1.8MHz. Change-Id: Iee9bd018bb8b6f94672a12538912d41c23d48a7e Signed-off-by: Spencer Oliver <[email protected]> diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index 58af0dd..9355f93 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -226,6 +226,21 @@ enum stlink_mode { #define REQUEST_SENSE 0x03 #define REQUEST_SENSE_LENGTH 18 +static const int stlink_khz_to_speed_map[] = { + 4000, + 1800, /* default */ + 1200, + 950, + 480, + 240, + 125, + 100, + 50, + 25, + 15, + 5 +}; + static void stlink_usb_init_buffer(void *handle, uint8_t direction, uint32_t size); /** */ @@ -534,6 +549,31 @@ static int stlink_usb_check_voltage(void *handle, float *target_voltage) return ERROR_OK; } +static int stlink_usb_set_swdclk(void *handle, uint16_t clk_freq) +{ + struct stlink_usb_handle_s *h = handle; + + assert(handle != NULL); + + /* only supported by stlink/v2 and for firmware >= 22 */ + if (h->version.stlink == 1 || h->version.jtag < 22) + return ERROR_COMMAND_NOTFOUND; + + stlink_usb_init_buffer(handle, h->rx_ep, 2); + + h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; + h->cmdbuf[h->cmdidx++] = 0x43; + h_u16_to_le(h->cmdbuf+h->cmdidx, clk_freq); + h->cmdidx += 2; + + int result = stlink_cmd_allow_retry(handle, h->databuf, 2); + + if (result != ERROR_OK) + return result; + + return ERROR_OK; +} + /** */ static int stlink_usb_current_mode(void *handle, uint8_t *mode) { @@ -1739,6 +1779,13 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd) goto error_open; } + err = stlink_usb_set_swdclk(h, param->initial_interface_speed); + + if (err != ERROR_OK && err != ERROR_COMMAND_NOTFOUND) { + LOG_ERROR("set clock speed failed"); + goto error_open; + } + /* get cpuid, so we can determine the max page size * start with a safe default */ h->max_mem_packet = (1 << 10); @@ -1766,6 +1813,48 @@ error_open: return ERROR_FAIL; } +static int stlink_speed(void *handle, int speed) +{ + struct stlink_usb_handle_s *h = handle; + assert(handle != NULL); + + int result = stlink_usb_set_swdclk(h, speed); + if (result != ERROR_OK && result != ERROR_COMMAND_NOTFOUND) + return ERROR_FAIL; + return ERROR_OK; +} + +/* convert adapter frequency to human readable kHz value */ +static int stlink_speed_div(int speed, int *khz) +{ + *khz = stlink_khz_to_speed_map[speed]; + return ERROR_OK; +} + +/* convert human readable kHz value to adapter frequency */ +static int stlink_khz(int khz, int *jtag_speed) +{ + unsigned i; + int speed_diff = 4000; + + for (i = 0; i < ARRAY_SIZE(stlink_khz_to_speed_map); i++) { + if (khz == stlink_khz_to_speed_map[i]) { + *jtag_speed = i; + break; + } else { + int current_diff = khz - stlink_khz_to_speed_map[i]; + /* get abs value for comparison */ + current_diff = (current_diff > 0) ? current_diff : -current_diff; + if (current_diff < speed_diff) { + speed_diff = current_diff; + *jtag_speed = i; + } + } + } + + return ERROR_OK; +} + /** */ struct hl_layout_api_s stlink_usb_layout_api = { /** */ @@ -1800,4 +1889,8 @@ struct hl_layout_api_s stlink_usb_layout_api = { .write_debug_reg = stlink_usb_write_debug_reg, /** */ .override_target = stlink_usb_override_target, + + .speed = stlink_speed, + .khz = stlink_khz, + .speed_div = stlink_speed_div, }; -- ------------------------------------------------------------------------------ Slashdot TV. Videos for Nerds. Stuff that Matters. http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
