硬汉嵌入式论坛

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

[玩转DAPLINK] 第4篇:DAPLINK(CMSIS-DAP)引脚配置,LED状态控制,时间戳获取等,含SWD和JTAG

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107217
QQ
发表于 2020-8-31 12:31:50 | 显示全部楼层 |阅读模式
CMSIS-DAP硬件调试端口的标准I/O引脚支持JTAG模式和SWD模式。

JTAG和SWD的IO引脚说明

1.png


对于SWDIO引脚,只有在SWD模式下才能调用。提供此功能的目的是实现更快的I/O,这是某些高级GPIO外设可以实现的,这些外设可以独立地写入/读取单个I/O引脚而不会影响同一I/O端口的任何其他引脚。

提供了以下SWDIO引脚功能:

PIN_SWDIO_OUT_ENABLE  以启用DAP硬件的输出模式。
PIN_SWDIO_OUT_DISABLE 以启用DAP硬件的输入模式。
PIN_SWDIO_IN                  以最大的速度从SWDIO引脚读取。
PIN_SWDIO_OUT               以最大可能的速度写入SWDIO引脚。



配置 DAP I/O

/*
    JTAG模式
    TCK, TMS, TDI, nTRST, nRESET设置为输出高电平
    TDO 设置为输入.
*/
__STATIC_INLINE void PORT_JTAG_SETUP (void) {
}

/**
   SWD模式
   SWCLK, SWDIO, nRESET设置为输出高电平
   TDI, nTRST设置为高阻  (pins are unused in SWD mode).
*/
__STATIC_INLINE void PORT_SWD_SETUP (void) {
}

/**
   禁止 JTAG/SWD 引脚
   TCK/SWCLK, TMS/SWDIO, TDI, TDO, nTRST, nRESET设置为高阻
*/
__STATIC_INLINE void PORT_OFF (void) {
}


配置SWCLK/TCK

读取引脚状态
__STATIC_FORCEINLINE uint32_t PIN_SWCLK_TCK_IN  (void) {
}

设置输出高电平
__STATIC_FORCEINLINE void     PIN_SWCLK_TCK_SET (void) {
}

设置输出低电平
__STATIC_FORCEINLINE void     PIN_SWCLK_TCK_CLR (void) {
}

配置 SWDIO/TMS

读取IO状态
__STATIC_FORCEINLINE uint32_t PIN_SWDIO_TMS_IN  (void) {
  return ((LPC_GPIO_PORT->PIN[PIN_SWDIO_TMS_PORT] >> PIN_SWDIO_TMS_BIT) & 1U);
}

设置输出高电平
__STATIC_FORCEINLINE void     PIN_SWDIO_TMS_SET (void) {
  LPC_GPIO_PORT->SET[PIN_SWDIO_TMS_PORT] = 1U << PIN_SWDIO_TMS_BIT;
}

设置输出低电平
__STATIC_FORCEINLINE void     PIN_SWDIO_TMS_CLR (void) {
  LPC_GPIO_PORT->CLR[PIN_SWDIO_TMS_PORT] = 1U << PIN_SWDIO_TMS_BIT;
}

读取IO状态,仅SWD接口模式使用
__STATIC_FORCEINLINE uint32_t PIN_SWDIO_IN      (void) {
  return (LPC_GPIO_PORT->MPIN[PIN_SWDIO_TMS_PORT] >> PIN_SWDIO_TMS_BIT);
}

设置IO输出值,仅SWD接口模式使用
__STATIC_FORCEINLINE void     PIN_SWDIO_OUT     (uint32_t bit) {
  LPC_GPIO_PORT->MPIN[PIN_SWDIO_TMS_PORT] = bit << PIN_SWDIO_TMS_BIT;
}

使能输出模式,仅SWD接口模式使用
__STATIC_FORCEINLINE void     PIN_SWDIO_OUT_ENABLE  (void) {
  LPC_GPIO_PORT->SET[PIN_SWDIO_OE_PORT] = 1U << PIN_SWDIO_OE_BIT;
}

使能输入模式,仅SWD接口模式使用
__STATIC_FORCEINLINE void     PIN_SWDIO_OUT_DISABLE (void) {
  LPC_GPIO_PORT->CLR[PIN_SWDIO_OE_PORT] = 1U << PIN_SWDIO_OE_BIT;
}

配置TDI

读取
__STATIC_FORCEINLINE uint32_t PIN_TDI_IN  (void) {

}

输出
__STATIC_FORCEINLINE void     PIN_TDI_OUT (uint32_t bit) {

}


配置TDO

读取
__STATIC_FORCEINLINE uint32_t PIN_TDO_IN  (void) {
}


配置nTRST

读取
__STATIC_FORCEINLINE uint32_t PIN_nTRST_IN   (void) {
  return (0U);  // Not available
}

输出
0: issue a JTAG TRST Test Reset.
1: release JTAG TRST Test Reset.
__STATIC_FORCEINLINE void     PIN_nTRST_OUT  (uint32_t bit) {
  ;             // Not available
}


配置nRESET

读取
__STATIC_FORCEINLINE uint32_t PIN_nRESET_IN  (void) {
  return ((LPC_GPIO_PORT->PIN[PIN_nRESET_PORT] >> PIN_nRESET_BIT) & 1U);
}

输出
- 0: issue a device hardware reset.
- 1: release device hardware reset.
__STATIC_FORCEINLINE void     PIN_nRESET_OUT (uint32_t bit) {

}

时钟周期计数器
  1. //**************************************************************************************************
  2. /**
  3. \defgroup DAP_Config_Timestamp_gr CMSIS-DAP Timestamp
  4. \ingroup DAP_ConfigIO_gr
  5. @{
  6. Access function for Test Domain Timer.

  7. The value of the Test Domain Timer in the Debug Unit is returned by the function \ref TIMESTAMP_GET. By
  8. default, the DWT timer is used.  The frequency of this timer is configured with \ref TIMESTAMP_CLOCK.

  9. */

  10. /** Get timestamp of Test Domain Timer.
  11. \return Current timestamp value.
  12. */
  13. __STATIC_INLINE uint32_t TIMESTAMP_GET (void) {
  14.   return (DWT->CYCCNT);
  15. }
复制代码


LED状态控制

  1. //**************************************************************************************************
  2. /**
  3. \defgroup DAP_Config_LEDs_gr CMSIS-DAP Hardware Status LEDs
  4. \ingroup DAP_ConfigIO_gr
  5. @{

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

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

  11. /** Debug Unit: Set status of Connected LED.
  12. \param bit status of the Connect LED.
  13.            - 1: Connect LED ON: debugger is connected to CMSIS-DAP Debug Unit.
  14.            - 0: Connect LED OFF: debugger is not connected to CMSIS-DAP Debug Unit.
  15. */
  16. __STATIC_INLINE void LED_CONNECTED_OUT (uint32_t bit) {
  17.   LPC_GPIO_PORT->B[32*LED_CONNECTED_PORT + LED_CONNECTED_BIT] = bit;
  18. }

  19. /** Debug Unit: Set status Target Running LED.
  20. \param bit status of the Target Running LED.
  21.            - 1: Target Running LED ON: program execution in target started.
  22.            - 0: Target Running LED OFF: program execution in target stopped.
  23. */
  24. __STATIC_INLINE void LED_RUNNING_OUT (uint32_t bit) {
  25.   ;             // Not available
  26. }
复制代码



初始化函数

  1. //**************************************************************************************************
  2. /**
  3. \defgroup DAP_Config_Initialization_gr CMSIS-DAP Initialization
  4. \ingroup DAP_ConfigIO_gr
  5. @{

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

  8. /** Setup of the Debug Unit I/O pins and LEDs (called when Debug Unit is initialized).
  9. This function performs the initialization of the CMSIS-DAP Hardware I/O Pins and the
  10. Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled and set:
  11. - I/O clock system enabled.
  12. - all I/O pins: input buffer enabled, output pins are set to HighZ mode.
  13. - for nTRST, nRESET a weak pull-up (if available) is enabled.
  14. - LED output pins are enabled and LEDs are turned off.
  15. */
  16. __STATIC_INLINE void DAP_SETUP (void) {

  17.   /* Enable clock and init GPIO outputs */

  18.   /* Configure I/O pins: function number, input buffer enabled,  */
  19.   /*                     no pull-up/down except nRESET (pull-up) */


  20.   /* Configure: SWCLK/TCK, SWDIO/TMS, SWDIO_OE, TDI as outputs (high level)   */
  21.   /*            TDO as input                                                  */
  22.   /*            nRESET as input with output latch set to low level            */
  23.   /*            nRESET_OE as output (low level)                               */

  24.   /* Configure: LED as output (turned off) */

  25.   /* Configure Peripheral Interrupt Priorities */

  26. }

  27. /** Reset Target Device with custom specific I/O pin or command sequence.
  28. This function allows the optional implementation of a device specific reset sequence.
  29. It is called when the command \ref DAP_ResetTarget and is for example required
  30. when a device needs a time-critical unlock sequence that enables the debug port.
  31. \return 0 = no device specific reset sequence is implemented.\n
  32.         1 = a device specific reset sequence is implemented.
  33. */
  34. __STATIC_INLINE uint8_t RESET_TARGET (void) {
  35.   return (0U);             // change to '1' when a device reset sequence is implemented
  36. }
复制代码










回复

使用道具 举报

2

主题

22

回帖

28

积分

新手上路

积分
28
发表于 2024-5-7 14:46:15 | 显示全部楼层
源码开源吗?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107217
QQ
 楼主| 发表于 2024-5-7 14:48:07 | 显示全部楼层

开源的,CMSIS软件包里面本身就带了一个例子的。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-21 15:42 , Processed in 0.166237 second(s), 32 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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