target/cortex_m: avoid dwt comparator overflow
[openocd.git] / src / target / cortex_m.c
index 79af632ac7faca703292f02055072b1fb033738a..a356350a2837f218435650e32b005d1fedf3f965 100644 (file)
@@ -1854,6 +1854,18 @@ static struct dwt_reg dwt_comp[] = {
        DWT_COMPARATOR(1),
        DWT_COMPARATOR(2),
        DWT_COMPARATOR(3),
+       DWT_COMPARATOR(4),
+       DWT_COMPARATOR(5),
+       DWT_COMPARATOR(6),
+       DWT_COMPARATOR(7),
+       DWT_COMPARATOR(8),
+       DWT_COMPARATOR(9),
+       DWT_COMPARATOR(10),
+       DWT_COMPARATOR(11),
+       DWT_COMPARATOR(12),
+       DWT_COMPARATOR(13),
+       DWT_COMPARATOR(14),
+       DWT_COMPARATOR(15),
 #undef DWT_COMPARATOR
 };
 
@@ -1887,6 +1899,7 @@ void cortex_m_dwt_setup(struct cortex_m_common *cm, struct target *target)
        int reg, i;
 
        target_read_u32(target, DWT_CTRL, &dwtcr);
+       LOG_DEBUG("DWT_CTRL: 0x%" PRIx32, dwtcr);
        if (!dwtcr) {
                LOG_DEBUG("no DWT");
                return;
@@ -1992,12 +2005,6 @@ int cortex_m_examine(struct target *target)
        /* stlink shares the examine handler but does not support
         * all its calls */
        if (!armv7m->stlink) {
-               retval = dap_dp_init(swjdp);
-               if (retval != ERROR_OK) {
-                       LOG_ERROR("Could not initialize the debug port");
-                       return retval;
-               }
-
                if (cortex_m->apsel < 0) {
                        /* Search for the MEM-AP */
                        retval = dap_find_ap(swjdp, AP_TYPE_AHB_AP, &armv7m->debug_ap);
@@ -2228,25 +2235,17 @@ static int cortex_m_handle_target_request(void *priv)
 }
 
 static int cortex_m_init_arch_info(struct target *target,
-       struct cortex_m_common *cortex_m, struct jtag_tap *tap)
+       struct cortex_m_common *cortex_m, struct adiv5_dap *dap)
 {
        struct armv7m_common *armv7m = &cortex_m->armv7m;
 
        armv7m_init_arch_info(target, armv7m);
 
-       /*  tap has no dap initialized */
-       if (!tap->dap) {
-               tap->dap = dap_init();
-
-               /* Leave (only) generic DAP stuff for debugport_init() */
-               tap->dap->tap = tap;
-       }
-
        /* default reset mode is to use srst if fitted
         * if not it will use CORTEX_M3_RESET_VECTRESET */
        cortex_m->soft_reset_config = CORTEX_M_RESET_VECTRESET;
 
-       armv7m->arm.dap = tap->dap;
+       armv7m->arm.dap = dap;
 
        /* register arch-specific functions */
        armv7m->examine_debug_reason = cortex_m_examine_debug_reason;
@@ -2266,16 +2265,16 @@ static int cortex_m_init_arch_info(struct target *target,
 static int cortex_m_target_create(struct target *target, Jim_Interp *interp)
 {
        struct cortex_m_common *cortex_m = calloc(1, sizeof(struct cortex_m_common));
-
        cortex_m->common_magic = CORTEX_M_COMMON_MAGIC;
-       cortex_m_init_arch_info(target, cortex_m, target->tap);
-
-       if (target->private_config != NULL) {
-               struct adiv5_private_config *pc =
-                               (struct adiv5_private_config *)target->private_config;
-               cortex_m->apsel = pc->ap_num;
-       } else
-               cortex_m->apsel = -1;
+       struct adiv5_private_config *pc;
+
+       pc = (struct adiv5_private_config *)target->private_config;
+       if (adiv5_verify_config(pc) != ERROR_OK)
+               return ERROR_FAIL;
+
+       cortex_m->apsel = pc->ap_num;
+
+       cortex_m_init_arch_info(target, cortex_m, pc->dap);
 
        return ERROR_OK;
 }

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)