This is an automated email from Gerrit.

"Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8574

-- gerrit

commit 04cc91a1585b8506aae2e2cea486e4073cd76e0a
Author: Antonio Borneo <borneo.anto...@gmail.com>
Date:   Sun Nov 10 14:30:25 2024 +0100

    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 <asie...@gmail.com>
    Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com>

diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c
index 0385e4d857..d77f28b0f4 100644
--- a/src/jtag/drivers/stlink_usb.c
+++ b/src/jtag/drivers/stlink_usb.c
@@ -3781,7 +3781,7 @@ static int stlink_open(struct hl_interface_param *param, 
enum stlink_mode mode,
        }
 
        /* initialize the debug hardware */
-       err = stlink_usb_init_mode(h, param->connect_under_reset, 
param->initial_interface_speed);
+       err = stlink_usb_init_mode(h, param->connect_under_reset, 
adapter_get_speed_khz());
 
        if (err != ERROR_OK) {
                LOG_ERROR("init mode failed (unable to connect to the target)");
@@ -5174,7 +5174,6 @@ static int stlink_dap_speed(int speed)
                return ERROR_JTAG_NOT_IMPLEMENTED;
        }
 
-       stlink_dap_param.initial_interface_speed = speed;
        stlink_speed(stlink_dap_handle, speed, false);
        return ERROR_OK;
 }
diff --git a/src/jtag/hla/hla_interface.c b/src/jtag/hla/hla_interface.c
index e826f79103..96862b0d05 100644
--- a/src/jtag/hla/hla_interface.c
+++ b/src/jtag/hla/hla_interface.c
@@ -30,7 +30,6 @@ static struct hl_interface hl_if = {
                .pid = { 0 },
                .transport = HL_TRANSPORT_UNKNOWN,
                .connect_under_reset = false,
-               .initial_interface_speed = -1,
                .use_stlink_tcp = false,
                .stlink_tcp_port = 7184,
        },
@@ -165,11 +164,8 @@ static int hl_interface_speed(int speed)
        if (!hl_if.layout->api->speed)
                return ERROR_OK;
 
-       if (!hl_if.handle) {
-               /* pass speed as initial param as interface not open yet */
-               hl_if.param.initial_interface_speed = speed;
+       if (!hl_if.handle)
                return ERROR_OK;
-       }
 
        hl_if.layout->api->speed(hl_if.handle, speed, false);
 
diff --git a/src/jtag/hla/hla_interface.h b/src/jtag/hla/hla_interface.h
index c95638b92a..f1550d9915 100644
--- a/src/jtag/hla/hla_interface.h
+++ b/src/jtag/hla/hla_interface.h
@@ -31,8 +31,6 @@ struct hl_interface_param {
        enum hl_transports transport;
        /** */
        bool connect_under_reset;
-       /** Initial interface clock clock speed */
-       int initial_interface_speed;
        /** */
        bool use_stlink_tcp;
        /** */

-- 

Reply via email to