Thursday, September 9th 2010, 4:05pm UTC+2

You are not logged in.

  • Login
  • Register

suppgrg

Beginner

Date of registration: Dec 20th 2007

Posts: 4

1

Thursday, December 20th 2007, 11:32am

JTAG DCC channel for terminal I/O (was: wishlist)

Hello

since we are approaching Christmas, I would submit to Segger JLink tech guys this request: can you realize a little simple terminal program (freeware I hope), to monitor the DCC channel for debug I/O with ARM micros?

It would be very helpful to receive (and send) data through the JTAG privileged channel, and near unintrusively respect to ARM (I know ARM needs little code snippets to communicate with DCC).

Thanks

This post has been edited 1 times, last edit by "suppgrg" (Dec 21st 2007, 9:08am)


SEGGER - Rolf

Super Moderator

Date of registration: Nov 21st 2007

Posts: 63

2

Thursday, December 20th 2007, 11:56pm

Hello,

thanks for sharing the idea. We will create a little (free) utility.
We are quite busy right now, so it may take a few weeks.

In the meantime, we'll add a command to J-Link commander (jlink.exe) which does the same thing:
"term" will act as a DCC terminal until the user presses Crtl-C.

It is already working;
we'll make this available in the next Beta version, probably tomorrow.

Happy holidays!

suppgrg

Beginner

Date of registration: Dec 20th 2007

Posts: 4

3

Friday, December 21st 2007, 9:13am

Re: JTAG DCC

Hello Mr. Rolf

very thanks for your prompt interest to my request. I take your promise as a "done thing", since it comes from the company owner!

Happy holidays!

SEGGER - Souhail

Super Moderator

Date of registration: Nov 15th 2007

Posts: 14

4

Friday, December 21st 2007, 8:22pm

Hello,

The upcoming J-Link Commander version includes the terminal function.
Attached a picture which shows this feature. We have included a DCC handler in our TCP/IP stack, showing debug information .

DCC routines for IAR and GNU ARM tool suite will be included in the J-Link software package.

You can download the latest BETA version of the software from the J-Link download page.

You just need to implement your debug I/O routines using the DCC routines.
Of course it is also necessary to periodically call the DCC_Process() function, e.g. in a timer interrupt.

Let us know if you need further help.

Happy holidays...

Souhail

SEGGER - Souhail

Super Moderator

Date of registration: Nov 15th 2007

Posts: 14

5

Friday, December 21st 2007, 8:26pm

For those who cannot wait to add DCC source code their application:

Here the implementation for the GNU ARM tool suite:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*********************************************************************
*          	SEGGER MICROCONTROLLER SYSTEME GmbH               	*
*    	Solutions for real time microcontroller applications    	*
**********************************************************************
*                                                                	*
*       	(c) 2006 -2007   SEGGER Microcontroller Systeme GmbH 	*
*                                                                	*
*  	Internet: www.segger.com   Support: support@segger.com    	*
*                                                                	*
**********************************************************************
----------------------------------------------------------------------
File	: JLINKDCC_Process.c
Purpose : Data handler for ARM J-Link type communication via DCC
Notes   : (1) How to use
          	In order to use the DCC communication to read / write memory, the
            	following needs to be done:
          	* Add this file to the project / make-file
          	* Make sure this data handler is called regularly
          	* Add the JLINKDCC data abort handler (optional)
            	For details, refer to the documentation or see file JLINKDCC_HandleDataAbort.s79.
      	(2) Compatibility
          	The J-Link ARM DCC handler is compatible to the DCC communication
          	protocol used by IAR in the embedded workbench for ARM and allows
          	using the live data window in C-Spy
---------------------------END-OF-HEADER------------------------------
*/

#include "JLINKDCC.h"

extern unsigned long CP14_ReadDCCStat(void);
extern unsigned long CP14_ReadDCC(void);
extern void CP14_WriteDCC(unsigned long Data);

/*********************************************************************
*
*   	Defines, configurable
*
**********************************************************************
*/

#define SUPPORT_READ_U8 	1   // Support byte reads if 1. 0 to disable.
#define SUPPORT_READ_U16	1   // Support half word reads if 1. 0 to disable.
#define SUPPORT_READ_U32	1   // Support word reads if 1. 0 to disable.
#define SUPPORT_WRITE_U8	1   // Support byte writes if 1. 0 to disable.
#define SUPPORT_WRITE_U16   1   // Support half word writes if 1. 0 to disable.
#define SUPPORT_WRITE_U32   1   // Support word writes if 1. 0 to disable.
#define SUPPORT_ABORT   	1   // Support aborts.

/*********************************************************************
*
*   	Defines, non- configurable
*
**********************************************************************
*/

#define U8  unsigned char
#define U16 unsigned short
#define U32 unsigned int

#define DCC_OP_READ_U32   0x01000000
#define DCC_OP_READ_U16   0x02000000
#define DCC_OP_READ_U8	0x04000000
#define DCC_OP_GET_CAPS   0x08000000
#define DCC_OP_WRITE_U32  0x10000000
#define DCC_OP_WRITE_U16  0x20000000
#define DCC_OP_WRITE_U8   0x40000000
#define DCC_OP_ODD_ADDR   0x80000000
#define DCC_OP_COMMAND	0x00000001

#define DCC_CAP_READ_U32  0x01
#define DCC_CAP_READ_U16  0x02
#define DCC_CAP_READ_U8   0x04
#define DCC_CAP_ABORT 	0x08
#define DCC_CAP_WRITE_U32 0x10
#define DCC_CAP_WRITE_U16 0x20
#define DCC_CAP_WRITE_U8  0x40

#define DCC_SIGNATURE 	0x91CA0000

#define DCC_CONFIG   	((DCC_CAP_READ_U8   * SUPPORT_READ_U8)	\
                    	| (DCC_CAP_READ_U16  * SUPPORT_READ_U16)   \
                    	| (DCC_CAP_READ_U32  * SUPPORT_READ_U32)   \
                    	| (DCC_CAP_WRITE_U8  * SUPPORT_WRITE_U8)   \
                    	| (DCC_CAP_WRITE_U16 * SUPPORT_WRITE_U16)  \
                    	| (DCC_CAP_WRITE_U32 * SUPPORT_WRITE_U32)  \
                    	| (DCC_CAP_ABORT 	* SUPPORT_ABORT))

#define SUPPORT_WRITE   (SUPPORT_WRITE_U8 | SUPPORT_WRITE_U16 | SUPPORT_WRITE_U32)

/*********************************************************************
*
*   	Global data
*
**********************************************************************
*/

U8 JLINKDCC_IsInHandler;
U8 JLINKDCC_AbortOccurred;

/*********************************************************************
*
*   	Static data
*
**********************************************************************
*/

static U16 _NumReadItems;
static U32 _Command;
static U32 _Addr;

static char _acBuffer[256];
static int  _RdPos;
static int  _WrPos;

#if (SUPPORT_WRITE)
  static U32 _Data;
#endif

/*********************************************************************
*
*   	Public code
*
**********************************************************************
*/
/*********************************************************************
*
*   	DCC_Process
*
*  Function description
*	This function should be called more or less regularily to allow
*	memory reads while the application progam is running.
*	The more often it is called, the higher the memory read speed.
*/
void DCC_Process(void) {
  U32 Data;

  //
  // Avoid problems if this code is called from multiple threads or interrupts
  //
  if (JLINKDCC_IsInHandler) {
	return;
  }
  JLINKDCC_IsInHandler = 1;
  //
  // Perform communication for memory read / write as far as configured
  //
  if (CP14_ReadDCCStat() & 1) {
	Data = CP14_ReadDCC();
	if (Data & DCC_OP_COMMAND) {
  	_Command = Data;
#if (DCC_CONFIG & (DCC_CAP_READ_U8 | DCC_CAP_WRITE_U8))
  	if (_Command & DCC_OP_ODD_ADDR) {
    	_Addr |= 1;
  	}
#endif
  	if (_Command & (DCC_OP_READ_U32 | DCC_OP_READ_U16 | DCC_OP_READ_U8 | DCC_OP_GET_CAPS)) {
    	_NumReadItems = (_Command >> 2) & 0xffff;
  	} else {
#if (DCC_CONFIG & DCC_CAP_WRITE_U32)
    	if (_Command & DCC_OP_WRITE_U32) {
      	_Data |= (_Command << 14) & 0xffff0000;
    	} else
#endif
#if (SUPPORT_WRITE)
    	{
      	_Data = (_Command >> 2) & 0xffff;
    	}
#endif
#if (DCC_CONFIG & DCC_CAP_WRITE_U8)
    	if (_Command & DCC_OP_WRITE_U8) {
      	*(U8*)_Addr = _Data;
      	_Addr += 1;
    	}
#endif
#if (DCC_CONFIG & DCC_CAP_WRITE_U16)
    	if (_Command & DCC_OP_WRITE_U16) {
      	*(U16*)_Addr = _Data;
      	_Addr += 2;
    	}
#endif
#if (DCC_CONFIG & DCC_CAP_WRITE_U32)
    	if (_Command & DCC_OP_WRITE_U32) {
      	*(U32*)_Addr =_Data;
      	_Addr += 4;
    	}
#endif
  	}
  	goto Done;
	}
	_Addr = Data;
  }
  if (_NumReadItems) {
	if ((CP14_ReadDCCStat() & 2) == 0) {
  	Data = (DCC_CONFIG | DCC_SIGNATURE);
#if (DCC_CONFIG & DCC_CAP_ABORT)
  	Data |= (JLINKDCC_AbortOccurred << 8);
  	if (_Command & DCC_OP_GET_CAPS) {
    	JLINKDCC_AbortOccurred = 0;
  	}
#endif
#if (DCC_CONFIG & DCC_CAP_READ_U8)
  	if (_Command & DCC_OP_READ_U8) {
    	Data = *(U8*)_Addr;
    	_Addr += 1;
  	}
#endif
#if (DCC_CONFIG & DCC_CAP_READ_U16)
  	if (_Command & DCC_OP_READ_U16) {
    	Data = *(U16*)_Addr;
    	_Addr += 2;
  	}
#endif
#if (DCC_CONFIG & DCC_CAP_READ_U32)
  	if (_Command & DCC_OP_READ_U32) {
    	Data = *(U32*)_Addr;
    	_Addr += 4;
  	}
#endif
  	CP14_WriteDCC(Data);
  	_NumReadItems--;
	}
  }
Done:
  //
  // Handle terminal out. Up to 3 bytes in one 32-bit unit
  //
  if ((CP14_ReadDCCStat() & 2) == 0) {
	int NumBytes;
	NumBytes = _WrPos - _RdPos;
	if (NumBytes < 0) {
  	NumBytes += sizeof(_acBuffer);
	}
	if (NumBytes) {
  	int i;
  	if (NumBytes > 3) {
    	NumBytes = 3;
  	}
  	Data = 0;
  	for (i = 0; i < NumBytes; i++) {
    	Data |= _acBuffer[_RdPos] << (8*i);
    	_RdPos++;
    	if (_RdPos == sizeof(_acBuffer)) {
      	_RdPos = 0;
    	}
  	}
  	Data |= (NumBytes - 1) << 24;
  	CP14_WriteDCC(Data);
	}
  }
  JLINKDCC_IsInHandler = 0;
}

/*********************************************************************
*
*   	JLINKDCC_SendChar
*
*  Function description
*/
void JLINKDCC_SendChar(char c) {
  int Pos;

  Pos = _WrPos + 1;
  if (Pos == sizeof(_acBuffer)) {
	Pos = 0;
  }
  if (Pos == _RdPos) {
	return;
  }
  _acBuffer[_WrPos] = c;
  _WrPos = Pos;
}

/*********************************************************************
*
*   	JLINKDCC_SendString
*
*  Function description
*/
void JLINKDCC_SendString(const char * s) {
  char c;
  while (1) {
	c = *s++;
	if (c == 0) {
  	break;
	}
	JLINKDCC_SendChar(c);
  }
}
/*************************** end of file ****************************/

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**********************************************************
*      	SEGGER MICROCONTROLLER SYSTEME GmbH
*   Solutions for real time microcontroller applications
***********************************************************
*
* File	: JLINKDCC_Process_ASM.s
* Purpose : Routines for setting and writing co-processor register CP14 
        	(DCC-communication) (GNU ARM tool suite)
--------- END-OF-HEADER ---------------------------------
*/

/*********************************************************************
*
*   	GNU ARM
*
*/
    	.text
    	.global  CP14_ReadDCCStat
    	.global  CP14_ReadDCC
    	.global  CP14_WriteDCC
    	.arm
    	.section .text, "ax" 

/*********************************************************************
*
*   	Public code
*
**********************************************************************
*/

/*********************************************************************
*
*   	CP14_ReadDCCStat
*/
CP14_ReadDCCStat:
  mrc P14,0,R0,C0,C0,0
  bx lr

/*********************************************************************
*
*   	CP14_ReadDCC
*/
CP14_ReadDCC:
  mrc P14,0,R0,C1,C0,0
  bx lr

/*********************************************************************
*
*   	CP14_WriteDCC
*/
CP14_WriteDCC:
  mcr P14,0,R0,C1,C0,0
  bx lr
  
  .end
/**************************** End of file ***************************/


-- Souhail

Gelware

Beginner

Date of registration: Jan 7th 2008

Posts: 1

Location: Trieste

Occupation: Senior Embedded Software Engineer

6

Monday, January 7th 2008, 5:23pm

DCC Terminal Input from Host to Target

Hello,

In my opinion, it seems there is no way to receive data from Host to the Target (using JLINK>term command), but only it is possible to use it as a simple Target to Host console.
When using jlink3.79h_beta after any key-press the 'term' session exit.

My idea was to write a simple terminal with VT100 escape capabilites using DCC,
but in the Jlink-SDK package there is no example on using:


JLINKARM_ReadDcc()
JLINKARM_WriteDcc()

Anyone, does have some knowledge on that?


Thanks!

SEGGER - Rolf

Super Moderator

Date of registration: Nov 21st 2007

Posts: 63

7

Thursday, January 10th 2008, 11:02am

Hello "Gelware",

the J-Link SDK contains the source code of the J-Link commander (Jlink.exe).
Since the current Beta supports the "term" command, it uses the DCC read/write functions
and and be used as sample.

Please contact us (info@segger.com) and we'll send you the latest SDK.

You are right that the J-Link commanders "term" command supports one-way
communication only currently and is not a full terminal, but it would indeed
be quite helpful to have such an application, preferably stand-alone.

Best regards,
Rolf

gerhardf

Beginner

Date of registration: Nov 28th 2007

Posts: 13

8

Tuesday, March 9th 2010, 4:03pm

hello,
i would like to reanimate this thread because i would like to use the dcc feature too.
I would be interested in using the dcc in conjunction with the terminal i/o window of the iar workbench.
sending from the target to the debugger through dcc is working fine by including the jlinkdcc_process.c module and periodically calling the function JLINKDCC_Process() at the target.
but i'm not able to receive characters which are send from the terminal i/o window to the target. _HandleRead() is called peridodically but _ReadDCCStat() returns always 0. so it seems that dcc is only working in one direction.
is this a known problem or already not implemented feature?
many thanks in advance
gerhard

gerhardf

Beginner

Date of registration: Nov 28th 2007

Posts: 13

9

Wednesday, March 24th 2010, 11:08am

hello,
is anybody at segger willing/able to answer my question?
many thanks in advance
gerhard