DAP_config.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /*
  2. * Copyright (c) 2013-2017 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * ----------------------------------------------------------------------
  19. *
  20. * $Date: 1. December 2017
  21. * $Revision: V2.0.0
  22. *
  23. * Project: CMSIS-DAP Configuration
  24. * Title: DAP_config.h CMSIS-DAP Configuration File (Template)
  25. *
  26. *---------------------------------------------------------------------------*/
  27. #ifndef __DAP_CONFIG_H__
  28. #define __DAP_CONFIG_H__
  29. //**************************************************************************************************
  30. /**
  31. \defgroup DAP_Config_Debug_gr CMSIS-DAP Debug Unit Information
  32. \ingroup DAP_ConfigIO_gr
  33. @{
  34. Provides definitions about the hardware and configuration of the Debug Unit.
  35. This information includes:
  36. - Definition of Cortex-M processor parameters used in CMSIS-DAP Debug Unit.
  37. - Debug Unit Identification strings (Vendor, Product, Serial Number).
  38. - Debug Unit communication packet size.
  39. - Debug Access Port supported modes and settings (JTAG/SWD and SWO).
  40. - Optional information about a connected Target Device (for Evaluation Boards).
  41. */
  42. #ifdef _RTE_
  43. #include "RTE_Components.h"
  44. #include CMSIS_device_header
  45. #else
  46. #include "device.h" // Debug Unit Cortex-M Processor Header File
  47. #endif
  48. /// Processor Clock of the Cortex-M MCU used in the Debug Unit.
  49. /// This value is used to calculate the SWD/JTAG clock speed.
  50. #define CPU_CLOCK 100000000U ///< Specifies the CPU Clock in Hz.
  51. /// Number of processor cycles for I/O Port write operations.
  52. /// This value is used to calculate the SWD/JTAG clock speed that is generated with I/O
  53. /// Port write operations in the Debug Unit by a Cortex-M MCU. Most Cortex-M processors
  54. /// require 2 processor cycles for a I/O Port Write operation. If the Debug Unit uses
  55. /// a Cortex-M0+ processor with high-speed peripheral I/O only 1 processor cycle might be
  56. /// required.
  57. #define IO_PORT_WRITE_CYCLES 2U ///< I/O Cycles: 2=default, 1=Cortex-M0+ fast I/0.
  58. /// Indicate that Serial Wire Debug (SWD) communication mode is available at the Debug Access Port.
  59. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  60. #define DAP_SWD 1 ///< SWD Mode: 1 = available, 0 = not available.
  61. /// Indicate that JTAG communication mode is available at the Debug Port.
  62. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  63. #define DAP_JTAG 1 ///< JTAG Mode: 1 = available, 0 = not available.
  64. /// Configure maximum number of JTAG devices on the scan chain connected to the Debug Access Port.
  65. /// This setting impacts the RAM requirements of the Debug Unit. Valid range is 1 .. 255.
  66. #define DAP_JTAG_DEV_CNT 8U ///< Maximum number of JTAG devices on scan chain.
  67. /// Default communication mode on the Debug Access Port.
  68. /// Used for the command \ref DAP_Connect when Port Default mode is selected.
  69. #define DAP_DEFAULT_PORT 1U ///< Default JTAG/SWJ Port Mode: 1 = SWD, 2 = JTAG.
  70. /// Default communication speed on the Debug Access Port for SWD and JTAG mode.
  71. /// Used to initialize the default SWD/JTAG clock frequency.
  72. /// The command \ref DAP_SWJ_Clock can be used to overwrite this default setting.
  73. #define DAP_DEFAULT_SWJ_CLOCK 1000000U ///< Default SWD/JTAG clock frequency in Hz.
  74. /// Maximum Package Size for Command and Response data.
  75. /// This configuration settings is used to optimize the communication performance with the
  76. /// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB,
  77. /// 1024 for High-speed USB HID and 512 for High-speed USB WinUSB.
  78. #define DAP_PACKET_SIZE 512U ///< Specifies Packet Size in bytes.
  79. /// Maximum Package Buffers for Command and Response data.
  80. /// This configuration settings is used to optimize the communication performance with the
  81. /// debugger and depends on the USB peripheral. For devices with limited RAM or USB buffer the
  82. /// setting can be reduced (valid range is 1 .. 255).
  83. #define DAP_PACKET_COUNT 8U ///< Specifies number of packets buffered.
  84. /// Indicate that UART Serial Wire Output (SWO) trace is available.
  85. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  86. #define SWO_UART 1 ///< SWO UART: 1 = available, 0 = not available.
  87. /// Maximum SWO UART Baudrate.
  88. #define SWO_UART_MAX_BAUDRATE 10000000U ///< SWO UART Maximum Baudrate in Hz.
  89. /// Indicate that Manchester Serial Wire Output (SWO) trace is available.
  90. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  91. #define SWO_MANCHESTER 0 ///< SWO Manchester: 1 = available, 0 = not available.
  92. /// SWO Trace Buffer Size.
  93. #define SWO_BUFFER_SIZE 4096U ///< SWO Trace Buffer Size in bytes (must be 2^n).
  94. /// SWO Streaming Trace.
  95. #define SWO_STREAM 0 ///< SWO Streaming Trace: 1 = available, 0 = not available.
  96. /// Clock frequency of the Test Domain Timer. Timer value is returned with \ref TIMESTAMP_GET.
  97. #define TIMESTAMP_CLOCK 100000000U ///< Timestamp clock in Hz (0 = timestamps not supported).
  98. /// Debug Unit is connected to fixed Target Device.
  99. /// The Debug Unit may be part of an evaluation board and always connected to a fixed
  100. /// known device. In this case a Device Vendor and Device Name string is stored which
  101. /// may be used by the debugger or IDE to configure device parameters.
  102. #define TARGET_DEVICE_FIXED 0 ///< Target Device: 1 = known, 0 = unknown;
  103. #if TARGET_DEVICE_FIXED
  104. #define TARGET_DEVICE_VENDOR "ARM" ///< String indicating the Silicon Vendor
  105. #define TARGET_DEVICE_NAME "Cortex-M4" ///< String indicating the Target Device
  106. #endif
  107. /** Get Vendor ID string.
  108. \param str Pointer to buffer to store the string.
  109. \return String length.
  110. */
  111. __STATIC_INLINE uint8_t DAP_GetVendorString (char *str) {
  112. (void)str;
  113. return (0U);
  114. }
  115. /** Get Product ID string.
  116. \param str Pointer to buffer to store the string.
  117. \return String length.
  118. */
  119. __STATIC_INLINE uint8_t DAP_GetProductString (char *str) {
  120. (void)str;
  121. return (0U);
  122. }
  123. /** Get Serial Number string.
  124. \param str Pointer to buffer to store the string.
  125. \return String length.
  126. */
  127. __STATIC_INLINE uint8_t DAP_GetSerNumString (char *str) {
  128. (void)str;
  129. return (0U);
  130. }
  131. ///@}
  132. //**************************************************************************************************
  133. /**
  134. \defgroup DAP_Config_PortIO_gr CMSIS-DAP Hardware I/O Pin Access
  135. \ingroup DAP_ConfigIO_gr
  136. @{
  137. Standard I/O Pins of the CMSIS-DAP Hardware Debug Port support standard JTAG mode
  138. and Serial Wire Debug (SWD) mode. In SWD mode only 2 pins are required to implement the debug
  139. interface of a device. The following I/O Pins are provided:
  140. JTAG I/O Pin | SWD I/O Pin | CMSIS-DAP Hardware pin mode
  141. ---------------------------- | -------------------- | ---------------------------------------------
  142. TCK: Test Clock | SWCLK: Clock | Output Push/Pull
  143. TMS: Test Mode Select | SWDIO: Data I/O | Output Push/Pull; Input (for receiving data)
  144. TDI: Test Data Input | | Output Push/Pull
  145. TDO: Test Data Output | | Input
  146. nTRST: Test Reset (optional) | | Output Open Drain with pull-up resistor
  147. nRESET: Device Reset | nRESET: Device Reset | Output Open Drain with pull-up resistor
  148. DAP Hardware I/O Pin Access Functions
  149. -------------------------------------
  150. The various I/O Pins are accessed by functions that implement the Read, Write, Set, or Clear to
  151. these I/O Pins.
  152. For the SWDIO I/O Pin there are additional functions that are called in SWD I/O mode only.
  153. This functions are provided to achieve faster I/O that is possible with some advanced GPIO
  154. peripherals that can independently write/read a single I/O pin without affecting any other pins
  155. of the same I/O port. The following SWDIO I/O Pin functions are provided:
  156. - \ref PIN_SWDIO_OUT_ENABLE to enable the output mode from the DAP hardware.
  157. - \ref PIN_SWDIO_OUT_DISABLE to enable the input mode to the DAP hardware.
  158. - \ref PIN_SWDIO_IN to read from the SWDIO I/O pin with utmost possible speed.
  159. - \ref PIN_SWDIO_OUT to write to the SWDIO I/O pin with utmost possible speed.
  160. */
  161. // Configure DAP I/O pins ------------------------------
  162. /** Setup JTAG I/O pins: TCK, TMS, TDI, TDO, nTRST, and nRESET.
  163. Configures the DAP Hardware I/O pins for JTAG mode:
  164. - TCK, TMS, TDI, nTRST, nRESET to output mode and set to high level.
  165. - TDO to input mode.
  166. */
  167. __STATIC_INLINE void PORT_JTAG_SETUP (void) {
  168. ;
  169. }
  170. /** Setup SWD I/O pins: SWCLK, SWDIO, and nRESET.
  171. Configures the DAP Hardware I/O pins for Serial Wire Debug (SWD) mode:
  172. - SWCLK, SWDIO, nRESET to output mode and set to default high level.
  173. - TDI, nTRST to HighZ mode (pins are unused in SWD mode).
  174. */
  175. __STATIC_INLINE void PORT_SWD_SETUP (void) {
  176. ;
  177. }
  178. /** Disable JTAG/SWD I/O Pins.
  179. Disables the DAP Hardware I/O pins which configures:
  180. - TCK/SWCLK, TMS/SWDIO, TDI, TDO, nTRST, nRESET to High-Z mode.
  181. */
  182. __STATIC_INLINE void PORT_OFF (void) {
  183. ;
  184. }
  185. // SWCLK/TCK I/O pin -------------------------------------
  186. /** SWCLK/TCK I/O pin: Get Input.
  187. \return Current status of the SWCLK/TCK DAP hardware I/O pin.
  188. */
  189. __STATIC_FORCEINLINE uint32_t PIN_SWCLK_TCK_IN (void) {
  190. return (0U);
  191. }
  192. /** SWCLK/TCK I/O pin: Set Output to High.
  193. Set the SWCLK/TCK DAP hardware I/O pin to high level.
  194. */
  195. __STATIC_FORCEINLINE void PIN_SWCLK_TCK_SET (void) {
  196. ;
  197. }
  198. /** SWCLK/TCK I/O pin: Set Output to Low.
  199. Set the SWCLK/TCK DAP hardware I/O pin to low level.
  200. */
  201. __STATIC_FORCEINLINE void PIN_SWCLK_TCK_CLR (void) {
  202. ;
  203. }
  204. // SWDIO/TMS Pin I/O --------------------------------------
  205. /** SWDIO/TMS I/O pin: Get Input.
  206. \return Current status of the SWDIO/TMS DAP hardware I/O pin.
  207. */
  208. __STATIC_FORCEINLINE uint32_t PIN_SWDIO_TMS_IN (void) {
  209. return (0U);
  210. }
  211. /** SWDIO/TMS I/O pin: Set Output to High.
  212. Set the SWDIO/TMS DAP hardware I/O pin to high level.
  213. */
  214. __STATIC_FORCEINLINE void PIN_SWDIO_TMS_SET (void) {
  215. ;
  216. }
  217. /** SWDIO/TMS I/O pin: Set Output to Low.
  218. Set the SWDIO/TMS DAP hardware I/O pin to low level.
  219. */
  220. __STATIC_FORCEINLINE void PIN_SWDIO_TMS_CLR (void) {
  221. ;
  222. }
  223. /** SWDIO I/O pin: Get Input (used in SWD mode only).
  224. \return Current status of the SWDIO DAP hardware I/O pin.
  225. */
  226. __STATIC_FORCEINLINE uint32_t PIN_SWDIO_IN (void) {
  227. return (0U);
  228. }
  229. /** SWDIO I/O pin: Set Output (used in SWD mode only).
  230. \param bit Output value for the SWDIO DAP hardware I/O pin.
  231. */
  232. __STATIC_FORCEINLINE void PIN_SWDIO_OUT (uint32_t bit) {
  233. ;
  234. }
  235. /** SWDIO I/O pin: Switch to Output mode (used in SWD mode only).
  236. Configure the SWDIO DAP hardware I/O pin to output mode. This function is
  237. called prior \ref PIN_SWDIO_OUT function calls.
  238. */
  239. __STATIC_FORCEINLINE void PIN_SWDIO_OUT_ENABLE (void) {
  240. ;
  241. }
  242. /** SWDIO I/O pin: Switch to Input mode (used in SWD mode only).
  243. Configure the SWDIO DAP hardware I/O pin to input mode. This function is
  244. called prior \ref PIN_SWDIO_IN function calls.
  245. */
  246. __STATIC_FORCEINLINE void PIN_SWDIO_OUT_DISABLE (void) {
  247. ;
  248. }
  249. // TDI Pin I/O ---------------------------------------------
  250. /** TDI I/O pin: Get Input.
  251. \return Current status of the TDI DAP hardware I/O pin.
  252. */
  253. __STATIC_FORCEINLINE uint32_t PIN_TDI_IN (void) {
  254. return (0U);
  255. }
  256. /** TDI I/O pin: Set Output.
  257. \param bit Output value for the TDI DAP hardware I/O pin.
  258. */
  259. __STATIC_FORCEINLINE void PIN_TDI_OUT (uint32_t bit) {
  260. ;
  261. }
  262. // TDO Pin I/O ---------------------------------------------
  263. /** TDO I/O pin: Get Input.
  264. \return Current status of the TDO DAP hardware I/O pin.
  265. */
  266. __STATIC_FORCEINLINE uint32_t PIN_TDO_IN (void) {
  267. return (0U);
  268. }
  269. // nTRST Pin I/O -------------------------------------------
  270. /** nTRST I/O pin: Get Input.
  271. \return Current status of the nTRST DAP hardware I/O pin.
  272. */
  273. __STATIC_FORCEINLINE uint32_t PIN_nTRST_IN (void) {
  274. return (0U);
  275. }
  276. /** nTRST I/O pin: Set Output.
  277. \param bit JTAG TRST Test Reset pin status:
  278. - 0: issue a JTAG TRST Test Reset.
  279. - 1: release JTAG TRST Test Reset.
  280. */
  281. __STATIC_FORCEINLINE void PIN_nTRST_OUT (uint32_t bit) {
  282. ;
  283. }
  284. // nRESET Pin I/O------------------------------------------
  285. /** nRESET I/O pin: Get Input.
  286. \return Current status of the nRESET DAP hardware I/O pin.
  287. */
  288. __STATIC_FORCEINLINE uint32_t PIN_nRESET_IN (void) {
  289. return (0U);
  290. }
  291. /** nRESET I/O pin: Set Output.
  292. \param bit target device hardware reset pin status:
  293. - 0: issue a device hardware reset.
  294. - 1: release device hardware reset.
  295. */
  296. __STATIC_FORCEINLINE void PIN_nRESET_OUT (uint32_t bit) {
  297. ;
  298. }
  299. ///@}
  300. //**************************************************************************************************
  301. /**
  302. \defgroup DAP_Config_LEDs_gr CMSIS-DAP Hardware Status LEDs
  303. \ingroup DAP_ConfigIO_gr
  304. @{
  305. CMSIS-DAP Hardware may provide LEDs that indicate the status of the CMSIS-DAP Debug Unit.
  306. It is recommended to provide the following LEDs for status indication:
  307. - Connect LED: is active when the DAP hardware is connected to a debugger.
  308. - Running LED: is active when the debugger has put the target device into running state.
  309. */
  310. /** Debug Unit: Set status of Connected LED.
  311. \param bit status of the Connect LED.
  312. - 1: Connect LED ON: debugger is connected to CMSIS-DAP Debug Unit.
  313. - 0: Connect LED OFF: debugger is not connected to CMSIS-DAP Debug Unit.
  314. */
  315. __STATIC_INLINE void LED_CONNECTED_OUT (uint32_t bit) {}
  316. /** Debug Unit: Set status Target Running LED.
  317. \param bit status of the Target Running LED.
  318. - 1: Target Running LED ON: program execution in target started.
  319. - 0: Target Running LED OFF: program execution in target stopped.
  320. */
  321. __STATIC_INLINE void LED_RUNNING_OUT (uint32_t bit) {}
  322. ///@}
  323. //**************************************************************************************************
  324. /**
  325. \defgroup DAP_Config_Timestamp_gr CMSIS-DAP Timestamp
  326. \ingroup DAP_ConfigIO_gr
  327. @{
  328. Access function for Test Domain Timer.
  329. The value of the Test Domain Timer in the Debug Unit is returned by the function \ref TIMESTAMP_GET. By
  330. default, the DWT timer is used. The frequency of this timer is configured with \ref TIMESTAMP_CLOCK.
  331. */
  332. /** Get timestamp of Test Domain Timer.
  333. \return Current timestamp value.
  334. */
  335. __STATIC_INLINE uint32_t TIMESTAMP_GET (void) {
  336. return (DWT->CYCCNT);
  337. }
  338. ///@}
  339. //**************************************************************************************************
  340. /**
  341. \defgroup DAP_Config_Initialization_gr CMSIS-DAP Initialization
  342. \ingroup DAP_ConfigIO_gr
  343. @{
  344. CMSIS-DAP Hardware I/O and LED Pins are initialized with the function \ref DAP_SETUP.
  345. */
  346. /** Setup of the Debug Unit I/O pins and LEDs (called when Debug Unit is initialized).
  347. This function performs the initialization of the CMSIS-DAP Hardware I/O Pins and the
  348. Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled and set:
  349. - I/O clock system enabled.
  350. - all I/O pins: input buffer enabled, output pins are set to HighZ mode.
  351. - for nTRST, nRESET a weak pull-up (if available) is enabled.
  352. - LED output pins are enabled and LEDs are turned off.
  353. */
  354. __STATIC_INLINE void DAP_SETUP (void) {
  355. ;
  356. }
  357. /** Reset Target Device with custom specific I/O pin or command sequence.
  358. This function allows the optional implementation of a device specific reset sequence.
  359. It is called when the command \ref DAP_ResetTarget and is for example required
  360. when a device needs a time-critical unlock sequence that enables the debug port.
  361. \return 0 = no device specific reset sequence is implemented.\n
  362. 1 = a device specific reset sequence is implemented.
  363. */
  364. __STATIC_INLINE uint8_t RESET_TARGET (void) {
  365. return (0U); // change to '1' when a device reset sequence is implemented
  366. }
  367. ///@}
  368. #endif /* __DAP_CONFIG_H__ */