Skip to content

Commit 89fa7e6

Browse files
committed
jtag/esp32gpio: add gpio blink callback and pin set command
1 parent 2e998c1 commit 89fa7e6

File tree

2 files changed

+53
-23
lines changed

2 files changed

+53
-23
lines changed

src/jtag/drivers/esp32gpio.c

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ static dedic_gpio_bundle_handle_t gpio_in_bundle;
2121
static dedic_gpio_bundle_handle_t gpio_out_bundle;
2222

2323
/* mask values depends on the location in the gpio bundle array */
24+
#define GPIO_TDO_MASK 0x01 /* input */
25+
26+
/* outputs */
2427
#define GPIO_TCK_MASK 0x01
25-
#define GPIO_TDO_MASK 0x01
2628
#define GPIO_TDI_MASK 0x02
2729
#define GPIO_TMS_MASK 0x04
2830
#define GPIO_TRST_MASK 0x08
2931
#define GPIO_SRST_MASK 0x10
32+
#define GPIO_BLINK_MASK 0x20
3033

3134
/* GPIO setup functions */
3235
static inline void gpio_mode_input_set(int g)
@@ -52,6 +55,7 @@ static inline void gpio_clear(int g)
5255
static bb_value_t esp32_gpio_read(void);
5356
static int esp32_gpio_write(int tck, int tms, int tdi);
5457
static int esp32_gpio_reset(int trst, int srst);
58+
static int esp32_gpio_blink(int on);
5559

5660
static int esp32_gpio_init(void);
5761
static int esp32_gpio_quit(void);
@@ -64,24 +68,21 @@ static struct bitbang_interface esp32_gpio_bitbang = {
6468
.blink = NULL
6569
};
6670

67-
/* GPIO numbers for each signal. Negative values are invalid */
68-
static int tck_gpio = -1;
69-
static int tms_gpio = -1;
70-
static int tdi_gpio = -1;
71-
static int tdo_gpio = -1;
72-
static int trst_gpio = -1;
73-
static int srst_gpio = -1;
74-
75-
/* Transition delay coefficients. Tuned for IMX6UL 528MHz. Adjusted
76-
* experimentally for:10kHz, 100Khz, 500KHz. Speeds above 800Khz are impossible
77-
* to reach via memory mapped method (at least for IMX6UL@528MHz).
78-
* Measured mmap raw GPIO toggling speed on IMX6UL@528MHz: 1.3MHz.
79-
*/
71+
/* GPIO default values for each pin */
72+
static int tck_gpio = GPIO_NUM_NC;
73+
static int tms_gpio = GPIO_NUM_NC;
74+
static int tdi_gpio = GPIO_NUM_NC;
75+
static int tdo_gpio = GPIO_NUM_NC;
76+
static int trst_gpio = GPIO_NUM_NC;
77+
static int srst_gpio = GPIO_NUM_NC;
78+
static int blink_gpio = GPIO_NUM_NC;
79+
8080
static unsigned int jtag_delay = 0;
8181

8282
static bb_value_t esp32_gpio_read(void)
8383
{
84-
return dedic_gpio_cpu_ll_read_in() & GPIO_TDO_MASK ? BB_HIGH : BB_LOW;
84+
/* we have only one input and it's mask value is 0x01. So we don't need to check the mask value. */
85+
return dedic_gpio_cpu_ll_read_in();
8586
}
8687

8788
static int esp32_gpio_write(int tck, int tms, int tdi)
@@ -96,13 +97,19 @@ static int esp32_gpio_write(int tck, int tms, int tdi)
9697
return ERROR_OK;
9798
}
9899

100+
static int esp32_gpio_blink(int on)
101+
{
102+
dedic_gpio_cpu_ll_write_mask(GPIO_BLINK_MASK, on ? GPIO_BLINK_MASK : 0);
103+
return ERROR_OK;
104+
}
105+
99106
/* (1) assert or (0) deassert reset lines */
100107
static int esp32_gpio_reset(int trst, int srst)
101108
{
102-
if (trst_gpio != -1)
109+
if (trst_gpio != GPIO_NUM_NC)
103110
dedic_gpio_cpu_ll_write_mask(GPIO_TRST_MASK, trst ? GPIO_TRST_MASK : 0);
104111

105-
if (srst_gpio != -1)
112+
if (srst_gpio != GPIO_NUM_NC)
106113
dedic_gpio_cpu_ll_write_mask(GPIO_SRST_MASK, srst ? GPIO_SRST_MASK : 0);
107114

108115
return ERROR_OK;
@@ -205,6 +212,15 @@ COMMAND_HANDLER(esp32_gpio_handle_jtag_gpionum_trst)
205212
return ERROR_OK;
206213
}
207214

215+
COMMAND_HANDLER(esp32_gpio_handle_jtag_gpionum_blink)
216+
{
217+
if (CMD_ARGC == 1)
218+
COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], blink_gpio);
219+
220+
command_print(CMD, "esp32_gpio GPIO config: blink = %d", blink_gpio);
221+
return ERROR_OK;
222+
}
223+
208224
static const struct command_registration esp32_gpio_command_handlers[] = {
209225
{
210226
.name = "esp32_gpio_jtag_nums",
@@ -255,6 +271,13 @@ static const struct command_registration esp32_gpio_command_handlers[] = {
255271
.help = "gpio number for trst.",
256272
.usage = "[trst]",
257273
},
274+
{
275+
.name = "esp32_gpio_blink_num",
276+
.handler = &esp32_gpio_handle_jtag_gpionum_blink,
277+
.mode = COMMAND_CONFIG,
278+
.help = "gpio number for blink.",
279+
.usage = "[blink]",
280+
},
258281

259282
COMMAND_REGISTRATION_DONE
260283
};
@@ -295,12 +318,11 @@ static bool esp32_gpio_jtag_mode_possible(void)
295318

296319
static int esp32_gpio_init(void)
297320
{
298-
bitbang_interface = &esp32_gpio_bitbang;
299-
300321
LOG_INFO("esp32_gpio GPIO JTAG bitbang driver");
301322

302323
int khz = 5000;
303324
int jtag_speed = 0;
325+
304326
esp32_gpio_khz(khz, &jtag_speed);
305327

306328
/*
@@ -311,7 +333,6 @@ static int esp32_gpio_init(void)
311333
gpio_clear(tdi_gpio);
312334
gpio_clear(tck_gpio);
313335
gpio_set(tms_gpio);
314-
315336
gpio_mode_input_set(tdo_gpio);
316337
gpio_mode_output_set(tdi_gpio);
317338
gpio_mode_output_set(tck_gpio);
@@ -321,19 +342,25 @@ static int esp32_gpio_init(void)
321342
return ERROR_FAIL;
322343
}
323344

324-
int bundle_out_gpios[] = { tck_gpio, tdi_gpio, tms_gpio, 0, 0 };
345+
int bundle_out_gpios[] = { tck_gpio, tdi_gpio, tms_gpio, 0, 0, 0 };
325346
int bundle_in_gpios[] = { tdo_gpio };
326347

327-
if (trst_gpio != -1) {
348+
if (trst_gpio != GPIO_NUM_NC) {
328349
gpio_set(trst_gpio);
329350
gpio_mode_output_set(trst_gpio);
330351
bundle_out_gpios[3] = trst_gpio;
331352
}
332-
if (srst_gpio != -1) {
353+
if (srst_gpio != GPIO_NUM_NC) {
333354
gpio_set(srst_gpio);
334355
gpio_mode_output_set(srst_gpio);
335356
bundle_out_gpios[4] = srst_gpio;
336357
}
358+
if (blink_gpio != GPIO_NUM_NC) {
359+
gpio_clear(blink_gpio);
360+
gpio_mode_output_set(blink_gpio);
361+
bundle_out_gpios[5] = blink_gpio;
362+
esp32_gpio_bitbang.blink = esp32_gpio_blink;
363+
}
337364

338365
dedic_gpio_bundle_config_t out_bundle_config = {
339366
.gpio_array = bundle_out_gpios,
@@ -354,6 +381,8 @@ static int esp32_gpio_init(void)
354381
dedic_gpio_new_bundle(&out_bundle_config, &gpio_out_bundle);
355382
dedic_gpio_new_bundle(&in_bundle_config, &gpio_in_bundle);
356383

384+
bitbang_interface = &esp32_gpio_bitbang;
385+
357386
return ERROR_OK;
358387
}
359388

tcl/interface/esp32_gpio.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
adapter driver esp32_gpio
22
adapter speed 1000
33
esp32_gpio_jtag_nums 13 14 12 11
4+
# esp32_gpio_blink_num 5

0 commit comments

Comments
 (0)