static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int size) { struct stlink_usb_handle_s *h; assert(handle != NULL); h = (struct stlink_usb_handle_s *)handle; if (jtag_libusb_bulk_write(h->fd, STLINK_TX_EP, (char *)h->cmdbuf, cmdsize, 1000) != cmdsize) { return ERROR_FAIL; } if (h->direction == STLINK_TX_EP && size) { if (jtag_libusb_bulk_write(h->fd, STLINK_TX_EP, (char *)buf, size, 1000) != size) { LOG_DEBUG("bulk write failed"); return ERROR_FAIL; } } else if (h->direction == STLINK_RX_EP && size) { if (jtag_libusb_bulk_read(h->fd, STLINK_RX_EP, (char *)buf, size, 1000) != size) { LOG_DEBUG("bulk read failed"); return ERROR_FAIL; } } return ERROR_OK; }
static int stlink_usb_xfer_v1_get_status(void *handle) { struct stlink_usb_handle_s *h; assert(handle != NULL); h = (struct stlink_usb_handle_s *)handle; /* read status */ memset(h->cmdbuf, 0, STLINK_SG_SIZE); if (jtag_libusb_bulk_read(h->fd, STLINK_RX_EP, (char *)h->cmdbuf, 13, 1000) != 13) return ERROR_FAIL; uint32_t t1; t1 = buf_get_u32(h->cmdbuf, 0, 32); /* check for USBS */ if (t1 != 0x53425355) return ERROR_FAIL; /* * CSW status: * 0 success * 1 command failure * 2 phase error */ if (h->cmdbuf[12] != 0) return ERROR_FAIL; return ERROR_OK; }
static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int size) { struct stlink_usb_handle_s *h = handle; assert(handle != NULL); if (jtag_libusb_bulk_write(h->fd, h->tx_ep, (char *)h->cmdbuf, cmdsize, STLINK_WRITE_TIMEOUT) != cmdsize) { return ERROR_FAIL; } if (h->direction == h->tx_ep && size) { if (jtag_libusb_bulk_write(h->fd, h->tx_ep, (char *)buf, size, STLINK_WRITE_TIMEOUT) != size) { LOG_DEBUG("bulk write failed"); return ERROR_FAIL; } } else if (h->direction == h->rx_ep && size) { if (jtag_libusb_bulk_read(h->fd, h->rx_ep, (char *)buf, size, STLINK_READ_TIMEOUT) != size) { LOG_DEBUG("bulk read failed"); return ERROR_FAIL; } } return ERROR_OK; }
static int ublast2_libusb_read(struct ublast_lowlevel *low, uint8_t *buf, unsigned size, uint32_t *bytes_read) { *bytes_read = jtag_libusb_bulk_read(low->libusb_dev, USBBLASTER_EPIN | \ LIBUSB_ENDPOINT_IN, (char *)buf, size, 100); return ERROR_OK; }
static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size) { struct stlink_usb_handle_s *h = handle; assert(handle != NULL); assert(h->version.stlink >= 2); if (jtag_libusb_bulk_read(h->fd, h->trace_ep, (char *)buf, size, STLINK_READ_TIMEOUT) != size) { LOG_ERROR("bulk trace read failed"); return ERROR_FAIL; } return ERROR_OK; }
static int osbdm_send_and_recv(struct osbdm *osbdm) { /* Send request */ int count = jtag_libusb_bulk_write(osbdm->devh, OSBDM_USB_EP_WRITE, (char *)osbdm->buffer, osbdm->count, OSBDM_USB_TIMEOUT); if (count != osbdm->count) { LOG_ERROR("OSBDM communication error: can't write"); return ERROR_FAIL; } /* Save command code for next checking */ uint8_t cmd_saved = osbdm->buffer[0]; /* Reading answer */ osbdm->count = jtag_libusb_bulk_read(osbdm->devh, OSBDM_USB_EP_READ, (char *)osbdm->buffer, OSBDM_USB_BUFSIZE, OSBDM_USB_TIMEOUT); /* Now perform basic checks for data sent by BDM device */ if (osbdm->count < 0) { LOG_ERROR("OSBDM communication error: can't read"); return ERROR_FAIL; } if (osbdm->count < 2) { LOG_ERROR("OSBDM communication error: reply too small"); return ERROR_FAIL; } if (osbdm->count != osbdm->buffer[1]) { LOG_ERROR("OSBDM communication error: reply size mismatch"); return ERROR_FAIL; } if (cmd_saved != osbdm->buffer[0]) { LOG_ERROR("OSBDM communication error: reply command mismatch"); return ERROR_FAIL; } return ERROR_OK; }