DAP_config.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * Copyright (c) 2013-2021 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: 16. June 2021
  21. * $Revision: V2.1.0
  22. *
  23. * Project: CMSIS-DAP Examples LPC-Link2
  24. * Title: DAP_config.h CMSIS-DAP Configuration File for LPC-Link2
  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 1024U ///< 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 4U ///< 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. /// USART Driver instance number for the UART SWO.
  88. #define SWO_UART_DRIVER 1 ///< USART Driver instance number (Driver_USART#).
  89. /// Maximum SWO UART Baudrate.
  90. #define SWO_UART_MAX_BAUDRATE 10000000U ///< SWO UART Maximum Baudrate in Hz.
  91. /// Indicate that Manchester Serial Wire Output (SWO) trace is available.
  92. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  93. #define SWO_MANCHESTER 0 ///< SWO Manchester: 1 = available, 0 = not available.
  94. /// SWO Trace Buffer Size.
  95. #define SWO_BUFFER_SIZE 8192U ///< SWO Trace Buffer Size in bytes (must be 2^n).
  96. /// SWO Streaming Trace.
  97. #define SWO_STREAM 0 ///< SWO Streaming Trace: 1 = available, 0 = not available.
  98. /// Clock frequency of the Test Domain Timer. Timer value is returned with \ref TIMESTAMP_GET.
  99. #define TIMESTAMP_CLOCK 180000000U ///< Timestamp clock in Hz (0 = timestamps not supported).
  100. /// Indicate that UART Communication Port is available.
  101. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  102. #define DAP_UART 0 ///< DAP UART: 1 = available, 0 = not available.
  103. /// USART Driver instance number for the UART Communication Port.
  104. #define DAP_UART_DRIVER 0 ///< USART Driver instance number (Driver_USART#).
  105. /// UART Receive Buffer Size.
  106. #define DAP_UART_RX_BUFFER_SIZE 1024U ///< Uart Receive Buffer Size in bytes (must be 2^n).
  107. /// UART Transmit Buffer Size.
  108. #define DAP_UART_TX_BUFFER_SIZE 1024U ///< Uart Transmit Buffer Size in bytes (must be 2^n).
  109. /// Indicate that UART Communication via USB COM Port is available.
  110. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  111. #define DAP_UART_USB_COM_PORT 0 ///< USB COM Port: 1 = available, 0 = not available.
  112. /// Debug Unit is connected to fixed Target Device.
  113. /// The Debug Unit may be part of an evaluation board and always connected to a fixed
  114. /// known device. In this case a Device Vendor, Device Name, Board Vendor and Board Name strings
  115. /// are stored and may be used by the debugger or IDE to configure device parameters.
  116. #define TARGET_FIXED 0 ///< Target: 1 = known, 0 = unknown;
  117. #define TARGET_DEVICE_VENDOR "NXP" ///< String indicating the Silicon Vendor
  118. #define TARGET_DEVICE_NAME "Cortex-M" ///< String indicating the Target Device
  119. #define TARGET_BOARD_VENDOR "NXP" ///< String indicating the Board Vendor
  120. #define TARGET_BOARD_NAME "NXP board" ///< String indicating the Board Name
  121. #if TARGET_FIXED != 0
  122. #include <string.h>
  123. static const char TargetDeviceVendor [] = TARGET_DEVICE_VENDOR;
  124. static const char TargetDeviceName [] = TARGET_DEVICE_NAME;
  125. static const char TargetBoardVendor [] = TARGET_BOARD_VENDOR;
  126. static const char TargetBoardName [] = TARGET_BOARD_NAME;
  127. #endif
  128. /** Get Vendor Name string.
  129. \param str Pointer to buffer to store the string (max 60 characters).
  130. \return String length (including terminating NULL character) or 0 (no string).
  131. */
  132. __STATIC_INLINE uint8_t DAP_GetVendorString (char *str) {
  133. (void)str;
  134. return (0U);
  135. }
  136. /** Get Product Name string.
  137. \param str Pointer to buffer to store the string (max 60 characters).
  138. \return String length (including terminating NULL character) or 0 (no string).
  139. */
  140. __STATIC_INLINE uint8_t DAP_GetProductString (char *str) {
  141. (void)str;
  142. return (0U);
  143. }
  144. /** Get Serial Number string.
  145. \param str Pointer to buffer to store the string (max 60 characters).
  146. \return String length (including terminating NULL character) or 0 (no string).
  147. */
  148. __STATIC_INLINE uint8_t DAP_GetSerNumString (char *str) {
  149. (void)str;
  150. return (0U);
  151. }
  152. /** Get Target Device Vendor string.
  153. \param str Pointer to buffer to store the string (max 60 characters).
  154. \return String length (including terminating NULL character) or 0 (no string).
  155. */
  156. __STATIC_INLINE uint8_t DAP_GetTargetDeviceVendorString (char *str) {
  157. #if TARGET_FIXED != 0
  158. uint8_t len;
  159. strcpy(str, TargetDeviceVendor);
  160. len = (uint8_t)(strlen(TargetDeviceVendor) + 1U);
  161. return (len);
  162. #else
  163. (void)str;
  164. return (0U);
  165. #endif
  166. }
  167. /** Get Target Device Name string.
  168. \param str Pointer to buffer to store the string (max 60 characters).
  169. \return String length (including terminating NULL character) or 0 (no string).
  170. */
  171. __STATIC_INLINE uint8_t DAP_GetTargetDeviceNameString (char *str) {
  172. #if TARGET_FIXED != 0
  173. uint8_t len;
  174. strcpy(str, TargetDeviceName);
  175. len = (uint8_t)(strlen(TargetDeviceName) + 1U);
  176. return (len);
  177. #else
  178. (void)str;
  179. return (0U);
  180. #endif
  181. }
  182. /** Get Target Board Vendor string.
  183. \param str Pointer to buffer to store the string (max 60 characters).
  184. \return String length (including terminating NULL character) or 0 (no string).
  185. */
  186. __STATIC_INLINE uint8_t DAP_GetTargetBoardVendorString (char *str) {
  187. #if TARGET_FIXED != 0
  188. uint8_t len;
  189. strcpy(str, TargetBoardVendor);
  190. len = (uint8_t)(strlen(TargetBoardVendor) + 1U);
  191. return (len);
  192. #else
  193. (void)str;
  194. return (0U);
  195. #endif
  196. }
  197. /** Get Target Board Name string.
  198. \param str Pointer to buffer to store the string (max 60 characters).
  199. \return String length (including terminating NULL character) or 0 (no string).
  200. */
  201. __STATIC_INLINE uint8_t DAP_GetTargetBoardNameString (char *str) {
  202. #if TARGET_FIXED != 0
  203. uint8_t len;
  204. strcpy(str, TargetBoardName);
  205. len = (uint8_t)(strlen(TargetBoardName) + 1U);
  206. return (len);
  207. #else
  208. (void)str;
  209. return (0U);
  210. #endif
  211. }
  212. /** Get Product Firmware Version string.
  213. \param str Pointer to buffer to store the string (max 60 characters).
  214. \return String length (including terminating NULL character) or 0 (no string).
  215. */
  216. __STATIC_INLINE uint8_t DAP_GetProductFirmwareVersionString (char *str) {
  217. (void)str;
  218. return (0U);
  219. }
  220. ///@}
  221. // LPC43xx peripheral register bit masks (used by macros)
  222. #define CCU_CLK_CFG_RUN (1U << 0)
  223. #define CCU_CLK_CFG_AUTO (1U << 1)
  224. #define CCU_CLK_STAT_RUN (1U << 0)
  225. #define SCU_SFS_EPD (1U << 3)
  226. #define SCU_SFS_EPUN (1U << 4)
  227. #define SCU_SFS_EHS (1U << 5)
  228. #define SCU_SFS_EZI (1U << 6)
  229. #define SCU_SFS_ZIF (1U << 7)
  230. // Debug Port I/O Pins
  231. // SWCLK/TCK Pin P1_17: GPIO0[12]
  232. #define PIN_SWCLK_TCK_PORT 0
  233. #define PIN_SWCLK_TCK_BIT 12
  234. // SWDIO/TMS Pin P1_6: GPIO1[9]
  235. #define PIN_SWDIO_TMS_PORT 1
  236. #define PIN_SWDIO_TMS_BIT 9
  237. // SWDIO Output Enable Pin P1_5: GPIO1[8]
  238. #define PIN_SWDIO_OE_PORT 1
  239. #define PIN_SWDIO_OE_BIT 8
  240. // TDI Pin P1_18: GPIO0[13]
  241. #define PIN_TDI_PORT 0
  242. #define PIN_TDI_BIT 13
  243. // TDO Pin P1_14: GPIO1[7]
  244. #define PIN_TDO_PORT 1
  245. #define PIN_TDO_BIT 7
  246. // nTRST Pin Not available
  247. #define PIN_nTRST_PORT
  248. #define PIN_nTRST_BIT
  249. // nRESET Pin P2_5: GPIO5[5]
  250. #define PIN_nRESET_PORT 5
  251. #define PIN_nRESET_BIT 5
  252. // nRESET Output Enable Pin P2_6: GPIO5[6]
  253. #define PIN_nRESET_OE_PORT 5
  254. #define PIN_nRESET_OE_BIT 6
  255. // Debug Unit LEDs
  256. // Connected LED P1_1: GPIO0[8]
  257. #define LED_CONNECTED_PORT 0
  258. #define LED_CONNECTED_BIT 8
  259. // Target Running LED Not available
  260. //**************************************************************************************************
  261. /**
  262. \defgroup DAP_Config_PortIO_gr CMSIS-DAP Hardware I/O Pin Access
  263. \ingroup DAP_ConfigIO_gr
  264. @{
  265. Standard I/O Pins of the CMSIS-DAP Hardware Debug Port support standard JTAG mode
  266. and Serial Wire Debug (SWD) mode. In SWD mode only 2 pins are required to implement the debug
  267. interface of a device. The following I/O Pins are provided:
  268. JTAG I/O Pin | SWD I/O Pin | CMSIS-DAP Hardware pin mode
  269. ---------------------------- | -------------------- | ---------------------------------------------
  270. TCK: Test Clock | SWCLK: Clock | Output Push/Pull
  271. TMS: Test Mode Select | SWDIO: Data I/O | Output Push/Pull; Input (for receiving data)
  272. TDI: Test Data Input | | Output Push/Pull
  273. TDO: Test Data Output | | Input
  274. nTRST: Test Reset (optional) | | Output Open Drain with pull-up resistor
  275. nRESET: Device Reset | nRESET: Device Reset | Output Open Drain with pull-up resistor
  276. DAP Hardware I/O Pin Access Functions
  277. -------------------------------------
  278. The various I/O Pins are accessed by functions that implement the Read, Write, Set, or Clear to
  279. these I/O Pins.
  280. For the SWDIO I/O Pin there are additional functions that are called in SWD I/O mode only.
  281. This functions are provided to achieve faster I/O that is possible with some advanced GPIO
  282. peripherals that can independently write/read a single I/O pin without affecting any other pins
  283. of the same I/O port. The following SWDIO I/O Pin functions are provided:
  284. - \ref PIN_SWDIO_OUT_ENABLE to enable the output mode from the DAP hardware.
  285. - \ref PIN_SWDIO_OUT_DISABLE to enable the input mode to the DAP hardware.
  286. - \ref PIN_SWDIO_IN to read from the SWDIO I/O pin with utmost possible speed.
  287. - \ref PIN_SWDIO_OUT to write to the SWDIO I/O pin with utmost possible speed.
  288. */
  289. // Configure DAP I/O pins ------------------------------
  290. // LPC-Link2 HW uses buffers for debug port pins. Therefore it is not
  291. // possible to disable outputs SWCLK/TCK, TDI and they are left active.
  292. // Only SWDIO/TMS output can be disabled but it is also left active.
  293. // nRESET is configured for open drain mode.
  294. /** Setup JTAG I/O pins: TCK, TMS, TDI, TDO, nTRST, and nRESET.
  295. Configures the DAP Hardware I/O pins for JTAG mode:
  296. - TCK, TMS, TDI, nTRST, nRESET to output mode and set to high level.
  297. - TDO to input mode.
  298. */
  299. __STATIC_INLINE void PORT_JTAG_SETUP (void) {
  300. LPC_GPIO_PORT->MASK[PIN_SWDIO_TMS_PORT] = 0U;
  301. LPC_GPIO_PORT->MASK[PIN_TDI_PORT] = ~(1U << PIN_TDI_BIT);
  302. }
  303. /** Setup SWD I/O pins: SWCLK, SWDIO, and nRESET.
  304. Configures the DAP Hardware I/O pins for Serial Wire Debug (SWD) mode:
  305. - SWCLK, SWDIO, nRESET to output mode and set to default high level.
  306. - TDI, nTRST to HighZ mode (pins are unused in SWD mode).
  307. */
  308. __STATIC_INLINE void PORT_SWD_SETUP (void) {
  309. LPC_GPIO_PORT->MASK[PIN_TDI_PORT] = 0U;
  310. LPC_GPIO_PORT->MASK[PIN_SWDIO_TMS_PORT] = ~(1U << PIN_SWDIO_TMS_BIT);
  311. }
  312. /** Disable JTAG/SWD I/O Pins.
  313. Disables the DAP Hardware I/O pins which configures:
  314. - TCK/SWCLK, TMS/SWDIO, TDI, TDO, nTRST, nRESET to High-Z mode.
  315. */
  316. __STATIC_INLINE void PORT_OFF (void) {
  317. LPC_GPIO_PORT->SET[PIN_SWCLK_TCK_PORT] = (1U << PIN_SWCLK_TCK_BIT);
  318. LPC_GPIO_PORT->SET[PIN_SWDIO_TMS_PORT] = (1U << PIN_SWDIO_TMS_BIT);
  319. LPC_GPIO_PORT->SET[PIN_SWDIO_OE_PORT] = (1U << PIN_SWDIO_OE_BIT);
  320. LPC_GPIO_PORT->SET[PIN_TDI_PORT] = (1U << PIN_TDI_BIT);
  321. LPC_GPIO_PORT->DIR[PIN_nRESET_PORT] &= ~(1U << PIN_nRESET_BIT);
  322. LPC_GPIO_PORT->CLR[PIN_nRESET_OE_PORT] = (1U << PIN_nRESET_OE_BIT);
  323. }
  324. // SWCLK/TCK I/O pin -------------------------------------
  325. /** SWCLK/TCK I/O pin: Get Input.
  326. \return Current status of the SWCLK/TCK DAP hardware I/O pin.
  327. */
  328. __STATIC_FORCEINLINE uint32_t PIN_SWCLK_TCK_IN (void) {
  329. return ((LPC_GPIO_PORT->PIN[PIN_SWCLK_TCK_PORT] >> PIN_SWCLK_TCK_BIT) & 1U);
  330. }
  331. /** SWCLK/TCK I/O pin: Set Output to High.
  332. Set the SWCLK/TCK DAP hardware I/O pin to high level.
  333. */
  334. __STATIC_FORCEINLINE void PIN_SWCLK_TCK_SET (void) {
  335. LPC_GPIO_PORT->SET[PIN_SWCLK_TCK_PORT] = 1U << PIN_SWCLK_TCK_BIT;
  336. }
  337. /** SWCLK/TCK I/O pin: Set Output to Low.
  338. Set the SWCLK/TCK DAP hardware I/O pin to low level.
  339. */
  340. __STATIC_FORCEINLINE void PIN_SWCLK_TCK_CLR (void) {
  341. LPC_GPIO_PORT->CLR[PIN_SWCLK_TCK_PORT] = 1U << PIN_SWCLK_TCK_BIT;
  342. }
  343. // SWDIO/TMS Pin I/O --------------------------------------
  344. /** SWDIO/TMS I/O pin: Get Input.
  345. \return Current status of the SWDIO/TMS DAP hardware I/O pin.
  346. */
  347. __STATIC_FORCEINLINE uint32_t PIN_SWDIO_TMS_IN (void) {
  348. return ((LPC_GPIO_PORT->PIN[PIN_SWDIO_TMS_PORT] >> PIN_SWDIO_TMS_BIT) & 1U);
  349. }
  350. /** SWDIO/TMS I/O pin: Set Output to High.
  351. Set the SWDIO/TMS DAP hardware I/O pin to high level.
  352. */
  353. __STATIC_FORCEINLINE void PIN_SWDIO_TMS_SET (void) {
  354. LPC_GPIO_PORT->SET[PIN_SWDIO_TMS_PORT] = 1U << PIN_SWDIO_TMS_BIT;
  355. }
  356. /** SWDIO/TMS I/O pin: Set Output to Low.
  357. Set the SWDIO/TMS DAP hardware I/O pin to low level.
  358. */
  359. __STATIC_FORCEINLINE void PIN_SWDIO_TMS_CLR (void) {
  360. LPC_GPIO_PORT->CLR[PIN_SWDIO_TMS_PORT] = 1U << PIN_SWDIO_TMS_BIT;
  361. }
  362. /** SWDIO I/O pin: Get Input (used in SWD mode only).
  363. \return Current status of the SWDIO DAP hardware I/O pin.
  364. */
  365. __STATIC_FORCEINLINE uint32_t PIN_SWDIO_IN (void) {
  366. return (LPC_GPIO_PORT->MPIN[PIN_SWDIO_TMS_PORT] >> PIN_SWDIO_TMS_BIT);
  367. }
  368. /** SWDIO I/O pin: Set Output (used in SWD mode only).
  369. \param bit Output value for the SWDIO DAP hardware I/O pin.
  370. */
  371. __STATIC_FORCEINLINE void PIN_SWDIO_OUT (uint32_t bit) {
  372. LPC_GPIO_PORT->MPIN[PIN_SWDIO_TMS_PORT] = bit << PIN_SWDIO_TMS_BIT;
  373. }
  374. /** SWDIO I/O pin: Switch to Output mode (used in SWD mode only).
  375. Configure the SWDIO DAP hardware I/O pin to output mode. This function is
  376. called prior \ref PIN_SWDIO_OUT function calls.
  377. */
  378. __STATIC_FORCEINLINE void PIN_SWDIO_OUT_ENABLE (void) {
  379. LPC_GPIO_PORT->SET[PIN_SWDIO_OE_PORT] = 1U << PIN_SWDIO_OE_BIT;
  380. }
  381. /** SWDIO I/O pin: Switch to Input mode (used in SWD mode only).
  382. Configure the SWDIO DAP hardware I/O pin to input mode. This function is
  383. called prior \ref PIN_SWDIO_IN function calls.
  384. */
  385. __STATIC_FORCEINLINE void PIN_SWDIO_OUT_DISABLE (void) {
  386. LPC_GPIO_PORT->CLR[PIN_SWDIO_OE_PORT] = 1U << PIN_SWDIO_OE_BIT;
  387. }
  388. // TDI Pin I/O ---------------------------------------------
  389. /** TDI I/O pin: Get Input.
  390. \return Current status of the TDI DAP hardware I/O pin.
  391. */
  392. __STATIC_FORCEINLINE uint32_t PIN_TDI_IN (void) {
  393. return ((LPC_GPIO_PORT->PIN [PIN_TDI_PORT] >> PIN_TDI_BIT) & 1U);
  394. }
  395. /** TDI I/O pin: Set Output.
  396. \param bit Output value for the TDI DAP hardware I/O pin.
  397. */
  398. __STATIC_FORCEINLINE void PIN_TDI_OUT (uint32_t bit) {
  399. LPC_GPIO_PORT->MPIN[PIN_TDI_PORT] = bit << PIN_TDI_BIT;
  400. }
  401. // TDO Pin I/O ---------------------------------------------
  402. /** TDO I/O pin: Get Input.
  403. \return Current status of the TDO DAP hardware I/O pin.
  404. */
  405. __STATIC_FORCEINLINE uint32_t PIN_TDO_IN (void) {
  406. return ((LPC_GPIO_PORT->PIN[PIN_TDO_PORT] >> PIN_TDO_BIT) & 1U);
  407. }
  408. // nTRST Pin I/O -------------------------------------------
  409. /** nTRST I/O pin: Get Input.
  410. \return Current status of the nTRST DAP hardware I/O pin.
  411. */
  412. __STATIC_FORCEINLINE uint32_t PIN_nTRST_IN (void) {
  413. return (0U); // Not available
  414. }
  415. /** nTRST I/O pin: Set Output.
  416. \param bit JTAG TRST Test Reset pin status:
  417. - 0: issue a JTAG TRST Test Reset.
  418. - 1: release JTAG TRST Test Reset.
  419. */
  420. __STATIC_FORCEINLINE void PIN_nTRST_OUT (uint32_t bit) {
  421. (void) bit;
  422. // Not available
  423. }
  424. // nRESET Pin I/O------------------------------------------
  425. /** nRESET I/O pin: Get Input.
  426. \return Current status of the nRESET DAP hardware I/O pin.
  427. */
  428. __STATIC_FORCEINLINE uint32_t PIN_nRESET_IN (void) {
  429. return ((LPC_GPIO_PORT->PIN[PIN_nRESET_PORT] >> PIN_nRESET_BIT) & 1U);
  430. }
  431. /** nRESET I/O pin: Set Output.
  432. \param bit target device hardware reset pin status:
  433. - 0: issue a device hardware reset.
  434. - 1: release device hardware reset.
  435. */
  436. __STATIC_FORCEINLINE void PIN_nRESET_OUT (uint32_t bit) {
  437. if (bit) {
  438. LPC_GPIO_PORT->DIR[PIN_nRESET_PORT] &= ~(1U << PIN_nRESET_BIT);
  439. LPC_GPIO_PORT->CLR[PIN_nRESET_OE_PORT] = (1U << PIN_nRESET_OE_BIT);
  440. } else {
  441. LPC_GPIO_PORT->SET[PIN_nRESET_OE_PORT] = (1U << PIN_nRESET_OE_BIT);
  442. LPC_GPIO_PORT->DIR[PIN_nRESET_PORT] |= (1U << PIN_nRESET_BIT);
  443. }
  444. }
  445. ///@}
  446. //**************************************************************************************************
  447. /**
  448. \defgroup DAP_Config_LEDs_gr CMSIS-DAP Hardware Status LEDs
  449. \ingroup DAP_ConfigIO_gr
  450. @{
  451. CMSIS-DAP Hardware may provide LEDs that indicate the status of the CMSIS-DAP Debug Unit.
  452. It is recommended to provide the following LEDs for status indication:
  453. - Connect LED: is active when the DAP hardware is connected to a debugger.
  454. - Running LED: is active when the debugger has put the target device into running state.
  455. */
  456. /** Debug Unit: Set status of Connected LED.
  457. \param bit status of the Connect LED.
  458. - 1: Connect LED ON: debugger is connected to CMSIS-DAP Debug Unit.
  459. - 0: Connect LED OFF: debugger is not connected to CMSIS-DAP Debug Unit.
  460. */
  461. __STATIC_INLINE void LED_CONNECTED_OUT (uint32_t bit) {
  462. LPC_GPIO_PORT->B[32*LED_CONNECTED_PORT + LED_CONNECTED_BIT] = (uint8_t)bit;
  463. }
  464. /** Debug Unit: Set status Target Running LED.
  465. \param bit status of the Target Running LED.
  466. - 1: Target Running LED ON: program execution in target started.
  467. - 0: Target Running LED OFF: program execution in target stopped.
  468. */
  469. __STATIC_INLINE void LED_RUNNING_OUT (uint32_t bit) {
  470. (void) bit;
  471. // Not available
  472. }
  473. ///@}
  474. //**************************************************************************************************
  475. /**
  476. \defgroup DAP_Config_Timestamp_gr CMSIS-DAP Timestamp
  477. \ingroup DAP_ConfigIO_gr
  478. @{
  479. Access function for Test Domain Timer.
  480. The value of the Test Domain Timer in the Debug Unit is returned by the function \ref TIMESTAMP_GET. By
  481. default, the DWT timer is used. The frequency of this timer is configured with \ref TIMESTAMP_CLOCK.
  482. */
  483. /** Get timestamp of Test Domain Timer.
  484. \return Current timestamp value.
  485. */
  486. __STATIC_INLINE uint32_t TIMESTAMP_GET (void) {
  487. return (DWT->CYCCNT);
  488. }
  489. ///@}
  490. //**************************************************************************************************
  491. /**
  492. \defgroup DAP_Config_Initialization_gr CMSIS-DAP Initialization
  493. \ingroup DAP_ConfigIO_gr
  494. @{
  495. CMSIS-DAP Hardware I/O and LED Pins are initialized with the function \ref DAP_SETUP.
  496. */
  497. /** Setup of the Debug Unit I/O pins and LEDs (called when Debug Unit is initialized).
  498. This function performs the initialization of the CMSIS-DAP Hardware I/O Pins and the
  499. Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled and set:
  500. - I/O clock system enabled.
  501. - all I/O pins: input buffer enabled, output pins are set to HighZ mode.
  502. - for nTRST, nRESET a weak pull-up (if available) is enabled.
  503. - LED output pins are enabled and LEDs are turned off.
  504. */
  505. __STATIC_INLINE void DAP_SETUP (void) {
  506. /* Enable clock and init GPIO outputs */
  507. LPC_CCU1->CLK_M4_GPIO_CFG = CCU_CLK_CFG_AUTO | CCU_CLK_CFG_RUN;
  508. while (!(LPC_CCU1->CLK_M4_GPIO_STAT & CCU_CLK_STAT_RUN));
  509. /* Configure I/O pins: function number, input buffer enabled, */
  510. /* no pull-up/down except nRESET (pull-up) */
  511. LPC_SCU->SFSP1_17 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* SWCLK/TCK: GPIO0[12] */
  512. LPC_SCU->SFSP1_6 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* SWDIO/TMS: GPIO1[9] */
  513. LPC_SCU->SFSP1_5 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* SWDIO_OE: GPIO1[8] */
  514. LPC_SCU->SFSP1_18 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* TDI: GPIO0[13] */
  515. LPC_SCU->SFSP1_14 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* TDO: GPIO1[7] */
  516. LPC_SCU->SFSP2_5 = 4U | SCU_SFS_EZI; /* nRESET: GPIO5[5] */
  517. LPC_SCU->SFSP2_6 = 4U | SCU_SFS_EPUN|SCU_SFS_EZI; /* nRESET_OE: GPIO5[6] */
  518. LPC_SCU->SFSP1_1 = 0U | SCU_SFS_EPUN|SCU_SFS_EZI; /* LED: GPIO0[8] */
  519. #ifdef TARGET_POWER_EN
  520. LPC_SCU->SFSP3_1 = 4U | SCU_SFS_EPUN|SCU_SFS_EZI; /* Target Power enable P3_1 GPIO5[8] */
  521. #endif
  522. /* Configure: SWCLK/TCK, SWDIO/TMS, SWDIO_OE, TDI as outputs (high level) */
  523. /* TDO as input */
  524. /* nRESET as input with output latch set to low level */
  525. /* nRESET_OE as output (low level) */
  526. LPC_GPIO_PORT->SET[PIN_SWCLK_TCK_PORT] = (1U << PIN_SWCLK_TCK_BIT);
  527. LPC_GPIO_PORT->SET[PIN_SWDIO_TMS_PORT] = (1U << PIN_SWDIO_TMS_BIT);
  528. LPC_GPIO_PORT->SET[PIN_SWDIO_OE_PORT] = (1U << PIN_SWDIO_OE_BIT);
  529. LPC_GPIO_PORT->SET[PIN_TDI_PORT] = (1U << PIN_TDI_BIT);
  530. LPC_GPIO_PORT->CLR[PIN_nRESET_PORT] = (1U << PIN_nRESET_BIT);
  531. LPC_GPIO_PORT->CLR[PIN_nRESET_OE_PORT] = (1U << PIN_nRESET_OE_BIT);
  532. LPC_GPIO_PORT->DIR[PIN_SWCLK_TCK_PORT] |= (1U << PIN_SWCLK_TCK_BIT);
  533. LPC_GPIO_PORT->DIR[PIN_SWDIO_TMS_PORT] |= (1U << PIN_SWDIO_TMS_BIT);
  534. LPC_GPIO_PORT->DIR[PIN_SWDIO_OE_PORT] |= (1U << PIN_SWDIO_OE_BIT);
  535. LPC_GPIO_PORT->DIR[PIN_TDI_PORT] |= (1U << PIN_TDI_BIT);
  536. LPC_GPIO_PORT->DIR[PIN_TDO_PORT] &= ~(1U << PIN_TDO_BIT);
  537. LPC_GPIO_PORT->DIR[PIN_nRESET_PORT] &= ~(1U << PIN_nRESET_BIT);
  538. LPC_GPIO_PORT->DIR[PIN_nRESET_OE_PORT] |= (1U << PIN_nRESET_OE_BIT);
  539. #ifdef TARGET_POWER_EN
  540. /* Target Power enable as output (turned on) */
  541. LPC_GPIO_PORT->SET[5] = (1U << 8);
  542. LPC_GPIO_PORT->DIR[5] |= (1U << 8);
  543. #endif
  544. /* Configure: LED as output (turned off) */
  545. LPC_GPIO_PORT->CLR[LED_CONNECTED_PORT] = (1U << LED_CONNECTED_BIT);
  546. LPC_GPIO_PORT->DIR[LED_CONNECTED_PORT] |= (1U << LED_CONNECTED_BIT);
  547. /* Configure Peripheral Interrupt Priorities */
  548. NVIC_SetPriority(USB0_IRQn, 1U);
  549. }
  550. /** Reset Target Device with custom specific I/O pin or command sequence.
  551. This function allows the optional implementation of a device specific reset sequence.
  552. It is called when the command \ref DAP_ResetTarget and is for example required
  553. when a device needs a time-critical unlock sequence that enables the debug port.
  554. \return 0 = no device specific reset sequence is implemented.\n
  555. 1 = a device specific reset sequence is implemented.
  556. */
  557. __STATIC_INLINE uint8_t RESET_TARGET (void) {
  558. return (0U); // change to '1' when a device reset sequence is implemented
  559. }
  560. ///@}
  561. #endif /* __DAP_CONFIG_H__ */