Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DAP.h Source File

DAP.h

00001 /*
00002  * Copyright (c) 2013-2019 ARM Limited. All rights reserved.
00003  * Copyright 2019, Cypress Semiconductor Corporation 
00004  * or a subsidiary of Cypress Semiconductor Corporation.
00005  *
00006  * SPDX-License-Identifier: Apache-2.0
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the License); you may
00009  * not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  * www.apache.org/licenses/LICENSE-2.0
00013  *
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00016  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
00019  *
00020  * ----------------------------------------------------------------------
00021  *
00022  * $Date:        26. November 2019
00023  * $Revision:    V2.0.0
00024  *
00025  * Project:      CMSIS-DAP Include
00026  * Title:        DAP.h Definitions
00027  *
00028  *---------------------------------------------------------------------------*/
00029 
00030 #ifndef __DAP_H__
00031 #define __DAP_H__
00032 
00033 
00034 // DAP Firmware Version
00035 #ifdef  DAP_FW_V1
00036 #define DAP_FW_VER                      "1.2.0"
00037 #else
00038 #define DAP_FW_VER                      "2.0.0"
00039 #endif
00040 
00041 // DAP Command IDs
00042 #define ID_DAP_Info                     0x00U
00043 #define ID_DAP_HostStatus               0x01U
00044 #define ID_DAP_Connect                  0x02U
00045 #define ID_DAP_Disconnect               0x03U
00046 #define ID_DAP_TransferConfigure        0x04U
00047 #define ID_DAP_Transfer                 0x05U
00048 #define ID_DAP_TransferBlock            0x06U
00049 #define ID_DAP_TransferAbort            0x07U
00050 #define ID_DAP_WriteABORT               0x08U
00051 #define ID_DAP_Delay                    0x09U
00052 #define ID_DAP_ResetTarget              0x0AU
00053 #define ID_DAP_SWJ_Pins                 0x10U
00054 #define ID_DAP_SWJ_Clock                0x11U
00055 #define ID_DAP_SWJ_Sequence             0x12U
00056 #define ID_DAP_SWD_Configure            0x13U
00057 #define ID_DAP_SWD_Sequence             0x1DU
00058 #define ID_DAP_JTAG_Sequence            0x14U
00059 #define ID_DAP_JTAG_Configure           0x15U
00060 #define ID_DAP_JTAG_IDCODE              0x16U
00061 #define ID_DAP_SWO_Transport            0x17U
00062 #define ID_DAP_SWO_Mode                 0x18U
00063 #define ID_DAP_SWO_Baudrate             0x19U
00064 #define ID_DAP_SWO_Control              0x1AU
00065 #define ID_DAP_SWO_Status               0x1BU
00066 #define ID_DAP_SWO_ExtendedStatus       0x1EU
00067 #define ID_DAP_SWO_Data                 0x1CU
00068 
00069 #define ID_DAP_QueueCommands            0x7EU
00070 #define ID_DAP_ExecuteCommands          0x7FU
00071 
00072 // DAP Vendor Command IDs
00073 #define ID_DAP_Vendor0                  0x80U
00074 #define ID_DAP_Vendor1                  0x81U
00075 #define ID_DAP_Vendor2                  0x82U
00076 #define ID_DAP_Vendor3                  0x83U
00077 #define ID_DAP_Vendor4                  0x84U
00078 #define ID_DAP_Vendor5                  0x85U
00079 #define ID_DAP_Vendor6                  0x86U
00080 #define ID_DAP_Vendor7                  0x87U
00081 #define ID_DAP_Vendor8                  0x88U
00082 #define ID_DAP_Vendor9                  0x89U
00083 #define ID_DAP_Vendor10                 0x8AU
00084 #define ID_DAP_Vendor11                 0x8BU
00085 #define ID_DAP_Vendor12                 0x8CU
00086 #define ID_DAP_Vendor13                 0x8DU
00087 #define ID_DAP_Vendor14                 0x8EU
00088 #define ID_DAP_Vendor15                 0x8FU
00089 #define ID_DAP_Vendor16                 0x90U
00090 #define ID_DAP_Vendor17                 0x91U
00091 #define ID_DAP_Vendor18                 0x92U
00092 #define ID_DAP_Vendor19                 0x93U
00093 #define ID_DAP_Vendor20                 0x94U
00094 #define ID_DAP_Vendor21                 0x95U
00095 #define ID_DAP_Vendor22                 0x96U
00096 #define ID_DAP_Vendor23                 0x97U
00097 #define ID_DAP_Vendor24                 0x98U
00098 #define ID_DAP_Vendor25                 0x99U
00099 #define ID_DAP_Vendor26                 0x9AU
00100 #define ID_DAP_Vendor27                 0x9BU
00101 #define ID_DAP_Vendor28                 0x9CU
00102 #define ID_DAP_Vendor29                 0x9DU
00103 #define ID_DAP_Vendor30                 0x9EU
00104 #define ID_DAP_Vendor31                 0x9FU
00105 
00106 // DAP Extended range of Vendor Command IDs
00107 
00108 #define ID_DAP_VendorExFirst            0xA0U
00109 #define ID_DAP_VendorExLast             0xFEU
00110 
00111 #define ID_DAP_Invalid                  0xFFU
00112 
00113 // DAP Status Code
00114 #define DAP_OK                          0U
00115 #define DAP_ERROR                       0xFFU
00116 
00117 // DAP ID
00118 #define DAP_ID_VENDOR                   1U
00119 #define DAP_ID_PRODUCT                  2U
00120 #define DAP_ID_SER_NUM                  3U
00121 #define DAP_ID_FW_VER                   4U
00122 #define DAP_ID_DEVICE_VENDOR            5U
00123 #define DAP_ID_DEVICE_NAME              6U
00124 #define DAP_ID_CAPABILITIES             0xF0U
00125 #define DAP_ID_TIMESTAMP_CLOCK          0xF1U
00126 #define DAP_ID_SWO_BUFFER_SIZE          0xFDU
00127 #define DAP_ID_PACKET_COUNT             0xFEU
00128 #define DAP_ID_PACKET_SIZE              0xFFU
00129 
00130 // DAP Host Status
00131 #define DAP_DEBUGGER_CONNECTED          0U
00132 #define DAP_TARGET_RUNNING              1U
00133 
00134 // DAP Port
00135 #define DAP_PORT_AUTODETECT             0U      // Autodetect Port
00136 #define DAP_PORT_DISABLED               0U      // Port Disabled (I/O pins in High-Z)
00137 #define DAP_PORT_SWD                    1U      // SWD Port (SWCLK, SWDIO) + nRESET
00138 #define DAP_PORT_JTAG                   2U      // JTAG Port (TCK, TMS, TDI, TDO, nTRST) + nRESET
00139 
00140 // DAP SWJ Pins
00141 #define DAP_SWJ_SWCLK_TCK               0       // SWCLK/TCK
00142 #define DAP_SWJ_SWDIO_TMS               1       // SWDIO/TMS
00143 #define DAP_SWJ_TDI                     2       // TDI
00144 #define DAP_SWJ_TDO                     3       // TDO
00145 #define DAP_SWJ_nTRST                   5       // nTRST
00146 #define DAP_SWJ_nRESET                  7       // nRESET
00147 
00148 // DAP Transfer Request
00149 #define DAP_TRANSFER_APnDP              (1U<<0)
00150 #define DAP_TRANSFER_RnW                (1U<<1)
00151 #define DAP_TRANSFER_A2                 (1U<<2)
00152 #define DAP_TRANSFER_A3                 (1U<<3)
00153 #define DAP_TRANSFER_MATCH_VALUE        (1U<<4)
00154 #define DAP_TRANSFER_MATCH_MASK         (1U<<5)
00155 #define DAP_TRANSFER_TIMESTAMP          (1U<<7)
00156 
00157 // DAP Transfer Response
00158 #define DAP_TRANSFER_OK                 (1U<<0)
00159 #define DAP_TRANSFER_WAIT               (1U<<1)
00160 #define DAP_TRANSFER_FAULT              (1U<<2)
00161 #define DAP_TRANSFER_ERROR              (1U<<3)
00162 #define DAP_TRANSFER_MISMATCH           (1U<<4)
00163 
00164 // DAP SWO Trace Mode
00165 #define DAP_SWO_OFF                     0U
00166 #define DAP_SWO_UART                    1U
00167 #define DAP_SWO_MANCHESTER              2U
00168 
00169 // DAP SWO Trace Status
00170 #define DAP_SWO_CAPTURE_ACTIVE          (1U<<0)
00171 #define DAP_SWO_CAPTURE_PAUSED          (1U<<1)
00172 #define DAP_SWO_STREAM_ERROR            (1U<<6)
00173 #define DAP_SWO_BUFFER_OVERRUN          (1U<<7)
00174 
00175 
00176 // Debug Port Register Addresses
00177 #define DP_IDCODE                       0x00U   // IDCODE Register (SW Read only)
00178 #define DP_ABORT                        0x00U   // Abort Register (SW Write only)
00179 #define DP_CTRL_STAT                    0x04U   // Control & Status
00180 #define DP_WCR                          0x04U   // Wire Control Register (SW Only)
00181 #define DP_SELECT                       0x08U   // Select Register (JTAG R/W & SW W)
00182 #define DP_RESEND                       0x08U   // Resend (SW Read Only)
00183 #define DP_RDBUFF                       0x0CU   // Read Buffer (Read Only)
00184 
00185 // JTAG IR Codes
00186 #define JTAG_ABORT                      0x08U
00187 #define JTAG_DPACC                      0x0AU
00188 #define JTAG_APACC                      0x0BU
00189 #define JTAG_IDCODE                     0x0EU
00190 #define JTAG_BYPASS                     0x0FU
00191 
00192 // JTAG Sequence Info
00193 #define JTAG_SEQUENCE_TCK               0x3FU   // TCK count
00194 #define JTAG_SEQUENCE_TMS               0x40U   // TMS value
00195 #define JTAG_SEQUENCE_TDO               0x80U   // TDO capture
00196 
00197 // SWD Sequence Info
00198 #define SWD_SEQUENCE_CLK                0x3FU   // SWCLK count
00199 #define SWD_SEQUENCE_DIN                0x80U   // SWDIO capture
00200 
00201 
00202 #include <stddef.h>
00203 #include <stdint.h>
00204 #include "cmsis_compiler.h"
00205 
00206 // DAP Data structure
00207 typedef struct {
00208   uint8_t     debug_port;                       // Debug Port
00209   uint8_t     fast_clock;                       // Fast Clock Flag
00210   uint8_t     padding[2];
00211   uint32_t   clock_delay;                       // Clock Delay
00212   uint32_t     timestamp;                       // Last captured Timestamp
00213   struct {                                      // Transfer Configuration
00214     uint8_t   idle_cycles;                      // Idle cycles after transfer
00215     uint8_t    padding[3];
00216     uint16_t  retry_count;                      // Number of retries after WAIT response
00217     uint16_t  match_retry;                      // Number of retries if read value does not match
00218     uint32_t  match_mask;                       // Match Mask
00219   } transfer;
00220 #if (DAP_SWD != 0)
00221   struct {                                      // SWD Configuration
00222     uint8_t    turnaround;                      // Turnaround period
00223     uint8_t    data_phase;                      // Always generate Data Phase
00224   } swd_conf;
00225 #endif
00226 #if (DAP_JTAG != 0)
00227   struct {                                      // JTAG Device Chain
00228     uint8_t   count;                            // Number of devices
00229     uint8_t   index;                            // Device index (device at TDO has index 0)
00230 #if (DAP_JTAG_DEV_CNT != 0)
00231     uint8_t   ir_length[DAP_JTAG_DEV_CNT];      // IR Length in bits
00232     uint16_t  ir_before[DAP_JTAG_DEV_CNT];      // Bits before IR
00233     uint16_t  ir_after [DAP_JTAG_DEV_CNT];      // Bits after IR
00234 #endif
00235   } jtag_dev;
00236 #endif
00237 } DAP_Data_t;
00238 
00239 extern          DAP_Data_t DAP_Data;            // DAP Data
00240 extern volatile uint8_t    DAP_TransferAbort;   // Transfer Abort Flag
00241 
00242 
00243 #ifdef  __cplusplus
00244 extern "C"
00245 {
00246 #endif
00247 
00248 // Functions
00249 extern void     SWJ_Sequence    (uint32_t count, const uint8_t *data);
00250 extern void     SWD_Sequence    (uint32_t info,  const uint8_t *swdo, uint8_t *swdi);
00251 extern void     JTAG_Sequence   (uint32_t info,  const uint8_t *tdi,  uint8_t *tdo);
00252 extern void     JTAG_IR         (uint32_t ir);
00253 extern uint32_t JTAG_ReadIDCode (void);
00254 extern void     JTAG_WriteAbort (uint32_t data);
00255 extern uint8_t  JTAG_Transfer   (uint32_t request, uint32_t *data);
00256 extern uint8_t  SWD_Transfer    (uint32_t request, uint32_t *data);
00257 
00258 extern void     Delayms         (uint32_t delay);
00259 
00260 extern uint32_t SWO_Transport      (const uint8_t *request, uint8_t *response);
00261 extern uint32_t SWO_Mode           (const uint8_t *request, uint8_t *response);
00262 extern uint32_t SWO_Baudrate       (const uint8_t *request, uint8_t *response);
00263 extern uint32_t SWO_Control        (const uint8_t *request, uint8_t *response);
00264 extern uint32_t SWO_Status                                 (uint8_t *response);
00265 extern uint32_t SWO_ExtendedStatus (const uint8_t *request, uint8_t *response);
00266 extern uint32_t SWO_Data           (const uint8_t *request, uint8_t *response);
00267 
00268 extern void     SWO_QueueTransfer    (uint8_t *buf, uint32_t num);
00269 extern void     SWO_AbortTransfer    (void);
00270 extern void     SWO_TransferComplete (void);
00271 
00272 extern uint32_t UART_SWO_Mode     (uint32_t enable);
00273 extern uint32_t UART_SWO_Baudrate (uint32_t baudrate);
00274 extern uint32_t UART_SWO_Control  (uint32_t active);
00275 extern void     UART_SWO_Capture  (uint8_t *buf, uint32_t num);
00276 extern uint32_t UART_SWO_GetCount (void);
00277 
00278 extern uint32_t Manchester_SWO_Mode     (uint32_t enable);
00279 extern uint32_t Manchester_SWO_Baudrate (uint32_t baudrate);
00280 extern uint32_t Manchester_SWO_Control  (uint32_t active);
00281 extern void     Manchester_SWO_Capture  (uint8_t *buf, uint32_t num);
00282 extern uint32_t Manchester_SWO_GetCount (void);
00283 
00284 extern uint32_t DAP_ProcessVendorCommand (const uint8_t *request, uint8_t *response);
00285 extern uint32_t DAP_ProcessCommand       (const uint8_t *request, uint8_t *response);
00286 extern uint32_t DAP_ExecuteCommand       (const uint8_t *request, uint8_t *response);
00287 
00288 extern void     DAP_Setup (void);
00289 
00290 // Configurable delay for clock generation
00291 #ifndef DELAY_SLOW_CYCLES
00292 #define DELAY_SLOW_CYCLES       3U      // Number of cycles for one iteration
00293 #endif
00294 #if defined(__CC_ARM)
00295 __STATIC_FORCEINLINE void PIN_DELAY_SLOW (uint32_t delay) {
00296   uint32_t count = delay;
00297   while (--count);
00298 }
00299 #else
00300 __STATIC_FORCEINLINE void PIN_DELAY_SLOW (uint32_t delay) {
00301   __ASM volatile (
00302   ".syntax unified\n"
00303   "0:\n\t"
00304     "subs %0,%0,#1\n\t"
00305     "bne  0b\n"
00306   : "+l" (delay) : : "cc"
00307   );
00308 }
00309 #endif
00310 
00311 // Fixed delay for fast clock generation
00312 #ifndef DELAY_FAST_CYCLES
00313 #define DELAY_FAST_CYCLES       0U      // Number of cycles: 0..3
00314 #endif
00315 __STATIC_FORCEINLINE void PIN_DELAY_FAST (void) {
00316 #if (DELAY_FAST_CYCLES >= 1U)
00317   __NOP();
00318 #endif
00319 #if (DELAY_FAST_CYCLES >= 2U)
00320   __NOP();
00321 #endif
00322 #if (DELAY_FAST_CYCLES >= 3U)
00323   __NOP();
00324 #endif
00325 }
00326 
00327 #ifdef  __cplusplus
00328 }
00329 #endif
00330 
00331 
00332 #endif  /* __DAP_H__ */