DAP_config.h 27 KB

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