硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2453|回复: 1
收起左侧

[玩转DAPLINK] 优化完善USB2.0高速版DAPLINK的一些细节设置

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106974
QQ
发表于 2020-11-3 03:04:01 | 显示全部楼层 |阅读模式


引脚:
  1. Standard I/O Pins of the CMSIS-DAP Hardware Debug Port support standard JTAG mode
  2. and Serial Wire Debug (SWD) mode. In SWD mode only 2 pins are required to implement the debug
  3. interface of a device. The following I/O Pins are provided:

  4. JTAG I/O Pin                 | SWD I/O Pin          | CMSIS-DAP Hardware pin mode
  5. ---------------------------- | -------------------- | ---------------------------------------------
  6. TCK: Test Clock              | SWCLK: Clock         | Output Push/Pull
  7. TMS: Test Mode Select        | SWDIO: Data I/O      | Output Push/Pull; Input (for receiving data)
  8. TDI: Test Data Input         |                      | Output Push/Pull
  9. TDO: Test Data Output        |                      | Input            
  10. nTRST: Test Reset (optional) |                      | Output Open Drain with pull-up resistor
  11. nRESET: Device Reset         | nRESET: Device Reset | Output Open Drain with pull-up resistor


  12. DAP Hardware I/O Pin Access Functions
  13. -------------------------------------
  14. The various I/O Pins are accessed by functions that implement the Read, Write, Set, or Clear to
  15. these I/O Pins.

  16. For the SWDIO I/O Pin there are additional functions that are called in SWD I/O mode only.
  17. This functions are provided to achieve faster I/O that is possible with some advanced GPIO
  18. peripherals that can independently write/read a single I/O pin without affecting any other pins
  19. of the same I/O port. The following SWDIO I/O Pin functions are provided:
  20. - \ref PIN_SWDIO_OUT_ENABLE to enable the output mode from the DAP hardware.
  21. - \ref PIN_SWDIO_OUT_DISABLE to enable the input mode to the DAP hardware.
  22. - \ref PIN_SWDIO_IN to read from the SWDIO I/O pin with utmost possible speed.
  23. - \ref PIN_SWDIO_OUT to write to the SWDIO I/O pin with utmost possible speed.
  24. */
复制代码




回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106974
QQ
 楼主| 发表于 2020-11-3 14:28:12 | 显示全部楼层


  1. /**
  2. * @file    DAP_config.h
  3. * @brief
  4. *
  5. * DAPLink Interface Firmware
  6. * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
  7. * SPDX-License-Identifier: Apache-2.0
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  10. * not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  17. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */

  21. #ifndef __DAP_CONFIG_H__
  22. #define __DAP_CONFIG_H__

  23. #include "stm32f1xx.h"
  24. #include "stdint.h"
  25. #include "cmsis_os2.h"
  26. #include "IO_Config.h"
  27. #include "uart.h"
  28. //#include "debug_cm.h"
  29. //#include "swd_host.h"
  30. //**************************************************************************************************
  31. /**
  32. \defgroup DAP_Config_Debug_gr CMSIS-DAP Debug Unit Information
  33. \ingroup DAP_ConfigIO_gr
  34. @{
  35. Provides definitions about:
  36. - Definition of Cortex-M processor parameters used in CMSIS-DAP Debug Unit.
  37. - Debug Unit communication packet size.
  38. - Debug Access Port communication mode (JTAG or SWD).
  39. - Optional information about a connected Target Device (for Evaluation Boards).
  40. */

  41. /// Processor Clock of the Cortex-M MCU used in the Debug Unit.
  42. /// This value is used to calculate the SWD/JTAG clock speed.
  43. #define CPU_CLOCK               SystemCoreClock        ///< Specifies the CPU Clock in Hz

  44. /// Number of processor cycles for I/O Port write operations.
  45. /// This value is used to calculate the SWD/JTAG clock speed that is generated with I/O
  46. /// Port write operations in the Debug Unit by a Cortex-M MCU. Most Cortex-M processors
  47. /// requrie 2 processor cycles for a I/O Port Write operation.  If the Debug Unit uses
  48. /// a Cortex-M0+ processor with high-speed peripheral I/O only 1 processor cycle might be
  49. /// requrired.
  50. #define IO_PORT_WRITE_CYCLES    2               ///< I/O Cycles: 2=default, 1=Cortex-M0+ fast I/0

  51. /// Indicate that Serial Wire Debug (SWD) communication mode is available at the Debug Access Port.
  52. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  53. #define DAP_SWD                 1               ///< SWD Mode:  1 = available, 0 = not available

  54. /// Indicate that JTAG communication mode is available at the Debug Port.
  55. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  56. #define DAP_JTAG                0               ///< JTAG Mode: 1 = available, 0 = not available.

  57. /// Configure maximum number of JTAG devices on the scan chain connected to the Debug Access Port.
  58. /// This setting impacts the RAM requirements of the Debug Unit. Valid range is 1 .. 255.
  59. #define DAP_JTAG_DEV_CNT        0               ///< Maximum number of JTAG devices on scan chain

  60. /// Default communication mode on the Debug Access Port.
  61. /// Used for the command \ref DAP_Connect when Port Default mode is selected.
  62. #define DAP_DEFAULT_PORT        1               ///< Default JTAG/SWJ Port Mode: 1 = SWD, 2 = JTAG.

  63. /// Default communication speed on the Debug Access Port for SWD and JTAG mode.
  64. /// Used to initialize the default SWD/JTAG clock frequency.
  65. /// The command \ref DAP_SWJ_Clock can be used to overwrite this default setting.
  66. #define DAP_DEFAULT_SWJ_CLOCK   5000000         ///< Default SWD/JTAG clock frequency in Hz.

  67. /// Maximum Package Size for Command and Response data.
  68. /// This configuration settings is used to optimized the communication performance with the
  69. /// debugger and depends on the USB peripheral. Change setting to 1024 for High-Speed USB.
  70. #define DAP_PACKET_SIZE        64              ///< USB: 64 = Full-Speed, 1024 = High-Speed.

  71. /// Maximum Package Buffers for Command and Response data.
  72. /// This configuration settings is used to optimized the communication performance with the
  73. /// debugger and depends on the USB peripheral. For devices with limited RAM or USB buffer the
  74. /// setting can be reduced (valid range is 1 .. 255). Change setting to 4 for High-Speed USB.
  75. #define DAP_PACKET_COUNT       4              ///< Buffers: 64 = Full-Speed, 4 = High-Speed.

  76. /// Indicate that UART Serial Wire Output (SWO) trace is available.
  77. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  78. #define SWO_UART                0               ///< SWO UART:  1 = available, 0 = not available

  79. /// Maximum SWO UART Baudrate
  80. #define SWO_UART_MAX_BAUDRATE   10000000U       ///< SWO UART Maximum Baudrate in Hz

  81. /// Indicate that Manchester Serial Wire Output (SWO) trace is available.
  82. /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
  83. #define SWO_MANCHESTER          0               ///< SWO Manchester:  1 = available, 0 = not available

  84. /// SWO Trace Buffer Size.
  85. #define SWO_BUFFER_SIZE         4096U           ///< SWO Trace Buffer Size in bytes (must be 2^n)


  86. /// Debug Unit is connected to fixed Target Device.
  87. /// The Debug Unit may be part of an evaluation board and always connected to a fixed
  88. /// known device.  In this case a Device Vendor and Device Name string is stored which
  89. /// may be used by the debugger or IDE to configure device parameters.
  90. #define TARGET_DEVICE_FIXED     0               ///< Target Device: 1 = known, 0 = unknown;

  91. #if TARGET_DEVICE_FIXED
  92. #define TARGET_DEVICE_VENDOR    ""              ///< String indicating the Silicon Vendor
  93. #define TARGET_DEVICE_NAME      ""              ///< String indicating the Target Device
  94. #endif

  95. ///@}


  96. static __inline void pin_out_init(GPIO_TypeDef* GPIOx, uint8_t pin_bit)
  97. {
  98.     if(pin_bit >= 8)
  99.     {
  100.         GPIOx->CRH &= ~(0x0000000F << ((pin_bit-8) << 2));
  101.         GPIOx->CRH |= ( ((uint32_t)(0x00|0x03) & 0x0F) << ((pin_bit-8) << 2) );
  102.     }
  103.     else
  104.     {
  105.         GPIOx->CRL &= ~(0x0000000F << ((pin_bit) << 2));
  106.         GPIOx->CRL |= ( ((uint32_t)(0x00|0x03) & 0x0F) << ((pin_bit) << 2) );
  107.     }
  108. }

  109. static __inline void pin_out_od_init(GPIO_TypeDef* GPIOx, uint8_t pin_bit)
  110. {
  111.     if(pin_bit >= 8)
  112.     {
  113.         GPIOx->CRH &= ~(0x0000000F << ((pin_bit-8) << 2));
  114.         GPIOx->CRH |= ( ((uint32_t)(0x04|0x03) & 0x0F) << ((pin_bit-8) << 2) );
  115.     }
  116.     else
  117.     {
  118.         GPIOx->CRL &= ~(0x0000000F << ((pin_bit) << 2));
  119.         GPIOx->CRL |= ( ((uint32_t)(0x04|0x03) & 0x0F) << ((pin_bit) << 2) );
  120.     }
  121. }

  122. static __inline void pin_in_init(GPIO_TypeDef* GPIOx, uint8_t pin_bit, uint8_t mode)
  123. {
  124.     uint8_t config;
  125.     if(mode == 1)
  126.         config = 0x08; //Up
  127.     else if(mode == 2)
  128.         config = 0x08; //down
  129.     else
  130.         config = 0x00; //GPIO_Mode_AIN

  131.     if(pin_bit >= 8)
  132.     {
  133.         GPIOx->CRH &= ~(0x0000000F << ((pin_bit-8) << 2));
  134.         GPIOx->CRH |= ( ((uint32_t)(config) & 0x0F) << ((pin_bit-8) << 2) );
  135.         if(mode == 1)
  136.             GPIOx->BSRR = (((uint32_t)0x01) << pin_bit);
  137.         else if(mode == 2)
  138.             GPIOx->BRR = (((uint32_t)0x01) << pin_bit);
  139.     }
  140.     else
  141.     {
  142.         GPIOx->CRL &= ~(0x0000000F << ((pin_bit) << 2));
  143.         GPIOx->CRL |= ( ((uint32_t)(config) & 0x0F) << ((pin_bit) << 2) );
  144.         if(mode == 1)
  145.             GPIOx->BSRR = (((uint32_t)0x01) << pin_bit);
  146.         else if(mode == 2)
  147.             GPIOx->BRR = (((uint32_t)0x01) << pin_bit);
  148.     }
  149. }
  150. //**************************************************************************************************
  151. /**
  152. \defgroup DAP_Config_PortIO_gr CMSIS-DAP Hardware I/O Pin Access
  153. \ingroup DAP_ConfigIO_gr
  154. @{

  155. Standard I/O Pins of the CMSIS-DAP Hardware Debug Port support standard JTAG mode
  156. and Serial Wire Debug (SWD) mode. In SWD mode only 2 pins are required to implement the debug
  157. interface of a device. The following I/O Pins are provided:

  158. JTAG I/O Pin                 | SWD I/O Pin          | CMSIS-DAP Hardware pin mode
  159. ---------------------------- | -------------------- | ---------------------------------------------
  160. TCK: Test Clock              | SWCLK: Clock         | Output Push/Pull
  161. TMS: Test Mode Select        | SWDIO: Data I/O      | Output Push/Pull; Input (for receiving data)
  162. TDI: Test Data Input         |                      | Output Push/Pull
  163. TDO: Test Data Output        |                      | Input
  164. nTRST: Test Reset (optional) |                      | Output Open Drain with pull-up resistor
  165. nRESET: Device Reset         | nRESET: Device Reset | Output Open Drain with pull-up resistor


  166. DAP Hardware I/O Pin Access Functions
  167. -------------------------------------
  168. The various I/O Pins are accessed by functions that implement the Read, Write, Set, or Clear to
  169. these I/O Pins.

  170. For the SWDIO I/O Pin there are additional functions that are called in SWD I/O mode only.
  171. This functions are provided to achieve faster I/O that is possible with some advanced GPIO
  172. peripherals that can independently write/read a single I/O pin without affecting any other pins
  173. of the same I/O port. The following SWDIO I/O Pin functions are provided:
  174. - \ref PIN_SWDIO_OUT_ENABLE to enable the output mode from the DAP hardware.
  175. - \ref PIN_SWDIO_OUT_DISABLE to enable the input mode to the DAP hardware.
  176. - \ref PIN_SWDIO_IN to read from the SWDIO I/O pin with utmost possible speed.
  177. - \ref PIN_SWDIO_OUT to write to the SWDIO I/O pin with utmost possible speed.
  178. */


  179. // Configure DAP I/O pins ------------------------------

  180. /** Setup JTAG I/O pins: TCK, TMS, TDI, TDO, nTRST, and nRESET.
  181. Configures the DAP Hardware I/O pins for JTAG mode:
  182. - TCK, TMS, TDI, nTRST, nRESET to output mode and set to high level.
  183. - TDO to input mode.
  184. */
  185. static __inline void PORT_JTAG_SETUP(void)
  186. {
  187. #if (DAP_JTAG != 0)

  188. #endif
  189. }

  190. /** Setup SWD I/O pins: SWCLK, SWDIO, and nRESET.
  191. Configures the DAP Hardware I/O pins for Serial Wire Debug (SWD) mode:
  192. - SWCLK, SWDIO, nRESET to output mode and set to default high level.
  193. - TDI, TMS, nTRST to HighZ mode (pins are unused in SWD mode).
  194. */
  195. static __inline void PORT_SWD_SETUP(void)
  196. {
  197.     // Set SWCLK HIGH
  198.     pin_out_init(SWCLK_TCK_PIN_PORT, SWCLK_TCK_PIN_Bit);
  199.     SWCLK_TCK_PIN_PORT->BSRR = SWCLK_TCK_PIN;
  200.     // Set SWDIO HIGH
  201.     pin_out_init(SWDIO_OUT_PIN_PORT, SWDIO_OUT_PIN_Bit);
  202.     SWDIO_OUT_PIN_PORT->BSRR = SWDIO_OUT_PIN;

  203.     pin_in_init(SWDIO_IN_PIN_PORT, SWDIO_IN_PIN_Bit, 1);
  204.     // Set RESET HIGH
  205.     pin_out_od_init(nRESET_PIN_PORT, nRESET_PIN_Bit);//TODO - fix reset logic
  206.     nRESET_PIN_PORT->BSRR = nRESET_PIN;
  207. }

  208. /** Disable JTAG/SWD I/O Pins.
  209. Disables the DAP Hardware I/O pins which configures:
  210. - TCK/SWCLK, TMS/SWDIO, TDI, TDO, nTRST, nRESET to High-Z mode.
  211. */
  212. static __inline void PORT_OFF(void)
  213. {
  214.     pin_in_init(SWCLK_TCK_PIN_PORT, SWCLK_TCK_PIN_Bit, 0);
  215.     pin_in_init(SWDIO_OUT_PIN_PORT, SWDIO_OUT_PIN_Bit, 0);
  216.     pin_in_init(SWDIO_IN_PIN_PORT, SWDIO_IN_PIN_Bit, 0);
  217. }

  218. // SWCLK/TCK I/O pin -------------------------------------

  219. /** SWCLK/TCK I/O pin: Get Input.
  220. \return Current status of the SWCLK/TCK DAP hardware I/O pin.
  221. */
  222. static __forceinline uint32_t PIN_SWCLK_TCK_IN(void)
  223. {
  224.     return ((SWCLK_TCK_PIN_PORT->ODR & SWCLK_TCK_PIN) ? 1 : 0);
  225. }

  226. /** SWCLK/TCK I/O pin: Set Output to High.
  227. Set the SWCLK/TCK DAP hardware I/O pin to high level.
  228. */
  229. static __forceinline void PIN_SWCLK_TCK_SET(void)
  230. {
  231.     SWCLK_TCK_PIN_PORT->BSRR = SWCLK_TCK_PIN;
  232. }

  233. /** SWCLK/TCK I/O pin: Set Output to Low.
  234. Set the SWCLK/TCK DAP hardware I/O pin to low level.
  235. */
  236. static __forceinline void PIN_SWCLK_TCK_CLR(void)
  237. {
  238.     SWCLK_TCK_PIN_PORT->BRR = SWCLK_TCK_PIN;
  239. }

  240. // SWDIO/TMS Pin I/O --------------------------------------

  241. /** SWDIO/TMS I/O pin: Get Input.
  242. \return Current status of the SWDIO/TMS DAP hardware I/O pin.
  243. */
  244. static __forceinline uint32_t PIN_SWDIO_TMS_IN(void)
  245. {
  246.     return ((SWDIO_IN_PIN_PORT->IDR & SWDIO_IN_PIN) ? 1 : 0);
  247. }

  248. /** SWDIO/TMS I/O pin: Set Output to High.
  249. Set the SWDIO/TMS DAP hardware I/O pin to high level.
  250. */
  251. static __forceinline void PIN_SWDIO_TMS_SET(void)
  252. {
  253.     SWDIO_OUT_PIN_PORT->BSRR = SWDIO_OUT_PIN;
  254. }

  255. /** SWDIO/TMS I/O pin: Set Output to Low.
  256. Set the SWDIO/TMS DAP hardware I/O pin to low level.
  257. */
  258. static __forceinline void PIN_SWDIO_TMS_CLR(void)
  259. {
  260.     SWDIO_OUT_PIN_PORT->BRR = SWDIO_OUT_PIN;
  261. }

  262. /** SWDIO I/O pin: Get Input (used in SWD mode only).
  263. \return Current status of the SWDIO DAP hardware I/O pin.
  264. */
  265. static __forceinline uint32_t PIN_SWDIO_IN(void)
  266. {
  267.     return ((SWDIO_IN_PIN_PORT->IDR & SWDIO_IN_PIN) ? 1 : 0);
  268. }

  269. /** SWDIO I/O pin: Set Output (used in SWD mode only).
  270. \param bit Output value for the SWDIO DAP hardware I/O pin.
  271. */
  272. static __forceinline void PIN_SWDIO_OUT(uint32_t bit)
  273. {
  274.     if (bit & 1)
  275.         SWDIO_OUT_PIN_PORT->BSRR = SWDIO_OUT_PIN;
  276.     else
  277.         SWDIO_OUT_PIN_PORT->BRR = SWDIO_OUT_PIN;
  278. }

  279. /** SWDIO I/O pin: Switch to Output mode (used in SWD mode only).
  280. Configure the SWDIO DAP hardware I/O pin to output mode. This function is
  281. called prior \ref PIN_SWDIO_OUT function calls.
  282. */
  283. static __forceinline void PIN_SWDIO_OUT_ENABLE(void)
  284. {
  285.     pin_out_init(SWDIO_OUT_PIN_PORT, SWDIO_OUT_PIN_Bit);
  286.     SWDIO_OUT_PIN_PORT->BRR = SWDIO_OUT_PIN;
  287. }

  288. /** SWDIO I/O pin: Switch to Input mode (used in SWD mode only).
  289. Configure the SWDIO DAP hardware I/O pin to input mode. This function is
  290. called prior \ref PIN_SWDIO_IN function calls.
  291. */
  292. static __forceinline void PIN_SWDIO_OUT_DISABLE(void)
  293. {
  294.     pin_in_init(SWDIO_OUT_PIN_PORT, SWDIO_OUT_PIN_Bit, 0);
  295.     SWDIO_OUT_PIN_PORT->BSRR = SWDIO_OUT_PIN;
  296. }


  297. // TDI Pin I/O ---------------------------------------------

  298. /** TDI I/O pin: Get Input.
  299. \return Current status of the TDI DAP hardware I/O pin.
  300. */
  301. static __forceinline uint32_t PIN_TDI_IN(void)
  302. {
  303.     return (0);   // Not available
  304. }

  305. /** TDI I/O pin: Set Output.
  306. \param bit Output value for the TDI DAP hardware I/O pin.
  307. */
  308. static __forceinline void PIN_TDI_OUT(uint32_t bit)
  309. {
  310.     ;             // Not available
  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. {
  318.     return (0);   // Not available
  319. }


  320. // nTRST Pin I/O -------------------------------------------

  321. /** nTRST I/O pin: Get Input.
  322. \return Current status of the nTRST DAP hardware I/O pin.
  323. */
  324. static __forceinline uint32_t PIN_nTRST_IN(void)
  325. {
  326.     return (0);   // Not available
  327. }

  328. /** nTRST I/O pin: Set Output.
  329. \param bit JTAG TRST Test Reset pin status:
  330.            - 0: issue a JTAG TRST Test Reset.
  331.            - 1: release JTAG TRST Test Reset.
  332. */
  333. static __forceinline void PIN_nTRST_OUT(uint32_t bit)
  334. {
  335.     ;             // Not available
  336. }

  337. // nRESET Pin I/O------------------------------------------

  338. /** nRESET I/O pin: Get Input.
  339. \return Current status of the nRESET DAP hardware I/O pin.
  340. */
  341. static __forceinline uint32_t PIN_nRESET_IN(void)
  342. {
  343.     return ((nRESET_PIN_PORT->IDR >> nRESET_PIN_Bit) & 1);
  344. }

  345. /** nRESET I/O pin: Set Output.
  346. \param bit target device hardware reset pin status:
  347.            - 0: issue a device hardware reset.
  348.            - 1: release device hardware reset.
  349. */
  350. // TODO - sw specific implementation should be created

  351. static __forceinline void     PIN_nRESET_OUT(uint32_t bit)
  352. {
  353.     if (bit & 1)
  354.         nRESET_PIN_PORT->BSRR = nRESET_PIN;
  355.     else
  356.         nRESET_PIN_PORT->BRR = nRESET_PIN;
  357. }

  358. //**************************************************************************************************
  359. /**
  360. \defgroup DAP_Config_LEDs_gr CMSIS-DAP Hardware Status LEDs
  361. \ingroup DAP_ConfigIO_gr
  362. @{

  363. CMSIS-DAP Hardware may provide LEDs that indicate the status of the CMSIS-DAP Debug Unit.

  364. It is recommended to provide the following LEDs for status indication:
  365. - Connect LED: is active when the DAP hardware is connected to a debugger.
  366. - Running LED: is active when the debugger has put the target device into running state.
  367. */

  368. /** Debug Unit: Set status of Connected LED.
  369. \param bit status of the Connect LED.
  370.            - 1: Connect LED ON: debugger is connected to CMSIS-DAP Debug Unit.
  371.            - 0: Connect LED OFF: debugger is not connected to CMSIS-DAP Debug Unit.
  372. */
  373. static __inline void LED_CONNECTED_OUT(uint32_t bit)
  374. {
  375.     if (bit & 1)
  376.         CONNECTED_LED_PORT->BRR = CONNECTED_LED_PIN; // LED on
  377.     else
  378.         CONNECTED_LED_PORT->BSRR = CONNECTED_LED_PIN;// LED off
  379. }

  380. /** Debug Unit: Set status Target Running LED.
  381. \param bit status of the Target Running LED.
  382.            - 1: Target Running LED ON: program execution in target started.
  383.            - 0: Target Running LED OFF: program execution in target stopped.
  384. */
  385. static __inline void LED_RUNNING_OUT(uint32_t bit)
  386. {
  387.     ;             // Not available
  388. }

  389. ///@}


  390. //**************************************************************************************************
  391. /**
  392. \defgroup DAP_Config_Initialization_gr CMSIS-DAP Initialization
  393. \ingroup DAP_ConfigIO_gr
  394. @{

  395. CMSIS-DAP Hardware I/O and LED Pins are initialized with the function \ref DAP_SETUP.
  396. */

  397. /** Setup of the Debug Unit I/O pins and LEDs (called when Debug Unit is initialized).
  398. This function performs the initialization of the CMSIS-DAP Hardware I/O Pins and the
  399. Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled and set:
  400. - I/O clock system enabled.
  401. - all I/O pins: input buffer enabled, output pins are set to HighZ mode.
  402. - for nTRST, nRESET a weak pull-up (if available) is enabled.
  403. - LED output pins are enabled and LEDs are turned off.
  404. */
  405. static __inline void DAP_SETUP(void)
  406. {
  407.     /* Enable port clock */
  408.     __HAL_RCC_GPIOA_CLK_ENABLE();
  409.     __HAL_RCC_GPIOB_CLK_ENABLE();
  410.     __HAL_RCC_GPIOC_CLK_ENABLE();
  411.     __HAL_RCC_GPIOD_CLK_ENABLE();
  412.     /* Configure I/O pin SWCLK */
  413.     pin_out_init(SWCLK_TCK_PIN_PORT, SWCLK_TCK_PIN_Bit);
  414.     SWCLK_TCK_PIN_PORT->BSRR = SWCLK_TCK_PIN;

  415.     pin_out_init(SWDIO_OUT_PIN_PORT, SWDIO_OUT_PIN_Bit);
  416.     SWDIO_OUT_PIN_PORT->BSRR = SWDIO_OUT_PIN;

  417.     pin_in_init(SWDIO_IN_PIN_PORT, SWDIO_IN_PIN_Bit, 1);

  418.     pin_out_od_init(nRESET_PIN_PORT, nRESET_PIN_Bit);
  419.     nRESET_PIN_PORT->BSRR = nRESET_PIN;

  420.     pin_out_init(CONNECTED_LED_PORT, CONNECTED_LED_PIN_Bit);
  421.     CONNECTED_LED_PORT->BSRR = CONNECTED_LED_PIN;
  422. }

  423. /** Reset Target Device with custom specific I/O pin or command sequence.
  424. This function allows the optional implementation of a device specific reset sequence.
  425. It is called when the command \ref DAP_ResetTarget and is for example required
  426. when a device needs a time-critical unlock sequence that enables the debug port.
  427. \return 0 = no device specific reset sequence is implemented.\n
  428.         1 = a device specific reset sequence is implemented.
  429. */
  430. static __inline uint32_t RESET_TARGET(void)
  431. {
  432.     return (0);              // change to '1' when a device reset sequence is implemented
  433. }

  434. ///@}


  435. #endif /* __DAP_CONFIG_H__ */
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-12 15:04 , Processed in 0.156563 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表