swim: fix adapter speed handling 29/5529/6
authorAntonio Borneo <borneo.antonio@gmail.com>
Tue, 4 Feb 2020 10:07:01 +0000 (11:07 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 24 May 2020 20:31:21 +0000 (21:31 +0100)
SWIM transport only supports two adapter speeds:
- "low speed"  equal to 363 kHz (8 MHz / 22)
- "high speed" equal to 800 kHz (8 MHz / 10)

Replace the previous convention that use "0" or "1" for "low" or
"high" speed with the effective speed in kHz.
Rework the implementation of stlink_speed_swim().
Set low speed in the stm8 config files, because only low speed is
permitted at debug connection; the previous code ignores the
initial value.

Change-Id: I2484c9419a2c554c59eb6b9216339393ab0b54f3
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5529
Tested-by: jenkins
src/jtag/drivers/stlink_usb.c
src/jtag/swim.h
src/target/stm8.c
tcl/target/stm8l.cfg
tcl/target/stm8s.cfg

index aef02c5635fac05609c8af08c758e83c1ecc2778..485a95c6b660219ff3b030e380b73760eebbb4e3 100644 (file)
@@ -36,6 +36,7 @@
 #include <jtag/hla/hla_layout.h>
 #include <jtag/hla/hla_transport.h>
 #include <jtag/hla/hla_interface.h>
+#include <jtag/swim.h>
 #include <target/target.h>
 #include <transport/transport.h>
 
@@ -2478,17 +2479,20 @@ static int stlink_usb_override_target(const char *targetname)
 
 static int stlink_speed_swim(void *handle, int khz, bool query)
 {
+       int retval;
+
        /*
-                       we dont care what the khz rate is
                        we only have low and high speed...
                        before changing speed the SWIM_CSR HS bit
                        must be updated
         */
-       if (khz == 0)
-               stlink_swim_speed(handle, 0);
-       else
-               stlink_swim_speed(handle, 1);
-       return khz;
+       if (!query) {
+               retval = stlink_swim_speed(handle, (khz < SWIM_FREQ_HIGH) ? 0 : 1);
+               if (retval != ERROR_OK)
+                       LOG_ERROR("Unable to set adapter speed");
+       }
+
+       return (khz < SWIM_FREQ_HIGH) ? SWIM_FREQ_LOW : SWIM_FREQ_HIGH;
 }
 
 static int stlink_match_speed_map(const struct speed_map *map, unsigned int map_size, int khz, bool query)
index d0ae18eab1751a85205d83d2a8f89e9c8473c70d..186e0cc71a1a47d429b43a68c45b43684d097204 100644 (file)
@@ -13,6 +13,9 @@
 #ifndef OPENOCD_JTAG_SWIM_H
 #define OPENOCD_JTAG_SWIM_H
 
+#define SWIM_FREQ_LOW   363
+#define SWIM_FREQ_HIGH  800
+
 struct swim_driver {
        /**
         * Send SRST (system reset) command to target.
index ad05b54f9b24bbc72a54af9e87938d607f771678..c06e0fae79db5f1403a6e2aa54c967656cdd02e0 100644 (file)
@@ -1670,7 +1670,7 @@ static int stm8_examine(struct target *target)
                        retval = stm8_write_u8(target, SWIM_CSR, SAFE_MASK + SWIM_DM + HS);
                        if (retval != ERROR_OK)
                                return retval;
-                       jtag_config_khz(1);
+                       jtag_config_khz(SWIM_FREQ_HIGH);
                        stm8->swim_configured = true;
                        /*
                                Now is the time to deassert reset if connect_under_reset.
index 386f371ea30a6e3940ca5fb0b8f09b28d067515b..f3c94280aed288573cf448a1373994473549eea6 100644 (file)
@@ -78,8 +78,8 @@ $_TARGETNAME configure -optionstart $_OPTIONSTART -optionend $_OPTIONEND -blocks
 # Set stm8l type
 $_TARGETNAME configure -enable_stm8l
 
-# The khz rate does not apply here, only slow <0> and fast <1>
-adapter speed 1
+# Set low speed at debug entry
+adapter speed 363
 
 reset_config srst_only
 
index 4768068e820e8410184e3fc596fcd92d65d59cca..5d52aea12b78027e6dd43d68d75e31842f9f2676 100644 (file)
@@ -75,8 +75,8 @@ $_TARGETNAME configure -optionstart $_OPTIONSTART -optionend $_OPTIONEND -blocks
 # Uncomment this line to enable interrupts while instruction step
 #$_TARGETNAME configure -enable_step_irq
 
-# The khz rate does not apply here, only slow <0> and fast <1>
-adapter speed 1
+# Set low speed at debug entry
+adapter speed 363
 
 reset_config srst_only
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)