#include "config.h"
#endif
+#include <helper/system.h>
#include <libusb.h>
#include <helper/log.h>
+#include <helper/replacements.h>
#include "cmsis_dap.h"
struct cmsis_dap_backend_data {
- libusb_context *usb_ctx;
- libusb_device_handle *dev_handle;
+ struct libusb_context *usb_ctx;
+ struct libusb_device_handle *dev_handle;
unsigned int ep_out;
unsigned int ep_in;
int interface;
static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t pids[], char *serial)
{
int err;
- libusb_context *ctx;
- libusb_device **device_list;
+ struct libusb_context *ctx;
+ struct libusb_device **device_list;
err = libusb_init(&ctx);
if (err) {
}
for (int i = 0; i < num_devices; i++) {
- libusb_device *dev = device_list[i];
+ struct libusb_device *dev = device_list[i];
struct libusb_device_descriptor dev_desc;
err = libusb_get_device_descriptor(dev, &dev_desc);
if (dev_desc.iSerialNumber == 0 && serial && serial[0])
continue;
- libusb_device_handle *dev_handle = NULL;
+ struct libusb_device_handle *dev_handle = NULL;
err = libusb_open(dev, &dev_handle);
if (err) {
/* It's to be expected that most USB devices can't be opened
}
dap->packet_size = packet_size;
- dap->packet_buffer_size = packet_size + REPORT_ID_SIZE;
+ dap->packet_buffer_size = packet_size;
dap->bdata->usb_ctx = ctx;
dap->bdata->dev_handle = dev_handle;
dap->bdata->ep_out = ep_out;
return ERROR_FAIL;
}
+ dap->command = dap->packet_buffer;
+ dap->response = dap->packet_buffer;
+
return ERROR_OK;
}
/* skip the first byte that is only used by the HID backend */
err = libusb_bulk_transfer(dap->bdata->dev_handle, dap->bdata->ep_out,
- dap->packet_buffer + REPORT_ID_SIZE, txlen - REPORT_ID_SIZE, &transferred, timeout_ms);
+ dap->packet_buffer, txlen, &transferred, timeout_ms);
if (err) {
if (err == LIBUSB_ERROR_TIMEOUT) {
return ERROR_TIMEOUT_REACHED;
static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
{
- unsigned int packet_buffer_size = pkt_sz + REPORT_ID_SIZE;
- uint8_t *buf = malloc(packet_buffer_size);
+ uint8_t *buf = malloc(pkt_sz);
if (buf == NULL) {
LOG_ERROR("unable to allocate CMSIS-DAP packet buffer");
return ERROR_FAIL;
dap->packet_buffer = buf;
dap->packet_size = pkt_sz;
- dap->packet_buffer_size = packet_buffer_size;
+ dap->packet_buffer_size = pkt_sz;
+
+ dap->command = dap->packet_buffer;
+ dap->response = dap->packet_buffer;
return ERROR_OK;
}