Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute two times the same statement for JTAG_Software_Disable ? #2

Open
BlackBrix opened this issue Mar 5, 2018 · 2 comments
Open

Comments

@BlackBrix
Copy link

is it correct (or "wanted") to execute two times the same statement in
CAN485/Examples/JTAG_Software_Disable/JTAG_Software_Disable.ino ?

MCUCR = (1<<JTD);
MCUCR = (1<<JTD);
@JamieBlakey
Copy link
Collaborator

It is necessary to write the JTD bit twice in order to disable the JTAG port. From the Datasheet:

23.5.1 MCU Control Register – MCUCR
• Bits 7 – JTD: JTAG Interface Disable
When this bit is zero, the JTAG interface is enabled if the JTAGEN Fuse is programmed. If this
bit is one, the JTAG interface is disabled. In order to avoid unintentional disabling or enabling of
the JTAG interface, a timed sequence must be followed when changing this bit: The application
software must write this bit to the desired value twice within four cycles to change its value. Note
that this bit must not be altered when using the On-chip Debug system.

Also see this discussion

Whether this is the correct method is up for debate. A compiler may possibly interpret this differently and optimize out the second write or something (I am no compiler expert, this may or may not be an issue). In all test environments it has compiled correctly and worked. It may be "safer" to rewrite this in assembler to ensure the 4 cycle requirement is always met.

Will leave the issue open for now with the intention to investigate further.

Comments are welcome if anyone can advise on compiler interpretation.

@BlackBrix
Copy link
Author

aah, OK, I see ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants