How to disable jtag with c

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

I tried these lines but none works

MCUCSR = 0x80;
MCUCSR |= (1<<7);

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

The datasheet tells you that you have to write to the JTD bit *twice* within four clock cycles as a safety for the disabling to come into effect:

		register volatile uint8_t MD asm("r24") = (MCUCR | (1 << JTD)); // Forces compiler to use IN, OR plus two OUTs rather than two lots of IN/AND/OUTs
		MCUCR = MD;                              // Turn on JTAG via code
		MCUCR = MD;

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

Hammer111,

Not sure why you made the second one an OR with existing contents. That may require a read-modify-write which violates the 4 cycle rule. Just:

MCUCSR = 0x80; 
MCUCSR = 0x80;

should be sufficient but ONLY if you have optimisation turned on. It will not work with -O0 (just one of the many reasons not to use -O0!). Rather sadly AVR Studio defaults GCC projects to -O0.

Cliff

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

Optimization for chip? How can I turn it on, I looked datasheet and searched for optimisation but no results found :(

Do I have to set some register(which one) for optimisation)?

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

I assume your post in the GCC forum means you are programmingin avr-gcc? If so then if using Studio go to "configuration options" on the "project" menu and set it there. If using an Mfile generated Makefile it should already contain "OPT = s" but you might want to just verify that.

Cliff

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

yeah I do program avrgcc and I make hex file and upload it by ponyprog

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

Yes but what do you use for a Makefile system (in other words what invokes the compiler?)

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

Build and ReBuild all generates me a hex file

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

So you are using STUDIO to build?!? In that case the optimisation setting is almost definitely wrong (it'll be set to -O0) and therefore you must follow my advice above to use Project/Config options and change it to -Os

Cliff

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

Hammer111 wrote:
Optimization for chip? How can I turn it on, I looked datasheet and searched for optimisation but no results found :(

Do I have to set some register(which one) for optimisation)?


Just so we're clear, "optimization" in this sense means that we're instructing the compiler to change the way it generates its code; it has nothing to do with changing the way in which the AVR's hardware interprets that code.

With optimization turned on, the compiler will typically generate MUCH smaller, faster code than is possible without optimization turned on.

For example, in this case, with optimization turned off, the compiler will never take advantage of the smaller, faster I/O register manipulation instructions. It will always access all I/O registers through their data memory-mapped equivalent locations. So it's not likely to be able to satisfy the 4 clock cycle timing limitation of programming the JTD bit.

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

It works than you clawson, you are the man :)

Thank you lfmorrison for explanation it's more clear now what it is :) :)

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

If you haven't changed the optimization before, that suggests you've left all the project settings to their defaults. I suggest you read my tutorial here for other setup hints for the best configuration.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

Got it working.

Thanks

Thanks

Regards

DJ