DAP_config.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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 Examples LPC-Link-II
  24. * Title: DAP_config.h CMSIS-DAP Configuration File for LPC-Link-II
  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 180000000U ///< 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 8192U ///< SWO Trace Buffer Size in bytes (must be 2^n).
  94. /// SWO Streaming Trace.
  95. #define SWO_STREAM 1 ///< 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 180000000U ///< 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 "" ///< String indicating the Silicon Vendor
  105. #define TARGET_DEVICE_NAME "" ///< 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. // LPC43xx peripheral register bit masks (used by macros)
  133. #define CCU_CLK_CFG_RUN (1U << 0)
  134. #define CCU_CLK_CFG_AUTO (1U << 1)
  135. #define CCU_CLK_STAT_RUN (1U << 0)
  136. #define SCU_SFS_EPD (1U << 3)
  137. #define SCU_SFS_EPUN (1U << 4)
  138. #define SCU_SFS_EHS (1U << 5)
  139. #define SCU_SFS_EZI (1U << 6)
  140. #define SCU_SFS_ZIF (1U << 7)
  141. // Debug Port I/O Pins
  142. // SWCLK/TCK Pin P1_17: GPIO0[12]
  143. #define PIN_SWCLK_TCK_PORT 0
  144. #define PIN_SWCLK_TCK_BIT 12
  145. // SWDIO/TMS Pin P1_6: GPIO1[9]
  146. #define PIN_SWDIO_TMS_PORT 1
  147. #define PIN_SWDIO_TMS_BIT 9
  148. // SWDIO Output Enable Pin P1_5: GPIO1[8]
  149. #define PIN_SWDIO_OE_PORT 1
  150. #define PIN_SWDIO_OE_BIT 8
  151. // TDI Pin P1_18: GPIO0[13]
  152. #define PIN_TDI_PORT 0
  153. #define PIN_TDI_BIT 13
  154. // TDO Pin P1_14: GPIO1[7]
  155. #define PIN_TDO_PORT 1
  156. #define PIN_TDO_BIT 7
  157. // nTRST Pin Not available
  158. #define PIN_nTRST_PORT
  159. #define PIN_nTRST_BIT
  160. // nRESET Pin P2_5: GPIO5[5]
  161. #define PIN_nRESET_PORT 5
  162. #define PIN_nRESET_BIT 5
  163. // nRESET Output Enable Pin P2_6: GPIO5[6]
  164. #define PIN_nRESET_OE_PORT 5
  165. #define PIN_nRESET_OE_BIT 6
  166. // Debug Unit LEDs
  167. // Connected LED P1_1: GPIO0[8]
  168. #define LED_CONNECTED_PORT 0
  169. #define LED_CONNECTED_BIT 8
  170. // Target Running LED Not available
  171. //**************************************************************************************************
  172. /**
  173. \defgroup DAP_Config_PortIO_gr CMSIS-DAP Hardware I/O Pin Access
  174. \ingroup DAP_ConfigIO_gr
  175. @{
  176. Standard I/O Pins of the CMSIS-DAP Hardware Debug Port support standard JTAG mode
  177. and Serial Wire Debug (SWD) mode. In SWD mode only 2 pins are required to implement the debug
  178. interface of a device. The following I/O Pins are provided:
  179. JTAG I/O Pin | SWD I/O Pin | CMSIS-DAP Hardware pin mode
  180. ---------------------------- | -------------------- | ---------------------------------------------
  181. TCK: Test Clock | SWCLK: Clock | Output Push/Pull
  182. TMS: Test Mode Select | SWDIO: Data I/O | Output Push/Pull; Input (for receiving data)
  183. TDI: Test Data Input | | Output Push/Pull
  184. TDO: Test Data Output | | Input
  185. nTRST: Test Reset (optional) | | Output Open Drain with pull-up resistor
  186. nRESET: Device Reset | nRESET: Device Reset | Output Open Drain with pull-up resistor
  187. DAP Hardware I/O Pin Access Functions
  188. -------------------------------------
  189. The various I/O Pins are accessed by functions that implement the Read, Write, Set, or Clear to
  190. these I/O Pins.
  191. For the SWDIO I/O Pin there are additional functions that are called in SWD I/O mode only.
  192. This functions are provided to achieve faster I/O that is possible with some advanced GPIO
  193. peripherals that can independently write/read a single I/O pin without affecting any other pins
  194. of the same I/O port. The following SWDIO I/O Pin functions are provided:
  195. - \ref PIN_SWDIO_OUT_ENABLE to enable the output mode from the DAP hardware.
  196. - \ref PIN_SWDIO_OUT_DISABLE to enable the input mode to the DAP hardware.
  197. - \ref PIN_SWDIO_IN to read from the SWDIO I/O pin with utmost possible speed.
  198. - \ref PIN_SWDIO_OUT to write to the SWDIO I/O pin with utmost possible speed.
  199. */
  200. // Configure DAP I/O pins ------------------------------
  201. // LPC-Link-II HW uses buffers for debug port pins. Therefore it is not
  202. // possible to disable outputs SWCLK/TCK, TDI and they are left active.
  203. // Only SWDIO/TMS output can be disabled but it is also left active.
  204. // nRESET is configured for open drain mode.
  205. /** Setup JTAG I/O pins: TCK, TMS, TDI, TDO, nTRST, and nRESET.
  206. Configures the DAP Hardware I/O pins for JTAG mode:
  207. - TCK, TMS, TDI, nTRST, nRESET to output mode and set to high level.
  208. - TDO to input mode.
  209. */
  210. __STATIC_INLINE void PORT_JTAG_SETUP (void) {
  211. LPC_GPIO_PORT->MASK[PIN_SWDIO_TMS_PORT] = 0U;
  212. LPC_GPIO_PORT->MASK[PIN_TDI_PORT] = ~(1U << PIN_TDI_BIT);
  213. }
  214. /** Setup SWD I/O pins: SWCLK, SWDIO, and nRESET.
  215. Configures the DAP Hardware I/O pins for Serial Wire Debug (SWD) mode:
  216. - SWCLK, SWDIO, nRESET to output mode and set to default high level.
  217. - TDI, nTRST to HighZ mode (pins are unused in SWD mode).
  218. */
  219. __STATIC_INLINE void PORT_SWD_SETUP (void) {
  220. LPC_GPIO_PORT->MASK[PIN_TDI_PORT] = 0U;
  221. LPC_GPIO_PORT->MASK[PIN_SWDIO_TMS_PORT] = ~(1U << PIN_SWDIO_TMS_BIT);
  222. }
  223. /** Disable JTAG/SWD I/O Pins.
  224. Disables the DAP Hardware I/O pins which configures:
  225. - TCK/SWCLK, TMS/SWDIO, TDI, TDO, nTRST, nRESET to High-Z mode.
  226. */
  227. __STATIC_INLINE void PORT_OFF (void) {
  228. LPC_GPIO_PORT->SET[PIN_SWCLK_TCK_PORT] = (1U << PIN_SWCLK_TCK_BIT);
  229. LPC_GPIO_PORT->SET[PIN_SWDIO_TMS_PORT] = (1U << PIN_SWDIO_TMS_BIT);
  230. LPC_GPIO_PORT->SET[PIN_SWDIO_OE_PORT] = (1U << PIN_SWDIO_OE_BIT);
  231. LPC_GPIO_PORT->SET[PIN_TDI_PORT] = (1U << PIN_TDI_BIT);
  232. LPC_GPIO_PORT->DIR[PIN_nRESET_PORT] &= ~(1U << PIN_nRESET_BIT);
  233. LPC_GPIO_PORT->CLR[PIN_nRESET_OE_PORT] = (1U << PIN_nRESET_OE_BIT);
  234. }
  235. // SWCLK/TCK I/O pin -------------------------------------
  236. /** SWCLK/TCK I/O pin: Get Input.
  237. \return Current status of the SWCLK/TCK DAP hardware I/O pin.
  238. */
  239. __STATIC_FORCEINLINE uint32_t PIN_SWCLK_TCK_IN (void) {
  240. return ((LPC_GPIO_PORT->PIN[PIN_SWCLK_TCK_PORT] >> PIN_SWCLK_TCK_BIT) & 1U);
  241. }
  242. /** SWCLK/TCK I/O pin: Set Output to High.
  243. Set the SWCLK/TCK DAP hardware I/O pin to high level.
  244. */
  245. __STATIC_FORCEINLINE void PIN_SWCLK_TCK_SET (void) {
  246. LPC_GPIO_PORT->SET[PIN_SWCLK_TCK_PORT] = 1U << PIN_SWCLK_TCK_BIT;
  247. }
  248. /** SWCLK/TCK I/O pin: Set Output to Low.
  249. Set the SWCLK/TCK DAP hardware I/O pin to low level.
  250. */
  251. __STATIC_FORCEINLINE void PIN_SWCLK_TCK_CLR (void) {
  252. LPC_GPIO_PORT->CLR[PIN_SWCLK_TCK_PORT] = 1U << PIN_SWCLK_TCK_BIT;
  253. }
  254. // SWDIO/TMS Pin I/O --------------------------------------
  255. /** SWDIO/TMS I/O pin: Get Input.
  256. \return Current status of the SWDIO/TMS DAP hardware I/O pin.
  257. */
  258. __STATIC_FORCEINLINE uint32_t PIN_SWDIO_TMS_IN (void) {
  259. return ((LPC_GPIO_PORT->PIN[PIN_SWDIO_TMS_PORT] >> PIN_SWDIO_TMS_BIT) & 1U);
  260. }
  261. /** SWDIO/TMS I/O pin: Set Output to High.
  262. Set the SWDIO/TMS DAP hardware I/O pin to high level.
  263. */
  264. __STATIC_FORCEINLINE void PIN_SWDIO_TMS_SET (void) {
  265. LPC_GPIO_PORT->SET[PIN_SWDIO_TMS_PORT] = 1U << PIN_SWDIO_TMS_BIT;
  266. }
  267. /** SWDIO/TMS I/O pin: Set Output to Low.
  268. Set the SWDIO/TMS DAP hardware I/O pin to low level.
  269. */
  270. __STATIC_FORCEINLINE void PIN_SWDIO_TMS_CLR (void) {
  271. LPC_GPIO_PORT->CLR[PIN_SWDIO_TMS_PORT] = 1U << PIN_SWDIO_TMS_BIT;
  272. }
  273. /** SWDIO I/O pin: Get Input (used in SWD mode only).
  274. \return Current status of the SWDIO DAP hardware I/O pin.
  275. */
  276. __STATIC_FORCEINLINE uint32_t PIN_SWDIO_IN (void) {
  277. return (LPC_GPIO_PORT->MPIN[PIN_SWDIO_TMS_PORT] >> PIN_SWDIO_TMS_BIT);
  278. }
  279. /** SWDIO I/O pin: Set Output (used in SWD mode only).
  280. \param bit Output value for the SWDIO DAP hardware I/O pin.
  281. */
  282. __STATIC_FORCEINLINE void PIN_SWDIO_OUT (uint32_t bit) {
  283. LPC_GPIO_PORT->MPIN[PIN_SWDIO_TMS_PORT] = bit << PIN_SWDIO_TMS_BIT;
  284. }
  285. /** SWDIO I/O pin: Switch to Output mode (used in SWD mode only).
  286. Configure the SWDIO DAP hardware I/O pin to output mode. This function is
  287. called prior \ref PIN_SWDIO_OUT function calls.
  288. */
  289. __STATIC_FORCEINLINE void PIN_SWDIO_OUT_ENABLE (void) {
  290. LPC_GPIO_PORT->SET[PIN_SWDIO_OE_PORT] = 1U << PIN_SWDIO_OE_BIT;
  291. }
  292. /** SWDIO I/O pin: Switch to Input mode (used in SWD mode only).
  293. Configure the SWDIO DAP hardware I/O pin to input mode. This function is
  294. called prior \ref PIN_SWDIO_IN function calls.
  295. */
  296. __STATIC_FORCEINLINE void PIN_SWDIO_OUT_DISABLE (void) {
  297. LPC_GPIO_PORT->CLR[PIN_SWDIO_OE_PORT] = 1U << PIN_SWDIO_OE_BIT;
  298. }
  299. // TDI Pin I/O ---------------------------------------------
  300. /** TDI I/O pin: Get Input.
  301. \return Current status of the TDI DAP hardware I/O pin.
  302. */
  303. __STATIC_FORCEINLINE uint32_t PIN_TDI_IN (void) {
  304. return ((LPC_GPIO_PORT->PIN [PIN_TDI_PORT] >> PIN_TDI_BIT) & 1U);
  305. }
  306. /** TDI I/O pin: Set Output.
  307. \param bit Output value for the TDI DAP hardware I/O pin.
  308. */
  309. __STATIC_FORCEINLINE void PIN_TDI_OUT (uint32_t bit) {
  310. LPC_GPIO_PORT->MPIN[PIN_TDI_PORT] = bit << PIN_TDI_BIT;
  311. }
  312. // TDO Pin I/O ---------------------------------------------
  313. /** TDO I/O pin: Get Input.
  314. \return Current status of the TDO DAP hardware I/O pin.
  315. */
  316. __STATIC_FORCEINLINE uint32_t PIN_TDO_IN (void) {
  317. return ((LPC_GPIO_PORT->PIN[PIN_TDO_PORT] >> PIN_TDO_BIT) & 1U);
  318. }
  319. // nTRST Pin I/O -------------------------------------------
  320. /** nTRST I/O pin: Get Input.
  321. \return Current status of the nTRST DAP hardware I/O pin.
  322. */
  323. __STATIC_FORCEINLINE uint32_t PIN_nTRST_IN (void) {
  324. return (0U); // Not available
  325. }
  326. /** nTRST I/O pin: Set Output.
  327. \param bit JTAG TRST Test Reset pin status:
  328. - 0: issue a JTAG TRST Test Reset.
  329. - 1: release JTAG TRST Test Reset.
  330. */
  331. __STATIC_FORCEINLINE void PIN_nTRST_OUT (uint32_t bit) {
  332. ; // Not available
  333. }
  334. // nRESET Pin I/O------------------------------------------
  335. /** nRESET I/O pin: Get Input.
  336. \return Current status of the nRESET DAP hardware I/O pin.
  337. */
  338. __STATIC_FORCEINLINE uint32_t PIN_nRESET_IN (void) {
  339. return ((LPC_GPIO_PORT->PIN[PIN_nRESET_PORT] >> PIN_nRESET_BIT) & 1U);
  340. }
  341. /** nRESET I/O pin: Set Output.
  342. \param bit target device hardware reset pin status:
  343. - 0: issue a device hardware reset.
  344. - 1: release device hardware reset.
  345. */
  346. __STATIC_FORCEINLINE void PIN_nRESET_OUT (uint32_t bit) {
  347. if (bit) {
  348. LPC_GPIO_PORT->DIR[PIN_nRESET_PORT] &= ~(1U << PIN_nRESET_BIT);
  349. LPC_GPIO_PORT->CLR[PIN_nRESET_OE_PORT] = (1U << PIN_nRESET_OE_BIT);
  350. } else {
  351. LPC_GPIO_PORT->SET[PIN_nRESET_OE_PORT] = (1U << PIN_nRESET_OE_BIT);
  352. LPC_GPIO_PORT->DIR[PIN_nRESET_PORT] |= (1U << PIN_nRESET_BIT);
  353. }
  354. }
  355. ///@}
  356. //**************************************************************************************************
  357. /**
  358. \defgroup DAP_Config_LEDs_gr CMSIS-DAP Hardware Status LEDs
  359. \ingroup DAP_ConfigIO_gr
  360. @{
  361. CMSIS-DAP Hardware may provide LEDs that indicate the status of the CMSIS-DAP Debug Unit.
  362. It is recommended to provide the following LEDs for status indication:
  363. - Connect LED: is active when the DAP hardware is connected to a debugger.
  364. - Running LED: is active when the debugger has put the target device into running state.
  365. */
  366. /** Debug Unit: Set status of Connected LED.
  367. \param bit status of the Connect LED.
  368. - 1: Connect LED ON: debugger is connected to CMSIS-DAP Debug Unit.
  369. - 0: Connect LED OFF: debugger is not connected to CMSIS-DAP Debug Unit.
  370. */
  371. __STATIC_INLINE void LED_CONNECTED_OUT (uint32_t bit) {
  372. LPC_GPIO_PORT->B[32*LED_CONNECTED_PORT + LED_CONNECTED_BIT] = bit;
  373. }
  374. /** Debug Unit: Set status Target Running LED.
  375. \param bit status of the Target Running LED.
  376. - 1: Target Running LED ON: program execution in target started.
  377. - 0: Target Running LED OFF: program execution in target stopped.
  378. */
  379. __STATIC_INLINE void LED_RUNNING_OUT (uint32_t bit) {
  380. ; // Not available
  381. }
  382. ///@}
  383. //**************************************************************************************************
  384. /**
  385. \defgroup DAP_Config_Timestamp_gr CMSIS-DAP Timestamp
  386. \ingroup DAP_ConfigIO_gr
  387. @{
  388. Access function for Test Domain Timer.
  389. The value of the Test Domain Timer in the Debug Unit is returned by the function \ref TIMESTAMP_GET. By
  390. default, the DWT timer is used. The frequency of this timer is configured with \ref TIMESTAMP_CLOCK.
  391. */
  392. /** Get timestamp of Test Domain Timer.
  393. \return Current timestamp value.
  394. */
  395. __STATIC_INLINE uint32_t TIMESTAMP_GET (void) {
  396. return (DWT->CYCCNT);
  397. }
  398. ///@}
  399. //**************************************************************************************************
  400. /**
  401. \defgroup DAP_Config_Initialization_gr CMSIS-DAP Initialization
  402. \ingroup DAP_ConfigIO_gr
  403. @{
  404. CMSIS-DAP Hardware I/O and LED Pins are initialized with the function \ref DAP_SETUP.
  405. */
  406. /** Setup of the Debug Unit I/O pins and LEDs (called when Debug Unit is initialized).
  407. This function performs the initialization of the CMSIS-DAP Hardware I/O Pins and the
  408. Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled and set:
  409. - I/O clock system enabled.
  410. - all I/O pins: input buffer enabled, output pins are set to HighZ mode.
  411. - for nTRST, nRESET a weak pull-up (if available) is enabled.
  412. - LED output pins are enabled and LEDs are turned off.
  413. */
  414. __STATIC_INLINE void DAP_SETUP (void) {
  415. /* Enable clock and init GPIO outputs */
  416. LPC_CCU1->CLK_M4_GPIO_CFG = CCU_CLK_CFG_AUTO | CCU_CLK_CFG_RUN;
  417. while (!(LPC_CCU1->CLK_M4_GPIO_STAT & CCU_CLK_STAT_RUN));
  418. /* Configure I/O pins: function number, input buffer enabled, */
  419. /* no pull-up/down except nRESET (pull-up) */
  420. LPC_SCU->SFSP1_17 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* SWCLK/TCK: GPIO0[12] */
  421. LPC_SCU->SFSP1_6 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* SWDIO/TMS: GPIO1[9] */
  422. LPC_SCU->SFSP1_5 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* SWDIO_OE: GPIO1[8] */
  423. LPC_SCU->SFSP1_18 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* TDI: GPIO0[13] */
  424. LPC_SCU->SFSP1_14 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* TDO: GPIO1[7] */
  425. LPC_SCU->SFSP2_5 = 4U | SCU_SFS_EZI; /* nRESET: GPIO5[5] */
  426. LPC_SCU->SFSP2_6 = 4U | SCU_SFS_EPUN|SCU_SFS_EZI; /* nRESET_OE: GPIO5[6] */
  427. LPC_SCU->SFSP1_1 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* LED: GPIO0[8] */
  428. /* Configure: SWCLK/TCK, SWDIO/TMS, SWDIO_OE, TDI as outputs (high level) */
  429. /* TDO as input */
  430. /* nRESET as input with output latch set to low level */
  431. /* nRESET_OE as output (low level) */
  432. LPC_GPIO_PORT->SET[PIN_SWCLK_TCK_PORT] = (1U << PIN_SWCLK_TCK_BIT);
  433. LPC_GPIO_PORT->SET[PIN_SWDIO_TMS_PORT] = (1U << PIN_SWDIO_TMS_BIT);
  434. LPC_GPIO_PORT->SET[PIN_SWDIO_OE_PORT] = (1U << PIN_SWDIO_OE_BIT);
  435. LPC_GPIO_PORT->SET[PIN_TDI_PORT] = (1U << PIN_TDI_BIT);
  436. LPC_GPIO_PORT->CLR[PIN_nRESET_PORT] = (1U << PIN_nRESET_BIT);
  437. LPC_GPIO_PORT->CLR[PIN_nRESET_OE_PORT] = (1U << PIN_nRESET_OE_BIT);
  438. LPC_GPIO_PORT->DIR[PIN_SWCLK_TCK_PORT] |= (1U << PIN_SWCLK_TCK_BIT);
  439. LPC_GPIO_PORT->DIR[PIN_SWDIO_TMS_PORT] |= (1U << PIN_SWDIO_TMS_BIT);
  440. LPC_GPIO_PORT->DIR[PIN_SWDIO_OE_PORT] |= (1U << PIN_SWDIO_OE_BIT);
  441. LPC_GPIO_PORT->DIR[PIN_TDI_PORT] |= (1U << PIN_TDI_BIT);
  442. LPC_GPIO_PORT->DIR[PIN_TDO_PORT] &= ~(1U << PIN_TDO_BIT);
  443. LPC_GPIO_PORT->DIR[PIN_nRESET_PORT] &= ~(1U << PIN_nRESET_BIT);
  444. LPC_GPIO_PORT->DIR[PIN_nRESET_OE_PORT] |= (1U << PIN_nRESET_OE_BIT);
  445. /* Configure: LED as output (turned off) */
  446. LPC_GPIO_PORT->CLR[LED_CONNECTED_PORT] = (1U << LED_CONNECTED_BIT);
  447. LPC_GPIO_PORT->DIR[LED_CONNECTED_PORT] |= (1U << LED_CONNECTED_BIT);
  448. /* Configure Peripheral Interrupt Priorities */
  449. NVIC_SetPriority(USB0_IRQn, 1U);
  450. }
  451. /** Reset Target Device with custom specific I/O pin or command sequence.
  452. This function allows the optional implementation of a device specific reset sequence.
  453. It is called when the command \ref DAP_ResetTarget and is for example required
  454. when a device needs a time-critical unlock sequence that enables the debug port.
  455. \return 0 = no device specific reset sequence is implemented.\n
  456. 1 = a device specific reset sequence is implemented.
  457. */
  458. __STATIC_INLINE uint8_t RESET_TARGET (void) {
  459. return (0U); // change to '1' when a device reset sequence is implemented
  460. }
  461. ///@}
  462. #endif /* __DAP_CONFIG_H__ */