Skip to content

Commit

Permalink
Remove superfluous JTAG disable code (qmk#6445)
Browse files Browse the repository at this point in the history
* Remove superfluous JTAG disable code

* 32A has differently named register

* Accidentally some operators

* 32A also has different JTAG pins

* Wrap disable_jtag() in an ifndef

* Document this new define

* Rename the define, it conflicts with a LUFA thing

Also, move the ifndef wrapping to the call in keyboard_setup()
  • Loading branch information
fauxpark authored and drashna committed Aug 21, 2019
1 parent 977c316 commit f2c179d
Show file tree
Hide file tree
Showing 19 changed files with 15 additions and 94 deletions.
17 changes: 5 additions & 12 deletions docs/faq_debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,15 @@ Pressing any key during sleep should wake host.

Arduino Leonardo and micro have **ATMega32U4** and can be used for TMK, though Arduino bootloader may be a problem.

## Enabling JTAG

## Using PF4-7 Pins of USB AVR?
You need to set JTD bit of MCUCR yourself to use PF4-7 as GPIO. Those pins are configured to serve JTAG function by default. MCUs like ATMega*U* or AT90USB* are affected with this.
By default, the JTAG debugging interface is disabled as soon as the keyboard starts up. JTAG-capable MCUs come from the factory with the `JTAGEN` fuse set, and it takes over certain pins of the MCU that the board may be using for the switch matrix, LEDs, etc.

If you are using Teensy this isn't needed. Teensy is shipped with JTAGEN fuse bit unprogrammed to disable the function.
If you would like to keep JTAG enabled, just add the following to your `config.h`:

See this code.
```c
#define NO_JTAG_DISABLE
```
// JTAG disable for PORT F. write JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);
```
https://github.com/tmk/tmk_keyboard/blob/master/keyboard/hbkb/matrix.c#L67

And read **26.5.1 MCU Control Register – MCUCR** of ATMega32U4 datasheet.


## Adding LED Indicators of Lock Keys
You need your own LED indicators for CapsLock, ScrollLock and NumLock? See this post.
Expand Down
17 changes: 0 additions & 17 deletions docs/zh-cn/faq_debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,6 @@ EXTRAKEY_ENABLE = yes # 音频控制和系统控制

Arduino Leonardo和micro使用**ATMega32U4**,该芯片TMK可用,但Arduino的bootloader会导致问题。


## 在USB AVR使用PF4-7针脚?
你要置位MCUCR寄存器JTD位来将PF4-7设置为GPIO。这些针脚默认是JTAG功能。 像ATMega*U* or AT90USB*这样的MCU会受影响。

如果是用Teensy的话就不需要了。Tennsy自带JTAGEN位未编程来失能该功能。
<!--翻译问题:上句可能有错,原文为:Teensy is shipped with JTAGEN fuse bit unprogrammed to disable the function. -->
代码如下。
```
// F接口JTAG失能。在四个周期内写入两次JTD位。
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);
```
https://github.com/tmk/tmk_keyboard/blob/master/keyboard/hbkb/matrix.c#L67

阅读ATMega32U4的datasheet中的**26.5.1 MCU Control Register – MCUCR**


## 为锁定键添加指示灯
你要自制CapsLock, ScrollLock 和 NumLock指示灯?见下文。

Expand Down
3 changes: 0 additions & 3 deletions keyboards/amj96/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ void matrix_init(void)
#ifdef UART_RGB_ENABLE
uart_rgb_init();
#endif
// disable JTAG
MCUCR = _BV(JTD);
MCUCR = _BV(JTD);

// 85 REST
DDRD |= _BV(PD7);
Expand Down
4 changes: 0 additions & 4 deletions keyboards/clueboard/17/17.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ void matrix_init_kb(void) {
// put your keyboard start-up code here
// runs once when the firmware starts up
matrix_init_user();

// JTAG disable for PORT F. write JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);
};

void led_set_kb(uint8_t usb_led) {
Expand Down
4 changes: 0 additions & 4 deletions keyboards/clueboard/66/rev2/rev2.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ void matrix_init_kb(void) {
// runs once when the firmware starts up
matrix_init_user();
led_init_ports();

// JTAG disable for PORT F. write JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);
}


Expand Down
4 changes: 0 additions & 4 deletions keyboards/clueboard/66_hotswap/prototype/prototype.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ void matrix_init_kb(void) {
// runs once when the firmware starts up
matrix_init_user();
led_init_ports();

// JTAG disable for PORT F. write JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);
}


Expand Down
4 changes: 0 additions & 4 deletions keyboards/ergodone/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ uint8_t matrix_cols(void)

void matrix_init(void)
{
// disable JTAG
MCUCR = (1<<JTD);
MCUCR = (1<<JTD);

unselect_rows();
init_cols();

Expand Down
7 changes: 0 additions & 7 deletions keyboards/handwired/promethium/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ uint8_t matrix_cols(void) {
}

void matrix_init(void) {

// To use PORTF disable JTAG with writing JTD bit twice within four cycles.
#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__))
MCUCR |= _BV(JTD);
MCUCR |= _BV(JTD);
#endif

// initialize row and col
unselect_rows();
init_cols();
Expand Down
4 changes: 0 additions & 4 deletions keyboards/hhkb/rn42/rn42.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ host_driver_t rn42_driver = {

void rn42_init(void)
{
// JTAG disable for PORT F. write JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);

// PF7: BT connection control(high: connect, low: disconnect)
rn42_autoconnect();

Expand Down
4 changes: 0 additions & 4 deletions keyboards/hid_liber/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ uint8_t matrix_cols(void)

void matrix_init(void)
{
// To use PORTF disable JTAG with writing JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);

// initialize row and col
setup_io_pins();
setup_leds();
Expand Down
4 changes: 0 additions & 4 deletions keyboards/hotdox/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ uint8_t matrix_cols(void)

void matrix_init(void)
{
// disable JTAG
MCUCR = (1<<JTD);
MCUCR = (1<<JTD);

unselect_rows();
init_cols();

Expand Down
7 changes: 1 addition & 6 deletions keyboards/launchpad/rev1/rev1.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#include "launchpad.h"

void matrix_init_kb(void) {

// JTAG disable for PORT F. write JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);

// Undo init of RX LED, we use that port currently
//DDRB &= ~(1<<0);

matrix_init_user();

};
};
1 change: 0 additions & 1 deletion keyboards/lets_split/sockets/sockets.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#define DISABLE_JTAG // The keyboard uses PF4 and PF7, which are used by JTAG.

#include "lets_split.h"

Expand Down
2 changes: 0 additions & 2 deletions keyboards/miniaxe/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define EE_HANDS
#define I2C_MASTER_LEFT
//#define I2C_MASTER_RIGHT

#define DISABLE_JTAG
7 changes: 0 additions & 7 deletions keyboards/sx60/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ uint8_t matrix_cols(void) {
}

void matrix_init(void) {

/* To use PORTF disable JTAG with writing JTD bit twice within four cycles. */
#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__))
MCUCR |= _BV(JTD);
MCUCR |= _BV(JTD);
#endif

mcp23018_status = true;

/* initialize row and col */
Expand Down
6 changes: 0 additions & 6 deletions keyboards/vitamins_included/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ bool has_usb(void) {

void matrix_init(void)
{
#ifdef DISABLE_JTAG
// JTAG disable for PORT F. write JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);
#endif

// initialize row and col
#if (DIODE_DIRECTION == COL2ROW)
unselect_rows();
Expand Down
1 change: 0 additions & 1 deletion keyboards/vitamins_included/rev1/rev1.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#ifndef REV1_H
#define REV1_H
#define DISABLE_JTAG // The keyboard uses PF4, PF5 and PF7, which are used by JTAG.
#define EE_HANDS // This isn't optional for the vitamins included

#include QMK_KEYBOARD_H
Expand Down
11 changes: 9 additions & 2 deletions tmk_core/common/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata)
#endif

void disable_jtag(void) {
// To use PORTF disable JTAG with writing JTD bit twice within four cycles.
#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__))
// To use PF4-7 (PC2-5 on ATmega32A), disable JTAG by writing JTD bit twice within four cycles.
#if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || \
defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || \
defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
MCUCR |= _BV(JTD);
MCUCR |= _BV(JTD);
#elif defined(__AVR_ATmega32A__)
MCUCSR |= _BV(JTD);
MCUCSR |= _BV(JTD);
#endif
}

Expand Down Expand Up @@ -184,7 +189,9 @@ void keyboard_post_init_kb(void) {
* FIXME: needs doc
*/
void keyboard_setup(void) {
#ifndef NO_JTAG_DISABLE
disable_jtag();
#endif
matrix_setup();
keyboard_pre_init_kb();
}
Expand Down
2 changes: 0 additions & 2 deletions tmk_core/common/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ static inline bool IS_RELEASED(keyevent_t event) { return (!IS_NOEVENT(event) &&
.time = (timer_read() | 1) \
}

void disable_jtag(void);

/* it runs once at early stage of startup before keyboard_init. */
void keyboard_setup(void);
/* it runs once after initializing host side protocol, debug and MCU peripherals. */
Expand Down

0 comments on commit f2c179d

Please sign in to comment.