Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/daplink/cmsis-dap/SW_DP.c@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 2 | * Copyright (c) 2013-2017 ARM Limited. All rights reserved. |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Licensed under the Apache License, Version 2.0 (the License); you may |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 15 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 16 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 17 | * |
Pawel Zarembski |
0:01f31e923fe2 | 18 | * ---------------------------------------------------------------------- |
Pawel Zarembski |
0:01f31e923fe2 | 19 | * |
Pawel Zarembski |
0:01f31e923fe2 | 20 | * $Date: 1. December 2017 |
Pawel Zarembski |
0:01f31e923fe2 | 21 | * $Revision: V2.0.0 |
Pawel Zarembski |
0:01f31e923fe2 | 22 | * |
Pawel Zarembski |
0:01f31e923fe2 | 23 | * Project: CMSIS-DAP Source |
Pawel Zarembski |
0:01f31e923fe2 | 24 | * Title: SW_DP.c CMSIS-DAP SW DP I/O |
Pawel Zarembski |
0:01f31e923fe2 | 25 | * |
Pawel Zarembski |
0:01f31e923fe2 | 26 | *---------------------------------------------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 27 | |
Pawel Zarembski |
0:01f31e923fe2 | 28 | #include "DAP_config.h" |
Pawel Zarembski |
0:01f31e923fe2 | 29 | #include "DAP.h" |
Pawel Zarembski |
0:01f31e923fe2 | 30 | |
Pawel Zarembski |
0:01f31e923fe2 | 31 | |
Pawel Zarembski |
0:01f31e923fe2 | 32 | // SW Macros |
Pawel Zarembski |
0:01f31e923fe2 | 33 | |
Pawel Zarembski |
0:01f31e923fe2 | 34 | #define PIN_SWCLK_SET PIN_SWCLK_TCK_SET |
Pawel Zarembski |
0:01f31e923fe2 | 35 | #define PIN_SWCLK_CLR PIN_SWCLK_TCK_CLR |
Pawel Zarembski |
0:01f31e923fe2 | 36 | |
Pawel Zarembski |
0:01f31e923fe2 | 37 | #define SW_CLOCK_CYCLE() \ |
Pawel Zarembski |
0:01f31e923fe2 | 38 | PIN_SWCLK_CLR(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 39 | PIN_DELAY(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 40 | PIN_SWCLK_SET(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 41 | PIN_DELAY() |
Pawel Zarembski |
0:01f31e923fe2 | 42 | |
Pawel Zarembski |
0:01f31e923fe2 | 43 | #define SW_WRITE_BIT(bit) \ |
Pawel Zarembski |
0:01f31e923fe2 | 44 | PIN_SWDIO_OUT(bit); \ |
Pawel Zarembski |
0:01f31e923fe2 | 45 | PIN_SWCLK_CLR(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 46 | PIN_DELAY(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 47 | PIN_SWCLK_SET(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 48 | PIN_DELAY() |
Pawel Zarembski |
0:01f31e923fe2 | 49 | |
Pawel Zarembski |
0:01f31e923fe2 | 50 | #define SW_READ_BIT(bit) \ |
Pawel Zarembski |
0:01f31e923fe2 | 51 | PIN_SWCLK_CLR(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 52 | PIN_DELAY(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 53 | bit = PIN_SWDIO_IN(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 54 | PIN_SWCLK_SET(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 55 | PIN_DELAY() |
Pawel Zarembski |
0:01f31e923fe2 | 56 | |
Pawel Zarembski |
0:01f31e923fe2 | 57 | #define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) |
Pawel Zarembski |
0:01f31e923fe2 | 58 | |
Pawel Zarembski |
0:01f31e923fe2 | 59 | |
Pawel Zarembski |
0:01f31e923fe2 | 60 | // Generate SWJ Sequence |
Pawel Zarembski |
0:01f31e923fe2 | 61 | // count: sequence bit count |
Pawel Zarembski |
0:01f31e923fe2 | 62 | // data: pointer to sequence bit data |
Pawel Zarembski |
0:01f31e923fe2 | 63 | // return: none |
Pawel Zarembski |
0:01f31e923fe2 | 64 | #if ((DAP_SWD != 0) || (DAP_JTAG != 0)) |
Pawel Zarembski |
0:01f31e923fe2 | 65 | void SWJ_Sequence (uint32_t count, const uint8_t *data) { |
Pawel Zarembski |
0:01f31e923fe2 | 66 | uint32_t val; |
Pawel Zarembski |
0:01f31e923fe2 | 67 | uint32_t n; |
Pawel Zarembski |
0:01f31e923fe2 | 68 | |
Pawel Zarembski |
0:01f31e923fe2 | 69 | val = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 70 | n = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 71 | while (count--) { |
Pawel Zarembski |
0:01f31e923fe2 | 72 | if (n == 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 73 | val = *data++; |
Pawel Zarembski |
0:01f31e923fe2 | 74 | n = 8U; |
Pawel Zarembski |
0:01f31e923fe2 | 75 | } |
Pawel Zarembski |
0:01f31e923fe2 | 76 | if (val & 1U) { |
Pawel Zarembski |
0:01f31e923fe2 | 77 | PIN_SWDIO_TMS_SET(); |
Pawel Zarembski |
0:01f31e923fe2 | 78 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 79 | PIN_SWDIO_TMS_CLR(); |
Pawel Zarembski |
0:01f31e923fe2 | 80 | } |
Pawel Zarembski |
0:01f31e923fe2 | 81 | SW_CLOCK_CYCLE(); |
Pawel Zarembski |
0:01f31e923fe2 | 82 | val >>= 1; |
Pawel Zarembski |
0:01f31e923fe2 | 83 | n--; |
Pawel Zarembski |
0:01f31e923fe2 | 84 | } |
Pawel Zarembski |
0:01f31e923fe2 | 85 | } |
Pawel Zarembski |
0:01f31e923fe2 | 86 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 87 | |
Pawel Zarembski |
0:01f31e923fe2 | 88 | |
Pawel Zarembski |
0:01f31e923fe2 | 89 | // Generate SWD Sequence |
Pawel Zarembski |
0:01f31e923fe2 | 90 | // info: sequence information |
Pawel Zarembski |
0:01f31e923fe2 | 91 | // swdo: pointer to SWDIO generated data |
Pawel Zarembski |
0:01f31e923fe2 | 92 | // swdi: pointer to SWDIO captured data |
Pawel Zarembski |
0:01f31e923fe2 | 93 | // return: none |
Pawel Zarembski |
0:01f31e923fe2 | 94 | #if (DAP_SWD != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 95 | void SWD_Sequence (uint32_t info, const uint8_t *swdo, uint8_t *swdi) { |
Pawel Zarembski |
0:01f31e923fe2 | 96 | uint32_t val; |
Pawel Zarembski |
0:01f31e923fe2 | 97 | uint32_t bit; |
Pawel Zarembski |
0:01f31e923fe2 | 98 | uint32_t n, k; |
Pawel Zarembski |
0:01f31e923fe2 | 99 | |
Pawel Zarembski |
0:01f31e923fe2 | 100 | n = info & SWD_SEQUENCE_CLK; |
Pawel Zarembski |
0:01f31e923fe2 | 101 | if (n == 0U) { |
Pawel Zarembski |
0:01f31e923fe2 | 102 | n = 64U; |
Pawel Zarembski |
0:01f31e923fe2 | 103 | } |
Pawel Zarembski |
0:01f31e923fe2 | 104 | |
Pawel Zarembski |
0:01f31e923fe2 | 105 | if (info & SWD_SEQUENCE_DIN) { |
Pawel Zarembski |
0:01f31e923fe2 | 106 | while (n) { |
Pawel Zarembski |
0:01f31e923fe2 | 107 | val = 0U; |
Pawel Zarembski |
0:01f31e923fe2 | 108 | for (k = 8U; k && n; k--, n--) { |
Pawel Zarembski |
0:01f31e923fe2 | 109 | SW_READ_BIT(bit); |
Pawel Zarembski |
0:01f31e923fe2 | 110 | val >>= 1; |
Pawel Zarembski |
0:01f31e923fe2 | 111 | val |= bit << 7; |
Pawel Zarembski |
0:01f31e923fe2 | 112 | } |
Pawel Zarembski |
0:01f31e923fe2 | 113 | val >>= k; |
Pawel Zarembski |
0:01f31e923fe2 | 114 | *swdi++ = (uint8_t)val; |
Pawel Zarembski |
0:01f31e923fe2 | 115 | } |
Pawel Zarembski |
0:01f31e923fe2 | 116 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 117 | while (n) { |
Pawel Zarembski |
0:01f31e923fe2 | 118 | val = *swdo++; |
Pawel Zarembski |
0:01f31e923fe2 | 119 | for (k = 8U; k && n; k--, n--) { |
Pawel Zarembski |
0:01f31e923fe2 | 120 | SW_WRITE_BIT(val); |
Pawel Zarembski |
0:01f31e923fe2 | 121 | val >>= 1; |
Pawel Zarembski |
0:01f31e923fe2 | 122 | } |
Pawel Zarembski |
0:01f31e923fe2 | 123 | } |
Pawel Zarembski |
0:01f31e923fe2 | 124 | } |
Pawel Zarembski |
0:01f31e923fe2 | 125 | } |
Pawel Zarembski |
0:01f31e923fe2 | 126 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 127 | |
Pawel Zarembski |
0:01f31e923fe2 | 128 | |
Pawel Zarembski |
0:01f31e923fe2 | 129 | #if (DAP_SWD != 0) |
Pawel Zarembski |
0:01f31e923fe2 | 130 | |
Pawel Zarembski |
0:01f31e923fe2 | 131 | |
Pawel Zarembski |
0:01f31e923fe2 | 132 | // SWD Transfer I/O |
Pawel Zarembski |
0:01f31e923fe2 | 133 | // request: A[3:2] RnW APnDP |
Pawel Zarembski |
0:01f31e923fe2 | 134 | // data: DATA[31:0] |
Pawel Zarembski |
0:01f31e923fe2 | 135 | // return: ACK[2:0] |
Pawel Zarembski |
0:01f31e923fe2 | 136 | #define SWD_TransferFunction(speed) /**/ \ |
Pawel Zarembski |
0:01f31e923fe2 | 137 | static uint8_t SWD_Transfer##speed (uint32_t request, uint32_t *data) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 138 | uint32_t ack; \ |
Pawel Zarembski |
0:01f31e923fe2 | 139 | uint32_t bit; \ |
Pawel Zarembski |
0:01f31e923fe2 | 140 | uint32_t val; \ |
Pawel Zarembski |
0:01f31e923fe2 | 141 | uint32_t parity; \ |
Pawel Zarembski |
0:01f31e923fe2 | 142 | \ |
Pawel Zarembski |
0:01f31e923fe2 | 143 | uint32_t n; \ |
Pawel Zarembski |
0:01f31e923fe2 | 144 | \ |
Pawel Zarembski |
0:01f31e923fe2 | 145 | /* Packet Request */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 146 | parity = 0U; \ |
Pawel Zarembski |
0:01f31e923fe2 | 147 | SW_WRITE_BIT(1U); /* Start Bit */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 148 | bit = request >> 0; \ |
Pawel Zarembski |
0:01f31e923fe2 | 149 | SW_WRITE_BIT(bit); /* APnDP Bit */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 150 | parity += bit; \ |
Pawel Zarembski |
0:01f31e923fe2 | 151 | bit = request >> 1; \ |
Pawel Zarembski |
0:01f31e923fe2 | 152 | SW_WRITE_BIT(bit); /* RnW Bit */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 153 | parity += bit; \ |
Pawel Zarembski |
0:01f31e923fe2 | 154 | bit = request >> 2; \ |
Pawel Zarembski |
0:01f31e923fe2 | 155 | SW_WRITE_BIT(bit); /* A2 Bit */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 156 | parity += bit; \ |
Pawel Zarembski |
0:01f31e923fe2 | 157 | bit = request >> 3; \ |
Pawel Zarembski |
0:01f31e923fe2 | 158 | SW_WRITE_BIT(bit); /* A3 Bit */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 159 | parity += bit; \ |
Pawel Zarembski |
0:01f31e923fe2 | 160 | SW_WRITE_BIT(parity); /* Parity Bit */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 161 | SW_WRITE_BIT(0U); /* Stop Bit */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 162 | SW_WRITE_BIT(1U); /* Park Bit */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 163 | \ |
Pawel Zarembski |
0:01f31e923fe2 | 164 | /* Turnaround */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 165 | PIN_SWDIO_OUT_DISABLE(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 166 | for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 167 | SW_CLOCK_CYCLE(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 168 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 169 | \ |
Pawel Zarembski |
0:01f31e923fe2 | 170 | /* Acknowledge response */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 171 | SW_READ_BIT(bit); \ |
Pawel Zarembski |
0:01f31e923fe2 | 172 | ack = bit << 0; \ |
Pawel Zarembski |
0:01f31e923fe2 | 173 | SW_READ_BIT(bit); \ |
Pawel Zarembski |
0:01f31e923fe2 | 174 | ack |= bit << 1; \ |
Pawel Zarembski |
0:01f31e923fe2 | 175 | SW_READ_BIT(bit); \ |
Pawel Zarembski |
0:01f31e923fe2 | 176 | ack |= bit << 2; \ |
Pawel Zarembski |
0:01f31e923fe2 | 177 | \ |
Pawel Zarembski |
0:01f31e923fe2 | 178 | if (ack == DAP_TRANSFER_OK) { /* OK response */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 179 | /* Data transfer */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 180 | if (request & DAP_TRANSFER_RnW) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 181 | /* Read data */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 182 | val = 0U; \ |
Pawel Zarembski |
0:01f31e923fe2 | 183 | parity = 0U; \ |
Pawel Zarembski |
0:01f31e923fe2 | 184 | for (n = 32U; n; n--) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 185 | SW_READ_BIT(bit); /* Read RDATA[0:31] */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 186 | parity += bit; \ |
Pawel Zarembski |
0:01f31e923fe2 | 187 | val >>= 1; \ |
Pawel Zarembski |
0:01f31e923fe2 | 188 | val |= bit << 31; \ |
Pawel Zarembski |
0:01f31e923fe2 | 189 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 190 | SW_READ_BIT(bit); /* Read Parity */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 191 | if ((parity ^ bit) & 1U) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 192 | ack = DAP_TRANSFER_ERROR; \ |
Pawel Zarembski |
0:01f31e923fe2 | 193 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 194 | if (data) { *data = val; } \ |
Pawel Zarembski |
0:01f31e923fe2 | 195 | /* Turnaround */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 196 | for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 197 | SW_CLOCK_CYCLE(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 198 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 199 | PIN_SWDIO_OUT_ENABLE(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 200 | } else { \ |
Pawel Zarembski |
0:01f31e923fe2 | 201 | /* Turnaround */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 202 | for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 203 | SW_CLOCK_CYCLE(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 204 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 205 | PIN_SWDIO_OUT_ENABLE(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 206 | /* Write data */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 207 | val = *data; \ |
Pawel Zarembski |
0:01f31e923fe2 | 208 | parity = 0U; \ |
Pawel Zarembski |
0:01f31e923fe2 | 209 | for (n = 32U; n; n--) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 210 | SW_WRITE_BIT(val); /* Write WDATA[0:31] */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 211 | parity += val; \ |
Pawel Zarembski |
0:01f31e923fe2 | 212 | val >>= 1; \ |
Pawel Zarembski |
0:01f31e923fe2 | 213 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 214 | SW_WRITE_BIT(parity); /* Write Parity Bit */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 215 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 216 | /* Capture Timestamp */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 217 | if (request & DAP_TRANSFER_TIMESTAMP) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 218 | DAP_Data.timestamp = TIMESTAMP_GET(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 219 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 220 | /* Idle cycles */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 221 | n = DAP_Data.transfer.idle_cycles; \ |
Pawel Zarembski |
0:01f31e923fe2 | 222 | if (n) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 223 | PIN_SWDIO_OUT(0U); \ |
Pawel Zarembski |
0:01f31e923fe2 | 224 | for (; n; n--) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 225 | SW_CLOCK_CYCLE(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 226 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 227 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 228 | PIN_SWDIO_OUT(1U); \ |
Pawel Zarembski |
0:01f31e923fe2 | 229 | return ((uint8_t)ack); \ |
Pawel Zarembski |
0:01f31e923fe2 | 230 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 231 | \ |
Pawel Zarembski |
0:01f31e923fe2 | 232 | if ((ack == DAP_TRANSFER_WAIT) || (ack == DAP_TRANSFER_FAULT)) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 233 | /* WAIT or FAULT response */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 234 | if (DAP_Data.swd_conf.data_phase && ((request & DAP_TRANSFER_RnW) != 0U)) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 235 | for (n = 32U+1U; n; n--) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 236 | SW_CLOCK_CYCLE(); /* Dummy Read RDATA[0:31] + Parity */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 237 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 238 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 239 | /* Turnaround */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 240 | for (n = DAP_Data.swd_conf.turnaround; n; n--) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 241 | SW_CLOCK_CYCLE(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 242 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 243 | PIN_SWDIO_OUT_ENABLE(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 244 | if (DAP_Data.swd_conf.data_phase && ((request & DAP_TRANSFER_RnW) == 0U)) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 245 | PIN_SWDIO_OUT(0U); \ |
Pawel Zarembski |
0:01f31e923fe2 | 246 | for (n = 32U+1U; n; n--) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 247 | SW_CLOCK_CYCLE(); /* Dummy Write WDATA[0:31] + Parity */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 248 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 249 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 250 | PIN_SWDIO_OUT(1U); \ |
Pawel Zarembski |
0:01f31e923fe2 | 251 | return ((uint8_t)ack); \ |
Pawel Zarembski |
0:01f31e923fe2 | 252 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 253 | \ |
Pawel Zarembski |
0:01f31e923fe2 | 254 | /* Protocol error */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 255 | for (n = DAP_Data.swd_conf.turnaround + 32U + 1U; n; n--) { \ |
Pawel Zarembski |
0:01f31e923fe2 | 256 | SW_CLOCK_CYCLE(); /* Back off data phase */ \ |
Pawel Zarembski |
0:01f31e923fe2 | 257 | } \ |
Pawel Zarembski |
0:01f31e923fe2 | 258 | PIN_SWDIO_OUT_ENABLE(); \ |
Pawel Zarembski |
0:01f31e923fe2 | 259 | PIN_SWDIO_OUT(1U); \ |
Pawel Zarembski |
0:01f31e923fe2 | 260 | return ((uint8_t)ack); \ |
Pawel Zarembski |
0:01f31e923fe2 | 261 | } |
Pawel Zarembski |
0:01f31e923fe2 | 262 | |
Pawel Zarembski |
0:01f31e923fe2 | 263 | |
Pawel Zarembski |
0:01f31e923fe2 | 264 | #undef PIN_DELAY |
Pawel Zarembski |
0:01f31e923fe2 | 265 | #define PIN_DELAY() PIN_DELAY_FAST() |
Pawel Zarembski |
0:01f31e923fe2 | 266 | SWD_TransferFunction(Fast) |
Pawel Zarembski |
0:01f31e923fe2 | 267 | |
Pawel Zarembski |
0:01f31e923fe2 | 268 | #undef PIN_DELAY |
Pawel Zarembski |
0:01f31e923fe2 | 269 | #define PIN_DELAY() PIN_DELAY_SLOW(DAP_Data.clock_delay) |
Pawel Zarembski |
0:01f31e923fe2 | 270 | SWD_TransferFunction(Slow) |
Pawel Zarembski |
0:01f31e923fe2 | 271 | |
Pawel Zarembski |
0:01f31e923fe2 | 272 | |
Pawel Zarembski |
0:01f31e923fe2 | 273 | // SWD Transfer I/O |
Pawel Zarembski |
0:01f31e923fe2 | 274 | // request: A[3:2] RnW APnDP |
Pawel Zarembski |
0:01f31e923fe2 | 275 | // data: DATA[31:0] |
Pawel Zarembski |
0:01f31e923fe2 | 276 | // return: ACK[2:0] |
Pawel Zarembski |
0:01f31e923fe2 | 277 | uint8_t SWD_Transfer(uint32_t request, uint32_t *data) { |
Pawel Zarembski |
0:01f31e923fe2 | 278 | if (DAP_Data.fast_clock) { |
Pawel Zarembski |
0:01f31e923fe2 | 279 | return SWD_TransferFast(request, data); |
Pawel Zarembski |
0:01f31e923fe2 | 280 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 281 | return SWD_TransferSlow(request, data); |
Pawel Zarembski |
0:01f31e923fe2 | 282 | } |
Pawel Zarembski |
0:01f31e923fe2 | 283 | } |
Pawel Zarembski |
0:01f31e923fe2 | 284 | |
Pawel Zarembski |
0:01f31e923fe2 | 285 | |
Pawel Zarembski |
0:01f31e923fe2 | 286 | #endif /* (DAP_SWD != 0) */ |