Skip to content

Commit fe7d723

Browse files
committed
Tune JTAG clock cycle
Current implementation doesn't need delay, because code it self need 1 micro second per TCK cycle. This gives 1 MHz so it is correct for targets with 6 MHz CPU clocks and faster. This patch add special delay routine when TCKWAIT is 0. If TCKWAIT is non zero it is interpreted as delay in microseconds. This way it is easy to set longer TCK cycle if needed.
1 parent 20bd29f commit fe7d723

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Inc/jtag/jtag_low_level.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#include "stm32f4xx_it.h"
55

6-
#define TCKWAIT 10
6+
// if TCKWAIT == 0 than alternate method of delay is used.
7+
// if TCKWAIT > 0 than it represent half of TCK cycle in micro seconds
8+
#define TCKWAIT 0
79
#define SIZEOF_IN_BITS(x) (sizeof(x) * 8)
810

911
// maximum size of transfer in jtag_tdin function

Src/jtag/jtag_low_level.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#include "jtag/jtag_low_level.h"
66

77
uint32_t getUs(void) {
8-
uint32_t usTicks = HAL_RCC_GetSysClockFreq() / 1000000;
8+
static uint32_t usTicks = 0;
9+
if (usTicks == 0) {
10+
usTicks = HAL_RCC_GetSysClockFreq() / 1000000;
11+
}
912
register uint32_t ms, cycle_cnt;
1013
do {
1114
ms = HAL_GetTick();
@@ -23,15 +26,38 @@ void delayUs(uint16_t micros)
2326
}
2427
}
2528

29+
#if TCKWAIT == 0
30+
// current implementation of JTAG low level routines allow us to get ~1MHz if there
31+
// is no additional delay.
32+
static inline void short_delay(){
33+
asm("nop");
34+
asm("nop");
35+
asm("nop");
36+
asm("nop");
37+
asm("nop");
38+
asm("nop");
39+
asm("nop");
40+
asm("nop");
41+
}
42+
#endif
43+
2644
void jtag_tclk_up()
2745
{
46+
#if TCKWAIT == 0
47+
short_delay();
48+
#else
2849
delayUs(TCKWAIT);
50+
#endif
2951
HAL_GPIO_WritePin(JTAG_TCLK_GPIO_Port, JTAG_TCLK_Pin, GPIO_PIN_SET);
3052
}
3153

3254
void jtag_tclk_down()
3355
{
56+
#if TCKWAIT == 0
57+
short_delay();
58+
#else
3459
delayUs(TCKWAIT);
60+
#endif
3561
HAL_GPIO_WritePin(JTAG_TCLK_GPIO_Port, JTAG_TCLK_Pin, GPIO_PIN_RESET);
3662
}
3763

0 commit comments

Comments
 (0)