diff --git a/firmware/common/cpld_jtag.c b/firmware/common/cpld_jtag.c index 3e34f0b9..0948858c 100644 --- a/firmware/common/cpld_jtag.c +++ b/firmware/common/cpld_jtag.c @@ -29,47 +29,6 @@ static refill_buffer_cb refill_buffer; static uint32_t xsvf_buffer_len, xsvf_pos; static unsigned char* xsvf_buffer; -void cpld_jtag_setup(jtag_t* const jtag) { - scu_pinmux(SCU_PINMUX_CPLD_TDO, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION4); - scu_pinmux(SCU_PINMUX_CPLD_TCK, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(SCU_PINMUX_CPLD_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(SCU_PINMUX_CPLD_TDI, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); -#ifdef USER_INTERFACE_PORTAPACK - scu_pinmux(SCU_PINMUX_PP_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(SCU_PINMUX_PP_TDO, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); -#endif - - gpio_input(jtag->gpio->gpio_tdo); - gpio_output(jtag->gpio->gpio_tck); - gpio_output(jtag->gpio->gpio_tms); - gpio_output(jtag->gpio->gpio_tdi); -#ifdef USER_INTERFACE_PORTAPACK - gpio_output(jtag->gpio->gpio_pp_tms); - gpio_input(jtag->gpio->gpio_pp_tdo); -#endif -} - -/* set pins as inputs so we don't interfere with an external JTAG device */ -void cpld_jtag_release(jtag_t* const jtag) { - scu_pinmux(SCU_PINMUX_CPLD_TDO, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION4); - scu_pinmux(SCU_PINMUX_CPLD_TCK, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(SCU_PINMUX_CPLD_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(SCU_PINMUX_CPLD_TDI, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); -#ifdef USER_INTERFACE_PORTAPACK - scu_pinmux(SCU_PINMUX_PP_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(SCU_PINMUX_PP_TDO, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); -#endif - - gpio_input(jtag->gpio->gpio_tdo); - gpio_input(jtag->gpio->gpio_tck); - gpio_input(jtag->gpio->gpio_tms); - gpio_input(jtag->gpio->gpio_tdi); -#ifdef USER_INTERFACE_PORTAPACK - gpio_input(jtag->gpio->gpio_pp_tms); - gpio_input(jtag->gpio->gpio_pp_tdo); -#endif -} - /* return 0 if success else return error code see xsvfExecute() */ int cpld_jtag_program( jtag_t* const jtag, @@ -78,12 +37,10 @@ int cpld_jtag_program( refill_buffer_cb refill ) { int error; - cpld_jtag_setup(jtag); xsvf_buffer = buffer; xsvf_buffer_len = buffer_length; refill_buffer = refill; error = xsvfExecute(jtag->gpio); - cpld_jtag_release(jtag); return error; } diff --git a/firmware/common/cpld_jtag.h b/firmware/common/cpld_jtag.h index f8ce0b0e..04292d22 100644 --- a/firmware/common/cpld_jtag.h +++ b/firmware/common/cpld_jtag.h @@ -43,8 +43,6 @@ typedef struct jtag_t { typedef void (*refill_buffer_cb)(void); -void cpld_jtag_release(jtag_t* const jtag); - /* Return 0 if success else return error code see xsvfExecute() see micro.h. * * We expect the buffer to be initially full of data. After the entire diff --git a/firmware/common/hackrf_core.c b/firmware/common/hackrf_core.c index d1842557..74becd01 100644 --- a/firmware/common/hackrf_core.c +++ b/firmware/common/hackrf_core.c @@ -758,21 +758,50 @@ void ssp1_set_mode_max5864(void) spi_bus_start(max5864.bus, &ssp_config_max5864); } +static void jtag_setup(void) { + /* TDI and TMS pull-ups are required in all JTAG-compliant devices. + * Therefore, do not pull up TDI and TMS on HackRF CPLD, which is always present. + * HackRF TMS and TDI are dedicated, just drive instead of pulling up/down. + * TCK is recommended to be held low. + * TDO is undriven except when in Shift-IR or Shift-DR phases, so pull down to keep from floating. + * Nail down other signals before causing any transitions on TCK, to prevent undesired + * state changes. + */ + /* LPC43xx pull-up and pull-down resistors are approximately 53K. */ +#ifdef USER_INTERFACE_PORTAPACK + gpio_set(jtag_gpio_cpld.gpio_pp_tms); +#endif + gpio_set(jtag_gpio_cpld.gpio_tms); + gpio_set(jtag_gpio_cpld.gpio_tdi); + gpio_clear(jtag_gpio_cpld.gpio_tck); + +#ifdef USER_INTERFACE_PORTAPACK + /* Do not drive PortaPack-specific pins, initially, just to be cautious. */ + gpio_input(jtag_gpio_cpld.gpio_pp_tms); + gpio_input(jtag_gpio_cpld.gpio_pp_tdo); +#endif + gpio_output(jtag_gpio_cpld.gpio_tms); + gpio_output(jtag_gpio_cpld.gpio_tdi); + gpio_output(jtag_gpio_cpld.gpio_tck); + gpio_input(jtag_gpio_cpld.gpio_tdo); + + /* Configure CPLD JTAG pins */ +#ifdef USER_INTERFACE_PORTAPACK + scu_pinmux(SCU_PINMUX_PP_TMS, SCU_GPIO_PUP | SCU_CONF_FUNCTION0); + scu_pinmux(SCU_PINMUX_PP_TDO, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); +#endif + scu_pinmux(SCU_PINMUX_CPLD_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); + scu_pinmux(SCU_PINMUX_CPLD_TDI, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); + scu_pinmux(SCU_PINMUX_CPLD_TDO, SCU_GPIO_PDN | SCU_CONF_FUNCTION4); + scu_pinmux(SCU_PINMUX_CPLD_TCK, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); +} + void pin_setup(void) { /* Configure all GPIO as Input (safe state) */ gpio_init(); - /* Release CPLD JTAG pins */ - scu_pinmux(SCU_PINMUX_CPLD_TDO, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION4); - scu_pinmux(SCU_PINMUX_CPLD_TCK, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(SCU_PINMUX_CPLD_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(SCU_PINMUX_CPLD_TDI, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - - gpio_input(&gpio_cpld_tdo); - gpio_input(&gpio_cpld_tck); - gpio_input(&gpio_cpld_tms); - gpio_input(&gpio_cpld_tdi); - + jtag_setup(); + /* Configure SCU Pin Mux as GPIO */ scu_pinmux(SCU_PINMUX_LED1, SCU_GPIO_NOPULL); scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_NOPULL);