cortex_m: Do additional initialization during reset 88/2088/8
authorAndrey Smirnov <andrew.smirnov@gmail.com>
Thu, 3 Apr 2014 21:59:44 +0000 (14:59 -0700)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Sat, 28 Jun 2014 09:30:09 +0000 (09:30 +0000)
SAM4L requires additional steps to be taken right after SYSRESETREQ is
issued in order to function robustly:

       - CMSIS-DAP DAP driver needs to explicitly check for sticky bit
         errors since it is possible for adapter to perform successful
         write opration, report no errors and then, under the hood, do
         some other things that will result in sticky bit being set.

       - Debugger needs to wait for security system to finish
         intialization and assert CDBGPWRUPACK before proceeding

This change is related to commit http://openocd.zylin.com/#/c/1995/

Change-Id: I741c95a809bfd60d930cec9482239e4796a62326
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Reviewed-on: http://openocd.zylin.com/2088
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-by: Andrey Yurovsky <yurovsky@gmail.com>
src/target/adi_v5_cmsis_dap.c
src/target/cortex_m.c
tcl/target/at91sam4lXX.cfg

index e830089f478ec70f240bbc457431df685d921fed..9b591464394c18925d4f68887e48a2df81511c82 100644 (file)
@@ -167,10 +167,38 @@ static int (cmsis_dap_queue_ap_write)(struct adiv5_dap *dap, unsigned reg, uint3
 /** Executes all queued DAP operations. */
 static int cmsis_dap_run(struct adiv5_dap *dap)
 {
-       LOG_DEBUG("CMSIS-ADI: cmsis_dap_run");
+       LOG_DEBUG(" ");
        /* FIXME: for now the CMSIS-DAP interface hard-wires a zero-size queue. */
+       int ret;
+       uint32_t ctrlstat;
 
-       return ERROR_OK;
+       /*
+         Some debug dongles do more than asked for(e.g. EDBG from
+         Atmel) behind the scene and issuing an AP write
+         may result in more than just APACC SWD transaction, which in
+         turn can possibly set sticky error bit in CTRL/STAT register
+         of the DP(an example would be writing SYSRESETREQ to AIRCR).
+         Such adapters may interpret CMSIS-DAP secification
+         differently and not guarantee to be report those failures
+         via status byte of the return USB packet from CMSIS-DAP, so
+         we need to check CTRL/STAT and if that happens to clear it.
+       */
+       ret = cmsis_dap_queue_dp_read(dap, DP_CTRL_STAT, &ctrlstat);
+       if (ret != ERROR_OK) {
+               LOG_ERROR("Failed to read CTRL/STAT register");
+               return ret;
+       }
+
+       if (ctrlstat & SSTICKYERR) {
+               LOG_WARNING("SSTICKYERR was set, clearing it");
+               ret = cmsis_dap_clear_sticky_errors(dap);
+               if (ret != ERROR_OK) {
+                       LOG_ERROR("Failed to clear sticky errors");
+                       return ret;
+               }
+       }
+
+       return ret;
 }
 
 const struct dap_ops cmsis_dap_ops = {
index dc8d344401abe7d83f0db75d7b379b4f45489f61..103ce502a1820bf9f7f9a2ec31e4c80b7a6f21d6 100644 (file)
@@ -1069,6 +1069,19 @@ static int cortex_m_assert_reset(struct target *target)
                                "handler to reset any peripherals or configure hardware srst support.");
                }
 
+               /*
+                 SAM4L needs to execute security initalization
+                 startup sequence before AP access would be enabled.
+                 During the intialization CDBGPWRUPACK is pulled low and we
+                 need to wait for it to be set to 1 again.
+               */
+               retval = dap_dp_poll_register(swjdp, DP_CTRL_STAT,
+                                             CDBGPWRUPACK, CDBGPWRUPACK, 100);
+               if (retval != ERROR_OK) {
+                       LOG_ERROR("Failed waitnig for CDBGPWRUPACK");
+                       return ERROR_FAIL;
+               }
+
                {
                        /* I do not know why this is necessary, but it
                         * fixes strange effects (step/resume cause NMI
index 77ff98a8c95eac2dc038d654683d1602e879a8ba..93799a2399532f5c95838108bcfc4da516fa7527 100644 (file)
@@ -5,7 +5,3 @@ source [find target/at91sam4XXX.cfg]
 
 set _FLASHNAME $_CHIPNAME.flash
 flash bank $_FLASHNAME at91sam4l 0x00000000 0 1 1 $_TARGETNAME
-
-# if srst is not fitted use VECTRESET to perform a soft reset
-# this will only reset the core, not the peripherals
-cortex_m reset_config vectreset

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)