Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
static int ublast2_libusb_write(struct ublast_lowlevel *low, uint8_t *buf,
			       int size, uint32_t *bytes_written)
{
	*bytes_written = jtag_libusb_bulk_write(low->libusb_dev,
						USBBLASTER_EPOUT | \
						LIBUSB_ENDPOINT_OUT,
						(char *)buf,
						size,
						100);
	return ERROR_OK;
}
Exemplo n.º 4
0
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;
}