OpenOCD
ft232r.c File Reference
Include dependency graph for ft232r.c:

Go to the source code of this file.

Macros

#define FT232R_BIT_COUNT   8
 FT232R GPIO bit number to RS232 name. More...
 
#define FT232R_BUF_SIZE_EXTRA   4096
 
#define IN_EP   0x02
 
#define OUT_EP   0x81
 
#define SIO_ERASE_EEPROM   0x92
 
#define SIO_GET_LATENCY_TIMER   10
 
#define SIO_MODEM_CTRL   1 /* Set the modem control register */
 
#define SIO_POLL_MODEM_STATUS   5
 
#define SIO_READ_EEPROM   0x90
 
#define SIO_READ_PINS   12
 
#define SIO_RESET   0 /* Reset the port */
 
#define SIO_SET_BAUD_RATE   3 /* Set baud rate */
 
#define SIO_SET_BITMODE   11
 
#define SIO_SET_DATA   4 /* Set the data characteristics of the port */
 
#define SIO_SET_ERROR_CHAR   7
 
#define SIO_SET_EVENT_CHAR   6
 
#define SIO_SET_FLOW_CTRL   2 /* Set flow control register */
 
#define SIO_SET_LATENCY_TIMER   9
 
#define SIO_WRITE_EEPROM   0x91
 

Functions

 COMMAND_HANDLER (ft232r_handle_jtag_nums_command)
 
 COMMAND_HANDLER (ft232r_handle_restore_serial_command)
 
 COMMAND_HANDLER (ft232r_handle_srst_num_command)
 
 COMMAND_HANDLER (ft232r_handle_tck_num_command)
 
 COMMAND_HANDLER (ft232r_handle_tdi_num_command)
 
 COMMAND_HANDLER (ft232r_handle_tdo_num_command)
 
 COMMAND_HANDLER (ft232r_handle_tms_num_command)
 
 COMMAND_HANDLER (ft232r_handle_trst_num_command)
 
 COMMAND_HANDLER (ft232r_handle_vid_pid_command)
 
static int ft232r_bit_name_to_number (const char *name)
 
static char * ft232r_bit_number_to_name (int bit)
 
static void ft232r_increase_buf_size (size_t new_buf_size)
 
static int ft232r_init (void)
 
static int ft232r_khz (int khz, int *divisor)
 
static int ft232r_quit (void)
 
static void ft232r_reset (int trst, int srst)
 Control /TRST and /SYSRST pins. More...
 
static int ft232r_send_recv (void)
 Perform sync bitbang output/input transaction. More...
 
static int ft232r_speed (int divisor)
 
static int ft232r_speed_div (int divisor, int *khz)
 
static void ft232r_write (int tck, int tms, int tdi)
 Add one TCK/TMS/TDI sample to send buffer. More...
 
static void syncbb_end_state (tap_state_t state)
 
static int syncbb_execute_queue (struct jtag_command *cmd_queue)
 
static int syncbb_execute_tms (struct jtag_command *cmd)
 Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG (or SWD) state machine. More...
 
static void syncbb_path_move (struct pathmove_command *cmd)
 
static void syncbb_runtest (int num_cycles)
 
static void syncbb_scan (bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size)
 
static void syncbb_stableclocks (int num_cycles)
 Function syncbb_stableclocks issues a number of clock cycles while staying in a stable state. More...
 
static void syncbb_state_move (int skip)
 

Variables

static struct libusb_device_handle * adapter
 
struct adapter_driver ft232r_adapter_driver
 
static char * ft232r_bit_name_array [FT232R_BIT_COUNT]
 
static size_t ft232r_buf_size = FT232R_BUF_SIZE_EXTRA
 
static const struct command_registration ft232r_command_handlers []
 
static struct jtag_interface ft232r_interface
 
static uint8_t * ft232r_output
 
static size_t ft232r_output_len
 
static uint16_t ft232r_pid = 0x6001
 
static uint16_t ft232r_restore_bitmode = 0xFFFF
 0xFFFF disables restore by default, after exit serial port will not work. More...
 
static const struct command_registration ft232r_subcommand_handlers []
 
static uint16_t ft232r_vid = 0x0403
 
static int nsysrst_gpio = 6
 
static int ntrst_gpio = 4
 
static int tck_gpio
 
static int tdi_gpio = 1
 
static int tdo_gpio = 2
 
static int tms_gpio = 3
 

Macro Definition Documentation

◆ FT232R_BIT_COUNT

#define FT232R_BIT_COUNT   8

FT232R GPIO bit number to RS232 name.

Definition at line 71 of file ft232r.c.

◆ FT232R_BUF_SIZE_EXTRA

#define FT232R_BUF_SIZE_EXTRA   4096

Definition at line 59 of file ft232r.c.

◆ IN_EP

#define IN_EP   0x02

Definition at line 39 of file ft232r.c.

◆ OUT_EP

#define OUT_EP   0x81

Definition at line 40 of file ft232r.c.

◆ SIO_ERASE_EEPROM

#define SIO_ERASE_EEPROM   0x92

Definition at line 57 of file ft232r.c.

◆ SIO_GET_LATENCY_TIMER

#define SIO_GET_LATENCY_TIMER   10

Definition at line 52 of file ft232r.c.

◆ SIO_MODEM_CTRL

#define SIO_MODEM_CTRL   1 /* Set the modem control register */

Definition at line 44 of file ft232r.c.

◆ SIO_POLL_MODEM_STATUS

#define SIO_POLL_MODEM_STATUS   5

Definition at line 48 of file ft232r.c.

◆ SIO_READ_EEPROM

#define SIO_READ_EEPROM   0x90

Definition at line 55 of file ft232r.c.

◆ SIO_READ_PINS

#define SIO_READ_PINS   12

Definition at line 54 of file ft232r.c.

◆ SIO_RESET

#define SIO_RESET   0 /* Reset the port */

Definition at line 43 of file ft232r.c.

◆ SIO_SET_BAUD_RATE

#define SIO_SET_BAUD_RATE   3 /* Set baud rate */

Definition at line 46 of file ft232r.c.

◆ SIO_SET_BITMODE

#define SIO_SET_BITMODE   11

Definition at line 53 of file ft232r.c.

◆ SIO_SET_DATA

#define SIO_SET_DATA   4 /* Set the data characteristics of the port */

Definition at line 47 of file ft232r.c.

◆ SIO_SET_ERROR_CHAR

#define SIO_SET_ERROR_CHAR   7

Definition at line 50 of file ft232r.c.

◆ SIO_SET_EVENT_CHAR

#define SIO_SET_EVENT_CHAR   6

Definition at line 49 of file ft232r.c.

◆ SIO_SET_FLOW_CTRL

#define SIO_SET_FLOW_CTRL   2 /* Set flow control register */

Definition at line 45 of file ft232r.c.

◆ SIO_SET_LATENCY_TIMER

#define SIO_SET_LATENCY_TIMER   9

Definition at line 51 of file ft232r.c.

◆ SIO_WRITE_EEPROM

#define SIO_WRITE_EEPROM   0x91

Definition at line 56 of file ft232r.c.

Function Documentation

◆ COMMAND_HANDLER() [1/9]

COMMAND_HANDLER ( ft232r_handle_jtag_nums_command  )

◆ COMMAND_HANDLER() [2/9]

COMMAND_HANDLER ( ft232r_handle_restore_serial_command  )

◆ COMMAND_HANDLER() [3/9]

COMMAND_HANDLER ( ft232r_handle_srst_num_command  )

◆ COMMAND_HANDLER() [4/9]

COMMAND_HANDLER ( ft232r_handle_tck_num_command  )

◆ COMMAND_HANDLER() [5/9]

COMMAND_HANDLER ( ft232r_handle_tdi_num_command  )

◆ COMMAND_HANDLER() [6/9]

COMMAND_HANDLER ( ft232r_handle_tdo_num_command  )

◆ COMMAND_HANDLER() [7/9]

COMMAND_HANDLER ( ft232r_handle_tms_num_command  )

◆ COMMAND_HANDLER() [8/9]

COMMAND_HANDLER ( ft232r_handle_trst_num_command  )

◆ COMMAND_HANDLER() [9/9]

COMMAND_HANDLER ( ft232r_handle_vid_pid_command  )

Definition at line 388 of file ft232r.c.

References CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, ERROR_OK, ft232r_pid, ft232r_vid, and LOG_WARNING.

◆ ft232r_bit_name_to_number()

static int ft232r_bit_name_to_number ( const char *  name)
static

Definition at line 374 of file ft232r.c.

References FT232R_BIT_COUNT, ft232r_bit_name_array, and name.

Referenced by COMMAND_HANDLER().

◆ ft232r_bit_number_to_name()

static char* ft232r_bit_number_to_name ( int  bit)
static

Definition at line 367 of file ft232r.c.

References bit(), FT232R_BIT_COUNT, and ft232r_bit_name_array.

Referenced by COMMAND_HANDLER().

◆ ft232r_increase_buf_size()

static void ft232r_increase_buf_size ( size_t  new_buf_size)
static

Definition at line 162 of file ft232r.c.

References ft232r_buf_size, FT232R_BUF_SIZE_EXTRA, and ft232r_output.

Referenced by ft232r_reset(), and ft232r_write().

◆ ft232r_init()

◆ ft232r_khz()

static int ft232r_khz ( int  khz,
int *  divisor 
)
static

Definition at line 347 of file ft232r.c.

References ERROR_FAIL, ERROR_OK, and LOG_DEBUG.

◆ ft232r_quit()

◆ ft232r_reset()

static void ft232r_reset ( int  trst,
int  srst 
)
static

Control /TRST and /SYSRST pins.

Perform immediate bitbang transaction.

Definition at line 202 of file ft232r.c.

References ft232r_buf_size, ft232r_increase_buf_size(), ft232r_output, ft232r_output_len, ft232r_send_recv(), LOG_DEBUG, LOG_ERROR, nsysrst_gpio, and ntrst_gpio.

◆ ft232r_send_recv()

static int ft232r_send_recv ( void  )
static

Perform sync bitbang output/input transaction.

Before call, an array ft232r_output[] should be filled with data to send. Counter ft232r_output_len contains the number of bytes to send. On return, received data is put back to array ft232r_output[].

Definition at line 101 of file ft232r.c.

References adapter, ERROR_JTAG_DEVICE_ERROR, ERROR_OK, ft232r_output, ft232r_output_len, IN_EP, jtag_libusb_bulk_read(), jtag_libusb_bulk_write(), LOG_ERROR, and OUT_EP.

Referenced by ft232r_reset(), and syncbb_scan().

◆ ft232r_speed()

static int ft232r_speed ( int  divisor)
static

◆ ft232r_speed_div()

static int ft232r_speed_div ( int  divisor,
int *  khz 
)
static

Definition at line 335 of file ft232r.c.

References ERROR_OK.

◆ ft232r_write()

static void ft232r_write ( int  tck,
int  tms,
int  tdi 
)
static

◆ syncbb_end_state()

static void syncbb_end_state ( tap_state_t  state)
static

Definition at line 625 of file ft232r.c.

References LOG_ERROR, state, tap_is_state_stable(), and tap_set_end_state().

Referenced by syncbb_runtest(), and syncbb_scan().

◆ syncbb_execute_queue()

static int syncbb_execute_queue ( struct jtag_command cmd_queue)
static

Definition at line 806 of file ft232r.c.

◆ syncbb_execute_tms()

static int syncbb_execute_tms ( struct jtag_command cmd)
static

Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG (or SWD) state machine.

Definition at line 655 of file ft232r.c.

References bits, cmd, ERROR_OK, ft232r_write(), and LOG_DEBUG_IO.

◆ syncbb_path_move()

static void syncbb_path_move ( struct pathmove_command cmd)
static

◆ syncbb_runtest()

static void syncbb_runtest ( int  num_cycles)
static

◆ syncbb_scan()

static void syncbb_scan ( bool  ir_scan,
enum scan_type  type,
uint8_t *  buffer,
int  scan_size 
)
static

◆ syncbb_stableclocks()

static void syncbb_stableclocks ( int  num_cycles)
static

Function syncbb_stableclocks issues a number of clock cycles while staying in a stable state.

Because the TMS value required to stay in the RESET state is a 1, whereas the TMS value required to stay in any of the other stable states is a 0, this function checks the current stable state to decide on the value of TMS to use.

Definition at line 738 of file ft232r.c.

References ft232r_write(), tap_get_state(), and TAP_RESET.

◆ syncbb_state_move()

static void syncbb_state_move ( int  skip)
static

Variable Documentation

◆ adapter

◆ ft232r_adapter_driver

struct adapter_driver ft232r_adapter_driver
Initial value:
= {
.name = "ft232r",
.transports = jtag_only,
.init = ft232r_init,
.quit = ft232r_quit,
.speed = ft232r_speed,
.khz = ft232r_khz,
.speed_div = ft232r_speed_div,
.jtag_ops = &ft232r_interface,
}
const char *const jtag_only[]
Definition: adapter.c:27
static struct jtag_interface ft232r_interface
Definition: ft232r.c:898
static int ft232r_init(void)
Definition: ft232r.c:245
static int ft232r_khz(int khz, int *divisor)
Definition: ft232r.c:347
static int ft232r_speed_div(int divisor, int *khz)
Definition: ft232r.c:335
static int ft232r_speed(int divisor)
Definition: ft232r.c:229
static const struct command_registration ft232r_command_handlers[]
Definition: ft232r.c:610
static int ft232r_quit(void)
Definition: ft232r.c:311

Definition at line 806 of file ft232r.c.

◆ ft232r_bit_name_array

char* ft232r_bit_name_array[FT232R_BIT_COUNT]
static
Initial value:
= {
"TXD",
"RXD",
"RTS",
"CTS",
"DTR",
"DSR",
"DCD",
"RI"
}

Definition at line 72 of file ft232r.c.

Referenced by ft232r_bit_name_to_number(), and ft232r_bit_number_to_name().

◆ ft232r_buf_size

size_t ft232r_buf_size = FT232R_BUF_SIZE_EXTRA
static

◆ ft232r_command_handlers

const struct command_registration ft232r_command_handlers[]
static
Initial value:
= {
{
.name = "ft232r",
.mode = COMMAND_ANY,
.help = "perform ft232r management",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration ft232r_subcommand_handlers[]
Definition: ft232r.c:543
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:241

Definition at line 529 of file ft232r.c.

◆ ft232r_interface

struct jtag_interface ft232r_interface
static
Initial value:
= {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = syncbb_execute_queue,
}
static int syncbb_execute_queue(struct jtag_command *cmd_queue)
Definition: ft232r.c:806
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:187

Definition at line 806 of file ft232r.c.

◆ ft232r_output

uint8_t* ft232r_output
static

◆ ft232r_output_len

size_t ft232r_output_len
static

Definition at line 66 of file ft232r.c.

Referenced by ft232r_reset(), ft232r_send_recv(), ft232r_write(), and syncbb_scan().

◆ ft232r_pid

uint16_t ft232r_pid = 0x6001
static

Definition at line 62 of file ft232r.c.

Referenced by COMMAND_HANDLER(), and ft232r_init().

◆ ft232r_restore_bitmode

uint16_t ft232r_restore_bitmode = 0xFFFF
static

0xFFFF disables restore by default, after exit serial port will not work.

0x15 sets TXD RTS DTR as outputs, after exit serial port will continue to work.

Definition at line 93 of file ft232r.c.

Referenced by COMMAND_HANDLER(), ft232r_init(), and ft232r_quit().

◆ ft232r_subcommand_handlers

const struct command_registration ft232r_subcommand_handlers[]
static

Definition at line 529 of file ft232r.c.

◆ ft232r_vid

uint16_t ft232r_vid = 0x0403
static

Definition at line 61 of file ft232r.c.

Referenced by COMMAND_HANDLER(), and ft232r_init().

◆ nsysrst_gpio

int nsysrst_gpio = 6
static

Definition at line 88 of file ft232r.c.

Referenced by COMMAND_HANDLER(), ft232r_init(), ft232r_reset(), and ft232r_write().

◆ ntrst_gpio

int ntrst_gpio = 4
static

Definition at line 87 of file ft232r.c.

Referenced by COMMAND_HANDLER(), ft232r_init(), ft232r_reset(), and ft232r_write().

◆ tck_gpio

int tck_gpio
static

Definition at line 83 of file ft232r.c.

Referenced by COMMAND_HANDLER(), ft232r_init(), and ft232r_write().

◆ tdi_gpio

int tdi_gpio = 1
static

Definition at line 84 of file ft232r.c.

Referenced by COMMAND_HANDLER(), ft232r_init(), and ft232r_write().

◆ tdo_gpio

int tdo_gpio = 2
static

Definition at line 85 of file ft232r.c.

Referenced by COMMAND_HANDLER(), and syncbb_scan().

◆ tms_gpio

int tms_gpio = 3
static

Definition at line 86 of file ft232r.c.

Referenced by COMMAND_HANDLER(), ft232r_init(), and ft232r_write().