Skip to content

Commit c582cfb

Browse files
committed
driver: stlink: get adapter speed through adapter_get_speed_khz()
The stlink driver, both in dapdirect and in HLA modes, pretends to store locally the value of the adapter speed in order to use it later-on during adapter initialization. It doesn't work in dapdirect mode since the code to store locally the value will not be executed until the adapter is already fully initialized. This cause an issue in dapdirect mode: - due to the local value, still kept at -1, the adapter will be initialized to the lowest clock speed (5 KHz on stlink v2 in SWD mode); - after the adapter initialization the framework will again set the speed with the value requested by the user. Some target, like nRF51822, only accepts JTAG/SWD speed in a defined range of frequencies. The initial speed of 5 KHz used by dapdirect can be out of range, making the target debug port not working. The adapter framework already stores the value of speed and makes it available through adapter_get_speed_khz(). Drop struct hl_interface_param::initial_interface_speed. Let the code to use adapter_get_speed_khz(). Change-Id: Ie11bf0234574f2a9180d3d3a16efb78e08dfcd86 Reported-by: Andrzej Sierżęga <[email protected]> Signed-off-by: Antonio Borneo <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8574 Reviewed-by: Andrzej Sierżęga <[email protected]> Tested-by: jenkins
1 parent 8c739a4 commit c582cfb

File tree

3 files changed

+2
-9
lines changed

3 files changed

+2
-9
lines changed

src/jtag/drivers/stlink_usb.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3781,7 +3781,7 @@ static int stlink_open(struct hl_interface_param *param, enum stlink_mode mode,
37813781
}
37823782

37833783
/* initialize the debug hardware */
3784-
err = stlink_usb_init_mode(h, param->connect_under_reset, param->initial_interface_speed);
3784+
err = stlink_usb_init_mode(h, param->connect_under_reset, adapter_get_speed_khz());
37853785

37863786
if (err != ERROR_OK) {
37873787
LOG_ERROR("init mode failed (unable to connect to the target)");
@@ -5174,7 +5174,6 @@ static int stlink_dap_speed(int speed)
51745174
return ERROR_JTAG_NOT_IMPLEMENTED;
51755175
}
51765176

5177-
stlink_dap_param.initial_interface_speed = speed;
51785177
stlink_speed(stlink_dap_handle, speed, false);
51795178
return ERROR_OK;
51805179
}

src/jtag/hla/hla_interface.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ static struct hl_interface hl_if = {
3030
.pid = { 0 },
3131
.transport = HL_TRANSPORT_UNKNOWN,
3232
.connect_under_reset = false,
33-
.initial_interface_speed = -1,
3433
.use_stlink_tcp = false,
3534
.stlink_tcp_port = 7184,
3635
},
@@ -165,11 +164,8 @@ static int hl_interface_speed(int speed)
165164
if (!hl_if.layout->api->speed)
166165
return ERROR_OK;
167166

168-
if (!hl_if.handle) {
169-
/* pass speed as initial param as interface not open yet */
170-
hl_if.param.initial_interface_speed = speed;
167+
if (!hl_if.handle)
171168
return ERROR_OK;
172-
}
173169

174170
hl_if.layout->api->speed(hl_if.handle, speed, false);
175171

src/jtag/hla/hla_interface.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ struct hl_interface_param {
3131
enum hl_transports transport;
3232
/** */
3333
bool connect_under_reset;
34-
/** Initial interface clock clock speed */
35-
int initial_interface_speed;
3634
/** */
3735
bool use_stlink_tcp;
3836
/** */

0 commit comments

Comments
 (0)