Skip to content

Commit

Permalink
Change RST pin to emulate an open drain behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
phdussud committed Nov 7, 2022
1 parent 2d4c959 commit ac7c57c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
33 changes: 30 additions & 3 deletions pio_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ void jtag_task();//to process USB OUT packets while waiting for DMA to finish

#define DMA

#if 0
static bool pins_source = false; //false: PIO, true: GPIO

static void switch_pins_source(const pio_jtag_inst_t *jtag, bool gpio)
{
if (pins_source != gpio)
{
if (gpio)
{
gpio_put(jtag->pin_tdi, gpio_get(jtag->pin_tdi));
gpio_set_function(jtag->pin_tdi, GPIO_FUNC_SIO);
gpio_put(jtag->pin_tck, gpio_get(jtag->pin_tck));
gpio_set_function(jtag->pin_tck, GPIO_FUNC_SIO);
gpio_set_dir_out_masked((1 << jtag->pin_tdi) | (1 << jtag->pin_tck));
}
else
{
gpio_set_function(jtag->pin_tdi, GPIO_FUNC_PIO0);
gpio_set_function(jtag->pin_tck, GPIO_FUNC_PIO0);
}
pins_source = gpio;
}
}
#endif



#ifdef DMA

Expand Down Expand Up @@ -215,13 +241,14 @@ uint8_t __time_critical_func(pio_jtag_write_tms_blocking)(const pio_jtag_inst_t

static void init_pins(uint pin_tck, uint pin_tdi, uint pin_tdo, uint pin_tms, uint pin_rst, uint pin_trst)
{
// emulate open drain with pull up and direction
gpio_pull_up(pin_rst);
gpio_clr_mask((1u << pin_tms) | (1u << pin_rst) | (1u << pin_trst));
gpio_init_mask((1u << pin_tms) | (1u << pin_rst) | (1u << pin_trst));
gpio_set_dir_masked( (1u << pin_tms) | (1u << pin_rst) | (1u << pin_trst), 0xffffffffu);
gpio_set_dir_masked( (1u << pin_tms) | (1u << pin_trst), 0xffffffffu);
gpio_set_dir(pin_rst, false);
}



void init_jtag(pio_jtag_inst_t* jtag, uint freq, uint pin_tck, uint pin_tdi, uint pin_tdo, uint pin_tms, uint pin_rst, uint pin_trst)
{
init_pins(pin_tck, pin_tdi, pin_tdo, pin_tms, pin_rst, pin_trst);
Expand Down
3 changes: 2 additions & 1 deletion pio_jtag.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ static inline void jtag_set_tms(const pio_jtag_inst_t *jtag, bool value)
}
static inline void jtag_set_rst(const pio_jtag_inst_t *jtag, bool value)
{
gpio_put(jtag->pin_rst, value);
/* Change the direction to out to drive pin to 0 or to in to emulate open drain */
gpio_set_dir(jtag->pin_rst, !value);
}
static inline void jtag_set_trst(const pio_jtag_inst_t *jtag, bool value)
{
Expand Down

0 comments on commit ac7c57c

Please sign in to comment.