using JTAG pins

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there any reason I cannot disable JTAG after I use it to flash my program, and then use those JTAG pins as gpio pins?  Obviously I cant debug any part of the program with JTAG that uses those pins as gpio.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That works with the XMEGA. Don't know about others.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Isn't that what the JTD bit does in the MCUCSR reg?

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm sure you can - but would strongly recommend that you don't!

 

JTAG is far too valuable to disable!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

use those JTAG pins as gpio pins?

I usually use those pins for low priority things like LEDs or switches that I don't need during debug, however the JTAG pins are always available to do their job.

 

 

In your code you disable JTAG if not in debug mode, make sure that the reset pin is available on the JTAG connector so that it can take control of the chip when required.

 

I usually have a project definition file that has

 

//Project definitions

#define	debug 0					//Set just one, true=1 or false=0
//#define	debug 1

In main

 

int	main(void)
{

#if debug==0
	MCUCR = (1<<JTD); 							//Disable JTAG in run mode
	MCUCR = (1<<JTD);
#endif

and maybe as a reminder of the mode you are in

 


#if debug==1
	puts_P( PSTR( "\nWARNING Debug mode code!\r" ) );
#endif

 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Tue. Jul 7, 2020 - 11:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OH, OK John.  That's nice and elegant.  Thanks.  Why do you do the   MCUCR = (1<<JTD);  twice?  Is there some timing issue, or is it just so you are sure to see it?

 

I was just going to disable the JTAG fuse in AS7 when I wanted to use those pins after the code was all debugged, but if the JTAG fuse is disabled can I use my ICE and JTAG to re-enable it in AS7?  Seems like I wouldn't be able to.  Like once I disable the JTAG fuse I am forever forbidden to use JTAG using my ICE and the JTAG connector.  I guess I could go try.  I have a mega1284 with both ISP and JTAG headers in place so I wouldn't JTAG brick it.  It's like the guy trying to recycle power on his router when it hangs using WiFi.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why do you do the   MCUCR = (1<<JTD);  twice?  Is there some timing issue,

It's how it must be done according to the datasheet. MAKE SURE that you have optimisation on or the timing (within 4 cycles) will be out and it won't work.

 

You don't need to touch the JTAG fuse, it can be disabled in software but it's only a temporary disable. Once the chip is reset it will be enabled until disabled again by software.

 

That's the reason you must have the reset line connected to the JTAG header which is not really required for debugging.

 

Also make sure that the load on the JTAG pins is at least 1K or it may load down the JTAG and cause problems.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I see.  I will have to play around with it some.

 

I noticed the 1k isolation resistors.  I have always used 512 Ohms for the ISP lines.

 

js wrote:
It's how it must be done according to the datasheet. MAKE SURE that you have optimisation on or the timing (within 4 cycles) will be out and it won't work.

I usually use Optimize for Size.  Will that be too slow?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or if I am debugging I choose the newer AS7 optimization that is supposed to give an "enhanced debugging experience", and seems to be the default when choosing to debug.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have always used 512 Ohms for the ISP lines.  

It depends on the programmer, the old ones had lots of drive (just like us), newer ones not that much.

I usually use Optimize for Size. 

It's OK, some people in the past used the compiler without optimisation and the timing goes out the window. (...or the Mac or the Linux....)

 

I think the default is -g lately.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks John!  Actually, the default optimization for a debug build is O1.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I sent my response before I saw your last reply.  I think it they crossed in the either.  It takes a long time for signals to get from OZ to SF.  When I look at the compiler optimization and change the Solution Configuration from Release to Debug the compiler optimization changes from -Os to -O1.  When I actually do debug I usually choose the -Og for an "optimized debugging experience", whatever that means.

 

I got the 512 Ohm number from App Note AVR042:

 

I usually run at 5 V, so I figured 510 Ohm was consistent with Note 1.  However, it's true that App Note is 4 years old.

 

That document also says in the JTAG section:

I used to use 4.7k protection resistors, so I am inclined to go with your 1k advice rather than the 510 Ohm I would typically use.

 

Your schematic shows both input and output use of the JTAG pins, so you must define C2 - C5 somewhere as input or output.  Do you have do that with a #if debug==0, or does JTAG just ignore the pin definitions when you debug and take over the pins for it's own use.  I know some of the other pin definitions treated that way.

 

js wrote:
It depends on the programmer, the old ones had lots of drive (just like us), newer ones not that much.

I'm wondering if you have that backwards? sad

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0



However, it's true that App Note is 4 years old.

I can't remember the  note that mentioned 1K but it was pretty common MORE than 4 years ago. Maybe it was from the AS4 help files.

 

EDIT: It is from the JTAGICE mkII JTAG help (both AS4 and AS7)

 

I'm wondering if you have that backwards?

Older AVRs could pump out a lot more current than newer chips. The old AVR ISP Mk1 would work where the newer AVR ISP Mk2 would not work.

 

One of my clients never wanted the cap on the 100n reset lines because they had lots of problems programming the boards. So we compromised, I designed the PCB with the cap and they would leave them off in production.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Wed. Jul 8, 2020 - 10:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, thanks John!  1k it is.  You are the best.

 

js wrote:
Older AVRs could pump out a lot more current than newer chips. The old AVR ISP Mk1 would work where the newer AVR ISP Mk2 would not work.

I have a couple of Chinese AVRISP mkII's and sometimes they work and sometimes the ICE works.  Lately I have been using a lot of mega1284's and just using JTAG, although I have one board with both.  Soldering those .050" header pins up is a lot tougher than the ISP 0.10" headers, although I got a converter board from 0.050 to 0.10 on eBay, so I might start using the bigger headers even though they take up more space.  I can always use a bigger perfboard if things are cramped, but my circuits are rarely size limited.  I'm not sophisticated enough to do anything really complicated.   So far I have had enough pins and haven't had to use the JTAG pins for anything other than JTAG, so all of this was theoretical.  But thanks for your input.  It is greatly appreciated.

 

js wrote:
I'm wondering if you have that backwards?

js wrote:
the old ones had lots of drive (just like us), newer ones not that much.

I'm not so sure I have more drive the older I get.  I seem to be getting lazier, but it's true the younger people in the US dont want to study science.  They just want to get rich quick with the minimum of work doing business.  Or maybe I am just an old foggy.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MarkThomas wrote:
but it's true the younger people in the US dont want to study science.

Well my youngest with the Phd may disagree with you there, but I understand the intent....

 

Jim

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
Well my youngest with the Phd may disagree with you there, but I understand the intent....

 

Hey Jim,

That makes my day to hear of an American going into the sciences.  Most of the engineering students these days are from other countries, and we know how that is going...  Congratulations to your son.  Getting a PhD takes dedication and guts, but I sometimes wonder if it is worth the pain and suffering and social isolation that accompanies it.  Good for him!  We need more like him.

mark