aice: Always setup SDP basic mode
[openocd.git] / src / jtag / aice / aice_usb.c
index 8a5b3112e817f383b9fe78bb9aa53790042fd2ae..962219f79c0ba00f8ac248b00c451217d99a3d7b 100644 (file)
@@ -60,7 +60,10 @@ static void aice_pack_htdc(uint8_t cmd_code, uint8_t extra_word_length,
        usb_out_buffer[1] = extra_word_length;
        usb_out_buffer[2] = (uint8_t)(address & 0xFF);
        if (access_endian == AICE_BIG_ENDIAN) {
-               *(uint32_t *)(usb_out_buffer + 3) = word;
+               usb_out_buffer[6] = (uint8_t)((word >> 24) & 0xFF);
+               usb_out_buffer[5] = (uint8_t)((word >> 16) & 0xFF);
+               usb_out_buffer[4] = (uint8_t)((word >> 8) & 0xFF);
+               usb_out_buffer[3] = (uint8_t)(word & 0xFF);
        } else {
                usb_out_buffer[3] = (uint8_t)((word >> 24) & 0xFF);
                usb_out_buffer[4] = (uint8_t)((word >> 16) & 0xFF);
@@ -100,7 +103,10 @@ static void aice_pack_htdmc(uint8_t cmd_code, uint8_t target_id,
        usb_out_buffer[2] = extra_word_length;
        usb_out_buffer[3] = (uint8_t)(address & 0xFF);
        if (access_endian == AICE_BIG_ENDIAN) {
-               *(uint32_t *)(usb_out_buffer + 4) = word;
+               usb_out_buffer[7] = (uint8_t)((word >> 24) & 0xFF);
+               usb_out_buffer[6] = (uint8_t)((word >> 16) & 0xFF);
+               usb_out_buffer[5] = (uint8_t)((word >> 8) & 0xFF);
+               usb_out_buffer[4] = (uint8_t)(word & 0xFF);
        } else {
                usb_out_buffer[4] = (uint8_t)((word >> 24) & 0xFF);
                usb_out_buffer[5] = (uint8_t)((word >> 16) & 0xFF);
@@ -121,7 +127,10 @@ static void aice_pack_htdmc_multiple_data(uint8_t cmd_code, uint8_t target_id,
        uint8_t i;
        for (i = 0 ; i < num_of_words ; i++, word++) {
                if (access_endian == AICE_BIG_ENDIAN) {
-                       *(uint32_t *)(usb_out_buffer + 4 + i * 4) = *word;
+                       usb_out_buffer[7 + i * 4] = (uint8_t)((*word >> 24) & 0xFF);
+                       usb_out_buffer[6 + i * 4] = (uint8_t)((*word >> 16) & 0xFF);
+                       usb_out_buffer[5 + i * 4] = (uint8_t)((*word >> 8) & 0xFF);
+                       usb_out_buffer[4 + i * 4] = (uint8_t)(*word & 0xFF);
                } else {
                        usb_out_buffer[4 + i * 4] = (uint8_t)((*word >> 24) & 0xFF);
                        usb_out_buffer[5 + i * 4] = (uint8_t)((*word >> 16) & 0xFF);
@@ -144,7 +153,10 @@ static void aice_pack_htdmd(uint8_t cmd_code, uint8_t target_id,
        usb_out_buffer[6] = (uint8_t)((address >> 8) & 0xFF);
        usb_out_buffer[7] = (uint8_t)(address & 0xFF);
        if (access_endian == AICE_BIG_ENDIAN) {
-               *(uint32_t *)(usb_out_buffer + 8) = word;
+               usb_out_buffer[11] = (uint8_t)((word >> 24) & 0xFF);
+               usb_out_buffer[10] = (uint8_t)((word >> 16) & 0xFF);
+               usb_out_buffer[9] = (uint8_t)((word >> 8) & 0xFF);
+               usb_out_buffer[8] = (uint8_t)(word & 0xFF);
        } else {
                usb_out_buffer[8] = (uint8_t)((word >> 24) & 0xFF);
                usb_out_buffer[9] = (uint8_t)((word >> 16) & 0xFF);
@@ -154,7 +166,7 @@ static void aice_pack_htdmd(uint8_t cmd_code, uint8_t target_id,
 }
 
 static void aice_pack_htdmd_multiple_data(uint8_t cmd_code, uint8_t target_id,
-               uint8_t extra_word_length, uint32_t address, const uint32_t *word,
+               uint8_t extra_word_length, uint32_t address, const uint8_t *word,
                enum aice_target_endian access_endian)
 {
        usb_out_buffer[0] = cmd_code;
@@ -170,14 +182,17 @@ static void aice_pack_htdmd_multiple_data(uint8_t cmd_code, uint8_t target_id,
        /* num_of_words may be over 0xFF, so use uint32_t */
        uint32_t num_of_words = extra_word_length + 1;
 
-       for (i = 0 ; i < num_of_words ; i++, word++) {
+       for (i = 0 ; i < num_of_words ; i++, word += 4) {
                if (access_endian == AICE_BIG_ENDIAN) {
-                       *(uint32_t *)(usb_out_buffer + 8 + i * 4) = *word;
+                       usb_out_buffer[11 + i * 4] = word[3];
+                       usb_out_buffer[10 + i * 4] = word[2];
+                       usb_out_buffer[9 + i * 4] = word[1];
+                       usb_out_buffer[8 + i * 4] = word[0];
                } else {
-                       usb_out_buffer[8 + i * 4] = (uint8_t)((*word >> 24) & 0xFF);
-                       usb_out_buffer[9 + i * 4] = (uint8_t)((*word >> 16) & 0xFF);
-                       usb_out_buffer[10 + i * 4] = (uint8_t)((*word >> 8) & 0xFF);
-                       usb_out_buffer[11 + i * 4] = (uint8_t)(*word & 0xFF);
+                       usb_out_buffer[8 + i * 4] = word[3];
+                       usb_out_buffer[9 + i * 4] = word[2];
+                       usb_out_buffer[10 + i * 4] = word[1];
+                       usb_out_buffer[11 + i * 4] = word[0];
                }
        }
 }
@@ -189,7 +204,10 @@ static void aice_unpack_dtha(uint8_t *cmd_ack_code, uint8_t *extra_word_length,
        *extra_word_length = usb_in_buffer[1];
 
        if (access_endian == AICE_BIG_ENDIAN) {
-               *word = *(uint32_t *)(usb_in_buffer + 2);
+               *word = (usb_in_buffer[5] << 24) |
+                       (usb_in_buffer[4] << 16) |
+                       (usb_in_buffer[3] << 8) |
+                       (usb_in_buffer[2]);
        } else {
                *word = (usb_in_buffer[2] << 24) |
                        (usb_in_buffer[3] << 16) |
@@ -208,7 +226,10 @@ static void aice_unpack_dtha_multiple_data(uint8_t *cmd_ack_code,
        uint8_t i;
        for (i = 0 ; i < num_of_words ; i++, word++) {
                if (access_endian == AICE_BIG_ENDIAN) {
-                       *word = *(uint32_t *)(usb_in_buffer + 2 + i * 4);
+                       *word = (usb_in_buffer[5 + i * 4] << 24) |
+                               (usb_in_buffer[4 + i * 4] << 16) |
+                               (usb_in_buffer[3 + i * 4] << 8) |
+                               (usb_in_buffer[2 + i * 4]);
                } else {
                        *word = (usb_in_buffer[2 + i * 4] << 24) |
                                (usb_in_buffer[3 + i * 4] << 16) |
@@ -232,7 +253,10 @@ static void aice_unpack_dthma(uint8_t *cmd_ack_code, uint8_t *target_id,
        *target_id = usb_in_buffer[1];
        *extra_word_length = usb_in_buffer[2];
        if (access_endian == AICE_BIG_ENDIAN) {
-               *word = *(uint32_t *)(usb_in_buffer + 4);
+               *word = (usb_in_buffer[7] << 24) |
+                       (usb_in_buffer[6] << 16) |
+                       (usb_in_buffer[5] << 8) |
+                       (usb_in_buffer[4]);
        } else {
                *word = (usb_in_buffer[4] << 24) |
                        (usb_in_buffer[5] << 16) |
@@ -242,33 +266,39 @@ static void aice_unpack_dthma(uint8_t *cmd_ack_code, uint8_t *target_id,
 }
 
 static void aice_unpack_dthma_multiple_data(uint8_t *cmd_ack_code,
-               uint8_t *target_id, uint8_t *extra_word_length, uint32_t *word,
+               uint8_t *target_id, uint8_t *extra_word_length, uint8_t *word,
                enum aice_target_endian access_endian)
 {
        *cmd_ack_code = usb_in_buffer[0];
        *target_id = usb_in_buffer[1];
        *extra_word_length = usb_in_buffer[2];
        if (access_endian == AICE_BIG_ENDIAN) {
-               *word = *(uint32_t *)(usb_in_buffer + 4);
+               word[0] = usb_in_buffer[4];
+               word[1] = usb_in_buffer[5];
+               word[2] = usb_in_buffer[6];
+               word[3] = usb_in_buffer[7];
        } else {
-               *word = (usb_in_buffer[4] << 24) |
-                       (usb_in_buffer[5] << 16) |
-                       (usb_in_buffer[6] << 8) |
-                       (usb_in_buffer[7]);
+               word[0] = usb_in_buffer[7];
+               word[1] = usb_in_buffer[6];
+               word[2] = usb_in_buffer[5];
+               word[3] = usb_in_buffer[4];
        }
-       word++;
+       word += 4;
 
        uint8_t i;
        for (i = 0; i < *extra_word_length; i++) {
                if (access_endian == AICE_BIG_ENDIAN) {
-                       *word = *(uint32_t *)(usb_in_buffer + 8 + i * 4);
+                       word[0] = usb_in_buffer[8 + i * 4];
+                       word[1] = usb_in_buffer[9 + i * 4];
+                       word[2] = usb_in_buffer[10 + i * 4];
+                       word[3] = usb_in_buffer[11 + i * 4];
                } else {
-                       *word = (usb_in_buffer[8 + i * 4] << 24) |
-                               (usb_in_buffer[9 + i * 4] << 16) |
-                               (usb_in_buffer[10 + i * 4] << 8) |
-                               (usb_in_buffer[11 + i * 4]);
+                       word[0] = usb_in_buffer[11 + i * 4];
+                       word[1] = usb_in_buffer[10 + i * 4];
+                       word[2] = usb_in_buffer[9 + i * 4];
+                       word[3] = usb_in_buffer[8 + i * 4];
                }
-               word++;
+               word += 4;
        }
 }
 
@@ -395,6 +425,24 @@ static void aice_usb_packet_append(uint8_t *out_buffer, int out_length,
 
 /***************************************************************************/
 /* AICE commands */
+static int aice_edm_reset(void)
+{
+       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+               return ERROR_FAIL;
+
+       /* turn off FASTMODE */
+       uint32_t pin_status;
+       if (aice_read_ctrl(AICE_READ_CTRL_GET_JTAG_PIN_STATUS, &pin_status)
+                       != ERROR_OK)
+               return ERROR_FAIL;
+
+       if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status & (~0x2))
+                       != ERROR_OK)
+               return ERROR_FAIL;
+
+       return ERROR_OK;
+}
+
 static int aice_scan_chain(uint32_t *id_codes, uint8_t *num_of_ids)
 {
        int result;
@@ -432,7 +480,7 @@ static int aice_scan_chain(uint32_t *id_codes, uint8_t *num_of_ids)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -563,7 +611,7 @@ int aice_read_dtr(uint8_t target_id, uint32_t *data)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -613,7 +661,7 @@ int aice_write_dtr(uint8_t target_id, uint32_t data)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -663,7 +711,7 @@ int aice_read_misc(uint8_t target_id, uint32_t address, uint32_t *data)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -713,7 +761,7 @@ int aice_write_misc(uint8_t target_id, uint32_t address, uint32_t data)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -763,7 +811,7 @@ int aice_read_edmsr(uint8_t target_id, uint32_t address, uint32_t *data)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -813,7 +861,7 @@ int aice_write_edmsr(uint8_t target_id, uint32_t address, uint32_t data)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -889,7 +937,7 @@ static int aice_write_dim(uint8_t target_id, uint32_t *word, uint8_t num_of_word
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -938,7 +986,7 @@ static int aice_do_execute(uint8_t target_id)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -989,7 +1037,7 @@ int aice_write_mem_b(uint8_t target_id, uint32_t address, uint32_t data)
                                        return ERROR_FAIL;
 
                                /* clear timeout and retry */
-                               if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                               if (aice_edm_reset() != ERROR_OK)
                                        return ERROR_FAIL;
 
                                retry_times++;
@@ -1041,7 +1089,7 @@ int aice_write_mem_h(uint8_t target_id, uint32_t address, uint32_t data)
                                        return ERROR_FAIL;
 
                                /* clear timeout and retry */
-                               if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                               if (aice_edm_reset() != ERROR_OK)
                                        return ERROR_FAIL;
 
                                retry_times++;
@@ -1093,7 +1141,7 @@ int aice_write_mem(uint8_t target_id, uint32_t address, uint32_t data)
                                        return ERROR_FAIL;
 
                                /* clear timeout and retry */
-                               if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                               if (aice_edm_reset() != ERROR_OK)
                                        return ERROR_FAIL;
 
                                retry_times++;
@@ -1104,7 +1152,7 @@ int aice_write_mem(uint8_t target_id, uint32_t address, uint32_t data)
        return ERROR_OK;
 }
 
-int aice_fastread_mem(uint8_t target_id, uint32_t *word, uint32_t num_of_words)
+int aice_fastread_mem(uint8_t target_id, uint8_t *word, uint32_t num_of_words)
 {
        int result;
        int retry_times = 0;
@@ -1142,7 +1190,7 @@ int aice_fastread_mem(uint8_t target_id, uint32_t *word, uint32_t num_of_words)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -1152,7 +1200,7 @@ int aice_fastread_mem(uint8_t target_id, uint32_t *word, uint32_t num_of_words)
        return ERROR_OK;
 }
 
-int aice_fastwrite_mem(uint8_t target_id, const uint32_t *word, uint32_t num_of_words)
+int aice_fastwrite_mem(uint8_t target_id, const uint8_t *word, uint32_t num_of_words)
 {
        int result;
        int retry_times = 0;
@@ -1190,7 +1238,7 @@ int aice_fastwrite_mem(uint8_t target_id, const uint32_t *word, uint32_t num_of_
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -1240,7 +1288,7 @@ int aice_read_mem_b(uint8_t target_id, uint32_t address, uint32_t *data)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -1290,7 +1338,7 @@ int aice_read_mem_h(uint8_t target_id, uint32_t address, uint32_t *data)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -1341,7 +1389,7 @@ int aice_read_mem(uint8_t target_id, uint32_t address, uint32_t *data)
                                return ERROR_FAIL;
 
                        /* clear timeout and retry */
-                       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+                       if (aice_edm_reset() != ERROR_OK)
                                return ERROR_FAIL;
 
                        retry_times++;
@@ -1460,6 +1508,9 @@ static int aice_check_dbger(uint32_t expect_status)
                        return ERROR_OK;
                }
 
+               if ((i % 30) == 0)
+                       keep_alive();
+
                long long then = 0;
                if (i == aice_count_to_check_dbger)
                        then = timeval_ms();
@@ -1887,14 +1938,6 @@ get_delay:
        return ERROR_OK;
 }
 
-static int aice_edm_reset(void)
-{
-       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
-               return ERROR_FAIL;
-
-       return ERROR_OK;
-}
-
 static int aice_usb_set_clock(int set_clock)
 {
        if (aice_write_ctrl(AICE_WRITE_CTRL_TCK_CONTROL,
@@ -2334,9 +2377,10 @@ static int aice_usb_state(enum aice_target_state_s *state)
 
 static int aice_usb_reset(void)
 {
-       if (aice_write_ctrl(AICE_WRITE_CTRL_CLEAR_TIMEOUT_STATUS, 0x1) != ERROR_OK)
+       if (aice_edm_reset() != ERROR_OK)
                return ERROR_FAIL;
 
+       /* issue TRST */
        if (custom_trst_script == NULL) {
                if (aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_CONTROL,
                                        AICE_JTAG_PIN_CONTROL_TRST) != ERROR_OK)
@@ -2849,7 +2893,7 @@ static int aice_bulk_read_mem(uint32_t addr, uint32_t count, uint8_t *buffer)
                if (aice_write_misc(current_target_id, NDS_EDM_MISC_SBAR, addr) != ERROR_OK)
                        return ERROR_FAIL;
 
-               if (aice_fastread_mem(current_target_id, (uint32_t *)buffer,
+               if (aice_fastread_mem(current_target_id, buffer,
                                        packet_size) != ERROR_OK)
                        return ERROR_FAIL;
 
@@ -2873,7 +2917,7 @@ static int aice_bulk_write_mem(uint32_t addr, uint32_t count, const uint8_t *buf
                if (aice_write_misc(current_target_id, NDS_EDM_MISC_SBAR, addr | 1) != ERROR_OK)
                        return ERROR_FAIL;
 
-               if (aice_fastwrite_mem(current_target_id, (const uint32_t *)buffer,
+               if (aice_fastwrite_mem(current_target_id, buffer,
                                        packet_size) != ERROR_OK)
                        return ERROR_FAIL;
 

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)