|
CMSIS-DAP硬件调试端口的标准I/O引脚支持JTAG模式和SWD模式。
JTAG和SWD的IO引脚说明
对于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) {
}
时钟周期计数器
- //**************************************************************************************************
- /**
- \defgroup DAP_Config_Timestamp_gr CMSIS-DAP Timestamp
- \ingroup DAP_ConfigIO_gr
- @{
- Access function for Test Domain Timer.
- The value of the Test Domain Timer in the Debug Unit is returned by the function \ref TIMESTAMP_GET. By
- default, the DWT timer is used. The frequency of this timer is configured with \ref TIMESTAMP_CLOCK.
- */
- /** Get timestamp of Test Domain Timer.
- \return Current timestamp value.
- */
- __STATIC_INLINE uint32_t TIMESTAMP_GET (void) {
- return (DWT->CYCCNT);
- }
复制代码
LED状态控制
- //**************************************************************************************************
- /**
- \defgroup DAP_Config_LEDs_gr CMSIS-DAP Hardware Status LEDs
- \ingroup DAP_ConfigIO_gr
- @{
- CMSIS-DAP Hardware may provide LEDs that indicate the status of the CMSIS-DAP Debug Unit.
- It is recommended to provide the following LEDs for status indication:
- - Connect LED: is active when the DAP hardware is connected to a debugger.
- - Running LED: is active when the debugger has put the target device into running state.
- */
- /** Debug Unit: Set status of Connected LED.
- \param bit status of the Connect LED.
- - 1: Connect LED ON: debugger is connected to CMSIS-DAP Debug Unit.
- - 0: Connect LED OFF: debugger is not connected to CMSIS-DAP Debug Unit.
- */
- __STATIC_INLINE void LED_CONNECTED_OUT (uint32_t bit) {
- LPC_GPIO_PORT->B[32*LED_CONNECTED_PORT + LED_CONNECTED_BIT] = bit;
- }
- /** Debug Unit: Set status Target Running LED.
- \param bit status of the Target Running LED.
- - 1: Target Running LED ON: program execution in target started.
- - 0: Target Running LED OFF: program execution in target stopped.
- */
- __STATIC_INLINE void LED_RUNNING_OUT (uint32_t bit) {
- ; // Not available
- }
复制代码
初始化函数
- //**************************************************************************************************
- /**
- \defgroup DAP_Config_Initialization_gr CMSIS-DAP Initialization
- \ingroup DAP_ConfigIO_gr
- @{
- CMSIS-DAP Hardware I/O and LED Pins are initialized with the function \ref DAP_SETUP.
- */
- /** Setup of the Debug Unit I/O pins and LEDs (called when Debug Unit is initialized).
- This function performs the initialization of the CMSIS-DAP Hardware I/O Pins and the
- Status LEDs. In detail the operation of Hardware I/O and LED pins are enabled and set:
- - I/O clock system enabled.
- - all I/O pins: input buffer enabled, output pins are set to HighZ mode.
- - for nTRST, nRESET a weak pull-up (if available) is enabled.
- - LED output pins are enabled and LEDs are turned off.
- */
- __STATIC_INLINE void DAP_SETUP (void) {
- /* Enable clock and init GPIO outputs */
- /* Configure I/O pins: function number, input buffer enabled, */
- /* no pull-up/down except nRESET (pull-up) */
- /* Configure: SWCLK/TCK, SWDIO/TMS, SWDIO_OE, TDI as outputs (high level) */
- /* TDO as input */
- /* nRESET as input with output latch set to low level */
- /* nRESET_OE as output (low level) */
- /* Configure: LED as output (turned off) */
- /* Configure Peripheral Interrupt Priorities */
- }
- /** Reset Target Device with custom specific I/O pin or command sequence.
- This function allows the optional implementation of a device specific reset sequence.
- It is called when the command \ref DAP_ResetTarget and is for example required
- when a device needs a time-critical unlock sequence that enables the debug port.
- \return 0 = no device specific reset sequence is implemented.\n
- 1 = a device specific reset sequence is implemented.
- */
- __STATIC_INLINE uint8_t RESET_TARGET (void) {
- return (0U); // change to '1' when a device reset sequence is implemented
- }
复制代码
|
|