target: print reason why GDB halts
[openocd.git] / src / target / arm_adi_v5.c
index 72a07cd63e98e7efdde9e5f5c816e787ecf24b35..ba5db3b13c23bd1faca14cfd2c350524c51a6737 100644 (file)
@@ -88,7 +88,24 @@ static uint32_t max_tar_block_size(uint32_t tar_autoincr_block, uint32_t address
  *                                                                         *
 ***************************************************************************/
 
-/* Scan out and in from target ordered uint8_t buffers */
+/**
+ * Scan DPACC or APACC using target ordered uint8_t buffers.  No endianness
+ * conversions are performed.  See section 4.4.3 of the ADIv5 spec, which
+ * discusses operations which access these registers.
+ *
+ * Note that only one scan is performed.  If RnW is set, a separate scan
+ * will be needed to collect the data which was read; the "invalue" collects
+ * the posted result of a preceding operation, not the current one.
+ *
+ * @param swjdp the DAP
+ * @param instr JTAG_DP_APACC (AP access) or JTAG_DP_DPACC (DP access)
+ * @param reg_addr two significant bits; A[3:2]; for APACC access, the
+ *     SELECT register has more addressing bits.
+ * @param RnW false iff outvalue will be written to the DP or AP
+ * @param outvalue points to a 32-bit (little-endian) integer
+ * @param invalue NULL, or points to a 32-bit (little-endian) integer
+ * @param ack points to where the three bit JTAG_ACK_* code will be stored
+ */
 static int adi_jtag_dp_scan(struct swjdp_common *swjdp,
                uint8_t instr, uint8_t reg_addr, uint8_t RnW,
                uint8_t *outvalue, uint8_t *invalue, uint8_t *ack)
@@ -101,15 +118,31 @@ static int adi_jtag_dp_scan(struct swjdp_common *swjdp,
        arm_jtag_set_instr(jtag_info, instr, NULL);
 
        /* Add specified number of tck clocks before accessing memory bus */
-       if ((instr == DAP_IR_APACC) && ((reg_addr == AP_REG_DRW)||((reg_addr&0xF0) == AP_REG_BD0))&& (swjdp->memaccess_tck != 0))
+
+       /* REVISIT these TCK cycles should be *AFTER*  updating APACC, since
+        * they provide more time for the (MEM) AP to complete the read ...
+        * See "Minimum Response Time" for JTAG-DP, in the ADIv5 spec.
+        */
+       if ((instr == JTAG_DP_APACC)
+                       && ((reg_addr == AP_REG_DRW)
+                               || ((reg_addr & 0xF0) == AP_REG_BD0))
+                       && (swjdp->memaccess_tck != 0))
                jtag_add_runtest(swjdp->memaccess_tck, jtag_set_end_state(TAP_IDLE));
 
+       /* Scan out a read or write operation using some DP or AP register.
+        * For APACC access with any sticky error flag set, this is discarded.
+        */
        fields[0].tap = jtag_info->tap;
        fields[0].num_bits = 3;
        buf_set_u32(&out_addr_buf, 0, 3, ((reg_addr >> 1) & 0x6) | (RnW & 0x1));
        fields[0].out_value = &out_addr_buf;
        fields[0].in_value = ack;
 
+       /* NOTE: if we receive JTAG_ACK_WAIT, the previous operation did not
+        * complete; data we write is discarded, data we read is unpredictable.
+        * When overrun detect is active, STICKYORUN is set.
+        */
+
        fields[1].tap = jtag_info->tap;
        fields[1].num_bits = 32;
        fields[1].out_value = outvalue;
@@ -134,7 +167,14 @@ static int adi_jtag_dp_scan_u32(struct swjdp_common *swjdp,
        arm_jtag_set_instr(jtag_info, instr, NULL);
 
        /* Add specified number of tck clocks before accessing memory bus */
-       if ((instr == DAP_IR_APACC) && ((reg_addr == AP_REG_DRW)||((reg_addr&0xF0) == AP_REG_BD0))&& (swjdp->memaccess_tck != 0))
+
+       /* REVISIT these TCK cycles should be *AFTER*  updating APACC, since
+        * they provide more time for the (MEM) AP to complete the read ...
+        */
+       if ((instr == JTAG_DP_APACC)
+                       && ((reg_addr == AP_REG_DRW)
+                               || ((reg_addr & 0xF0) == AP_REG_BD0))
+                       && (swjdp->memaccess_tck != 0))
                jtag_add_runtest(swjdp->memaccess_tck, jtag_set_end_state(TAP_IDLE));
 
        fields[0].tap = jtag_info->tap;
@@ -172,15 +212,15 @@ static int scan_inout_check(struct swjdp_common *swjdp,
        adi_jtag_dp_scan(swjdp, instr, reg_addr, RnW, outvalue, NULL, NULL);
 
        if ((RnW == DPAP_READ) && (invalue != NULL))
-       {
-               adi_jtag_dp_scan(swjdp, DAP_IR_DPACC, DP_RDBUFF, DPAP_READ, 0, invalue, &swjdp->ack);
-       }
+               adi_jtag_dp_scan(swjdp, JTAG_DP_DPACC,
+                               DP_RDBUFF, DPAP_READ, 0, invalue, &swjdp->ack);
 
-       /* In TRANS_MODE_ATOMIC all DAP_IR_APACC transactions wait for ack = OK/FAULT and the check CTRL_STAT */
-       if ((instr == DAP_IR_APACC) && (swjdp->trans_mode == TRANS_MODE_ATOMIC))
-       {
+       /* In TRANS_MODE_ATOMIC all JTAG_DP_APACC transactions wait for
+        * ack = OK/FAULT and the check CTRL_STAT
+        */
+       if ((instr == JTAG_DP_APACC)
+                       && (swjdp->trans_mode == TRANS_MODE_ATOMIC))
                return swjdp_transaction_endcheck(swjdp);
-       }
 
        return ERROR_OK;
 }
@@ -189,18 +229,22 @@ static int scan_inout_check_u32(struct swjdp_common *swjdp,
                uint8_t instr, uint8_t reg_addr, uint8_t RnW,
                uint32_t outvalue, uint32_t *invalue)
 {
+       /* Issue the read or write */
        adi_jtag_dp_scan_u32(swjdp, instr, reg_addr, RnW, outvalue, NULL, NULL);
 
+       /* For reads,  collect posted value; RDBUFF has no other effect.
+        * Assumes read gets acked with OK/FAULT, and CTRL_STAT says "OK".
+        */
        if ((RnW == DPAP_READ) && (invalue != NULL))
-       {
-               adi_jtag_dp_scan_u32(swjdp, DAP_IR_DPACC, DP_RDBUFF, DPAP_READ, 0, invalue, &swjdp->ack);
-       }
+               adi_jtag_dp_scan_u32(swjdp, JTAG_DP_DPACC,
+                               DP_RDBUFF, DPAP_READ, 0, invalue, &swjdp->ack);
 
-       /* In TRANS_MODE_ATOMIC all DAP_IR_APACC transactions wait for ack = OK/FAULT and then check CTRL_STAT */
-       if ((instr == DAP_IR_APACC) && (swjdp->trans_mode == TRANS_MODE_ATOMIC))
-       {
+       /* In TRANS_MODE_ATOMIC all JTAG_DP_APACC transactions wait for
+        * ack = OK/FAULT and then check CTRL_STAT
+        */
+       if ((instr == JTAG_DP_APACC)
+                       && (swjdp->trans_mode == TRANS_MODE_ATOMIC))
                return swjdp_transaction_endcheck(swjdp);
-       }
 
        return ERROR_OK;
 }
@@ -214,7 +258,8 @@ int swjdp_transaction_endcheck(struct swjdp_common *swjdp)
 
 #if 0
        /* Danger!!!! BROKEN!!!! */
-       scan_inout_check_u32(swjdp, DAP_IR_DPACC, DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
+       scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+                       DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
        /* Danger!!!! BROKEN!!!! Why will jtag_execute_queue() fail here????
        R956 introduced the check on return value here and now Michael Schwingen reports
        that this code no longer works....
@@ -228,39 +273,50 @@ int swjdp_transaction_endcheck(struct swjdp_common *swjdp)
        /* Why??? second time it works??? */
 #endif
 
-       scan_inout_check_u32(swjdp, DAP_IR_DPACC, DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
+       /* Post CTRL/STAT read; discard any previous posted read value
+        * but collect its ACK status.
+        */
+       scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+                       DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
        if ((retval = jtag_execute_queue()) != ERROR_OK)
                return retval;
 
        swjdp->ack = swjdp->ack & 0x7;
 
-       if (swjdp->ack != 2)
+       /* common code path avoids calling timeval_ms() */
+       if (swjdp->ack != JTAG_ACK_OK_FAULT)
        {
                long long then = timeval_ms();
-               while (swjdp->ack != 2)
+
+               while (swjdp->ack != JTAG_ACK_OK_FAULT)
                {
-                       if (swjdp->ack == 1)
+                       if (swjdp->ack == JTAG_ACK_WAIT)
                        {
                                if ((timeval_ms()-then) > 1000)
                                {
-                                       LOG_WARNING("Timeout (1000ms) waiting for ACK = OK/FAULT in SWJDP transaction");
+                                       /* NOTE:  this would be a good spot
+                                        * to use JTAG_DP_ABORT.
+                                        */
+                                       LOG_WARNING("Timeout (1000ms) waiting "
+                                               "for ACK=OK/FAULT "
+                                               "in JTAG-DP transaction");
                                        return ERROR_JTAG_DEVICE_ERROR;
                                }
                        }
                        else
                        {
-                               LOG_WARNING("Invalid ACK in SWJDP transaction");
+                               LOG_WARNING("Invalid ACK %#x"
+                                               "in JTAG-DP transaction",
+                                               swjdp->ack);
                                return ERROR_JTAG_DEVICE_ERROR;
                        }
 
-                       scan_inout_check_u32(swjdp, DAP_IR_DPACC, DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
+                       scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+                                       DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
                        if ((retval = jtag_execute_queue()) != ERROR_OK)
                                return retval;
                        swjdp->ack = swjdp->ack & 0x7;
                }
-       } else
-       {
-               /* common code path avoids fn to timeval_ms() */
        }
 
        /* Check for STICKYERR and STICKYORUN */
@@ -279,14 +335,19 @@ int swjdp_transaction_endcheck(struct swjdp_common *swjdp)
                        /* Print information about last AHBAP access */
                        LOG_ERROR("AHBAP Cached values: dp_select 0x%" PRIx32 ", ap_csw 0x%" PRIx32 ", ap_tar 0x%" PRIx32 "", swjdp->dp_select_value, swjdp->ap_csw_value, swjdp->ap_tar_value);
                        if (ctrlstat & SSTICKYORUN)
-                               LOG_ERROR("SWJ-DP OVERRUN - check clock or reduce jtag speed");
+                               LOG_ERROR("JTAG-DP OVERRUN - "
+                                       "check clock or reduce jtag speed");
 
                        if (ctrlstat & SSTICKYERR)
-                               LOG_ERROR("SWJ-DP STICKY ERROR");
+                               LOG_ERROR("JTAG-DP STICKY ERROR");
 
                        /* Clear Sticky Error Bits */
-                       scan_inout_check_u32(swjdp, DAP_IR_DPACC, DP_CTRL_STAT, DPAP_WRITE, swjdp->dp_ctrl_stat | SSTICKYORUN | SSTICKYERR, NULL);
-                       scan_inout_check_u32(swjdp, DAP_IR_DPACC, DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
+                       scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+                                       DP_CTRL_STAT, DPAP_WRITE,
+                                       swjdp->dp_ctrl_stat | SSTICKYORUN
+                                               | SSTICKYERR, NULL);
+                       scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+                                       DP_CTRL_STAT, DPAP_READ, 0, &ctrlstat);
                        if ((retval = jtag_execute_queue()) != ERROR_OK)
                                return retval;
 
@@ -316,13 +377,15 @@ int swjdp_transaction_endcheck(struct swjdp_common *swjdp)
 static int dap_dp_write_reg(struct swjdp_common *swjdp,
                uint32_t value, uint8_t reg_addr)
 {
-       return scan_inout_check_u32(swjdp, DAP_IR_DPACC, reg_addr, DPAP_WRITE, value, NULL);
+       return scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+                       reg_addr, DPAP_WRITE, value, NULL);
 }
 
 static int dap_dp_read_reg(struct swjdp_common *swjdp,
                uint32_t *value, uint8_t reg_addr)
 {
-       return scan_inout_check_u32(swjdp, DAP_IR_DPACC, reg_addr, DPAP_READ, 0, value);
+       return scan_inout_check_u32(swjdp, JTAG_DP_DPACC,
+                       reg_addr, DPAP_READ, 0, value);
 }
 
 int dap_ap_select(struct swjdp_common *swjdp,uint8_t apsel)
@@ -360,7 +423,8 @@ static int dap_ap_write_reg(struct swjdp_common *swjdp,
                uint32_t reg_addr, uint8_t *out_value_buf)
 {
        dap_dp_bankselect(swjdp, reg_addr);
-       scan_inout_check(swjdp, DAP_IR_APACC, reg_addr, DPAP_WRITE, out_value_buf, NULL);
+       scan_inout_check(swjdp, JTAG_DP_APACC, reg_addr,
+                       DPAP_WRITE, out_value_buf, NULL);
 
        return ERROR_OK;
 }
@@ -371,7 +435,8 @@ int dap_ap_write_reg_u32(struct swjdp_common *swjdp, uint32_t reg_addr, uint32_t
 
        buf_set_u32(out_value_buf, 0, 32, value);
        dap_dp_bankselect(swjdp, reg_addr);
-       scan_inout_check(swjdp, DAP_IR_APACC, reg_addr, DPAP_WRITE, out_value_buf, NULL);
+       scan_inout_check(swjdp, JTAG_DP_APACC, reg_addr,
+                       DPAP_WRITE, out_value_buf, NULL);
 
        return ERROR_OK;
 }
@@ -379,7 +444,8 @@ int dap_ap_write_reg_u32(struct swjdp_common *swjdp, uint32_t reg_addr, uint32_t
 int dap_ap_read_reg_u32(struct swjdp_common *swjdp, uint32_t reg_addr, uint32_t *value)
 {
        dap_dp_bankselect(swjdp, reg_addr);
-       scan_inout_check_u32(swjdp, DAP_IR_APACC, reg_addr, DPAP_READ, 0, value);
+       scan_inout_check_u32(swjdp, JTAG_DP_APACC, reg_addr,
+                       DPAP_READ, 0, value);
 
        return ERROR_OK;
 }
@@ -758,15 +824,25 @@ int mem_ap_read_buf_u32(struct swjdp_common *swjdp, uint8_t *buffer, int count,
                dap_setup_accessport(swjdp, CSW_32BIT | CSW_ADDRINC_SINGLE, address);
 
                /* Scan out first read */
-               adi_jtag_dp_scan(swjdp, DAP_IR_APACC, AP_REG_DRW, DPAP_READ, 0, NULL, NULL);
+               adi_jtag_dp_scan(swjdp, JTAG_DP_APACC, AP_REG_DRW,
+                               DPAP_READ, 0, NULL, NULL);
                for (readcount = 0; readcount < blocksize - 1; readcount++)
                {
-                       /* Scan out read instruction and scan in previous value */
-                       adi_jtag_dp_scan(swjdp, DAP_IR_APACC, AP_REG_DRW, DPAP_READ, 0, buffer + 4 * readcount, &swjdp->ack);
+                       /* Scan out next read; scan in posted value for the
+                        * previous one.  Assumes read is acked "OK/FAULT",
+                        * and CTRL_STAT says that meant "OK".
+                        */
+                       adi_jtag_dp_scan(swjdp, JTAG_DP_APACC, AP_REG_DRW,
+                                       DPAP_READ, 0, buffer + 4 * readcount,
+                                       &swjdp->ack);
                }
 
-               /* Scan in last value */
-               adi_jtag_dp_scan(swjdp, DAP_IR_DPACC, DP_RDBUFF, DPAP_READ, 0, buffer + 4 * readcount, &swjdp->ack);
+               /* Scan in last posted value; RDBUFF has no other effect,
+                * assuming ack is OK/FAULT and CTRL_STAT says "OK".
+                */
+               adi_jtag_dp_scan(swjdp, JTAG_DP_DPACC, DP_RDBUFF,
+                               DPAP_READ, 0, buffer + 4 * readcount,
+                               &swjdp->ack);
                if (swjdp_transaction_endcheck(swjdp) == ERROR_OK)
                {
                        wcount = wcount - blocksize;

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)