Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion DAP/Include/DAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,22 @@
#include <stdint.h>
// #include "cmsis_compiler.h"

#ifndef DAP_SWD
#define DAP_SWD 0
#endif

#ifndef DAP_JTAG
#define DAP_JTAG 0
#endif

#ifndef DAP_CJTAG
#define DAP_CJTAG 0
#endif

#if (((DAP_JTAG != 0) || (DAP_CJTAG != 0)) && (DAP_JTAG_DEV_CNT < 1))
#error "DAP_JTAG_DEV_CNT must be at least 1 when JTAG or cJTAG is enabled"
#endif

// DAP Data structure
typedef struct {
uint8_t debug_port; // Debug Port
Expand All @@ -258,7 +274,7 @@ typedef struct {
uint8_t data_phase; // Always generate Data Phase
} swd_conf;
#endif
#if (DAP_JTAG != 0)
#if ((DAP_JTAG != 0) || (DAP_CJTAG != 0))
struct { // JTAG Device Chain
uint8_t count; // Number of devices
uint8_t index; // Device index (device at TDO has index 0)
Expand Down
68 changes: 52 additions & 16 deletions DAP/Source/DAP.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
#error "Maximum Packet Count is 255!"
#endif

#ifndef DAP_CJTAG
#define DAP_CJTAG 0
#endif

// Clock Macros
#define MAX_SWJ_CLOCK(delay_cycles) \
((CPU_CLOCK/2U) / (IO_PORT_WRITE_CYCLES + delay_cycles))
Expand Down Expand Up @@ -558,7 +554,7 @@ static uint32_t DAP_JTAG_Sequence(const uint8_t *request, uint8_t *response) {
uint32_t response_count;
uint32_t count;

#if (DAP_JTAG != 0)
#if ((DAP_JTAG != 0) || (DAP_CJTAG != 0))
*response++ = DAP_OK;
#else
*response++ = DAP_ERROR;
Expand All @@ -579,15 +575,15 @@ static uint32_t DAP_JTAG_Sequence(const uint8_t *request, uint8_t *response) {
JTAG_Sequence(sequence_info, request, response);
}
#endif
#if (DAP_JTAG != 0)
#if (DAP_CJTAG != 0)
if (DAP_Data.debug_port == DAP_PORT_CJTAG) {
CJTAG_Sequence(sequence_info, request, response);
}
#endif

request += count;
request_count += count + 1U;
#if (DAP_JTAG != 0)
#if ((DAP_JTAG != 0) || (DAP_CJTAG != 0))
if ((sequence_info & JTAG_SEQUENCE_TDO) != 0U) {
response += count;
response_count += count;
Expand All @@ -606,12 +602,16 @@ static uint32_t DAP_JTAG_Sequence(const uint8_t *request, uint8_t *response) {
// number of bytes in request (upper 16 bits)
static uint32_t DAP_JTAG_Configure(const uint8_t *request, uint8_t *response) {
uint32_t count;
#if (DAP_JTAG != 0)
#if ((DAP_JTAG != 0) || (DAP_CJTAG != 0))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
uint32_t length;
uint32_t bits;
uint32_t n;

count = *request++;
if (count > DAP_JTAG_DEV_CNT) {
*response = DAP_ERROR;
return (((count + 1U) << 16) | 1U);
}
DAP_Data.jtag_dev.count = (uint8_t)count;

bits = 0U;
Expand Down Expand Up @@ -642,11 +642,20 @@ static uint32_t DAP_JTAG_Configure(const uint8_t *request, uint8_t *response) {
// return: number of bytes in response (lower 16 bits)
// number of bytes in request (upper 16 bits)
static uint32_t DAP_JTAG_IDCode(const uint8_t *request, uint8_t *response) {
#if (DAP_JTAG != 0)
#if ((DAP_JTAG != 0) || (DAP_CJTAG != 0))
uint32_t data;

if ((DAP_Data.debug_port != DAP_PORT_JTAG) && (DAP_Data.debug_port != DAP_PORT_CJTAG)) {
goto id_error;
switch (DAP_Data.debug_port) {
#if (DAP_JTAG != 0)
case DAP_PORT_JTAG:
break;
#endif
#if (DAP_CJTAG != 0)
case DAP_PORT_CJTAG:
break;
#endif
default:
goto id_error;
}

// Device index (JTAP TAP)
Expand All @@ -664,7 +673,7 @@ static uint32_t DAP_JTAG_IDCode(const uint8_t *request, uint8_t *response) {
data = JTAG_ReadIDCode();
}
#endif
#if (DAP_JTAG != 0)
#if (DAP_CJTAG != 0)
if (DAP_Data.debug_port == DAP_PORT_CJTAG) {
// Select CJTAG chain
CJTAG_IR(JTAG_IDCODE);
Expand Down Expand Up @@ -1212,7 +1221,16 @@ static uint32_t DAP_JTAG_Transfer(const uint8_t *request, uint8_t *response) {
// Select JTAG chain
if (ir != JTAG_DPACC) {
ir = JTAG_DPACC;
JTAG_IR(ir);
#if (DAP_JTAG != 0)
if (DAP_Data.debug_port == DAP_PORT_JTAG) {
JTAG_IR(ir);
}
#endif
#if (DAP_CJTAG != 0)
if (DAP_Data.debug_port == DAP_PORT_CJTAG) {
CJTAG_IR(ir);
}
#endif
}
// Read previous data
retry = DAP_Data.transfer.retry_count;
Expand Down Expand Up @@ -1252,7 +1270,16 @@ static uint32_t DAP_JTAG_Transfer(const uint8_t *request, uint8_t *response) {
// Select JTAG chain
if (ir != request_ir) {
ir = request_ir;
JTAG_IR(ir);
#if (DAP_JTAG != 0)
if (DAP_Data.debug_port == DAP_PORT_JTAG) {
JTAG_IR(ir);
}
#endif
#if (DAP_CJTAG != 0)
if (DAP_Data.debug_port == DAP_PORT_CJTAG) {
CJTAG_IR(ir);
}
#endif
}
// Write DP/AP register
retry = DAP_Data.transfer.retry_count;
Expand Down Expand Up @@ -1308,7 +1335,16 @@ static uint32_t DAP_JTAG_Transfer(const uint8_t *request, uint8_t *response) {
// Select JTAG chain
if (ir != JTAG_DPACC) {
ir = JTAG_DPACC;
JTAG_IR(ir);
#if (DAP_JTAG != 0)
if (DAP_Data.debug_port == DAP_PORT_JTAG) {
JTAG_IR(ir);
}
#endif
#if (DAP_CJTAG != 0)
if (DAP_Data.debug_port == DAP_PORT_CJTAG) {
CJTAG_IR(ir);
}
#endif
}
if (post_read) {
// Read previous data
Expand Down Expand Up @@ -2039,7 +2075,7 @@ void DAP_Setup(void) {
DAP_Data.swd_conf.turnaround = 1U;
DAP_Data.swd_conf.data_phase = 0U;
#endif
#if (DAP_JTAG != 0)
#if ((DAP_JTAG != 0) || (DAP_CJTAG != 0))
DAP_Data.jtag_dev.count = 0U;
#endif

Expand Down
3 changes: 3 additions & 0 deletions projects/HSLink-Pro/src/DAP_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ This information includes:
/// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
#define DAP_JTAG 1 ///< JTAG Mode: 1 = available, 0 = not available.

// TODO: don't support cJTAG at this time
#define DAP_CJTAG 0

/// Configure maximum number of JTAG devices on the scan chain connected to the Debug Access Port.
/// This setting impacts the RAM requirements of the Debug Unit. Valid range is 1 .. 255.
#define DAP_JTAG_DEV_CNT 8U ///< Maximum number of JTAG devices on scan chain.
Expand Down
Loading