Pin setup: Break out JTAG configuration, rework to consider PortaPack.

This commit is contained in:
Jared Boone
2018-12-27 20:33:33 -08:00
parent bfd3b1b768
commit 816d435dc5
3 changed files with 40 additions and 56 deletions

View File

@ -29,47 +29,6 @@ static refill_buffer_cb refill_buffer;
static uint32_t xsvf_buffer_len, xsvf_pos; static uint32_t xsvf_buffer_len, xsvf_pos;
static unsigned char* xsvf_buffer; 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() */ /* return 0 if success else return error code see xsvfExecute() */
int cpld_jtag_program( int cpld_jtag_program(
jtag_t* const jtag, jtag_t* const jtag,
@ -78,12 +37,10 @@ int cpld_jtag_program(
refill_buffer_cb refill refill_buffer_cb refill
) { ) {
int error; int error;
cpld_jtag_setup(jtag);
xsvf_buffer = buffer; xsvf_buffer = buffer;
xsvf_buffer_len = buffer_length; xsvf_buffer_len = buffer_length;
refill_buffer = refill; refill_buffer = refill;
error = xsvfExecute(jtag->gpio); error = xsvfExecute(jtag->gpio);
cpld_jtag_release(jtag);
return error; return error;
} }

View File

@ -43,8 +43,6 @@ typedef struct jtag_t {
typedef void (*refill_buffer_cb)(void); 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. /* 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 * We expect the buffer to be initially full of data. After the entire

View File

@ -758,21 +758,50 @@ void ssp1_set_mode_max5864(void)
spi_bus_start(max5864.bus, &ssp_config_max5864); 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) { void pin_setup(void) {
/* Configure all GPIO as Input (safe state) */ /* Configure all GPIO as Input (safe state) */
gpio_init(); gpio_init();
/* Release CPLD JTAG pins */ jtag_setup();
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);
/* Configure SCU Pin Mux as GPIO */ /* Configure SCU Pin Mux as GPIO */
scu_pinmux(SCU_PINMUX_LED1, SCU_GPIO_NOPULL); scu_pinmux(SCU_PINMUX_LED1, SCU_GPIO_NOPULL);
scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_NOPULL); scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_NOPULL);