Problems reading large packets with USBHost::inTransfer

Hi,

When reading large 512 byte USB packets using USBHost:inTransfer, no data seems to be written to the data buffer. The function reports the number of bytes read (as the passed data buffer size), but doesn't actually copy the bytes (verified by initialising the data buffer and checking its content after the call).

Not sure if I'm doing something wrong (eg. in the endpoint configuration) or if this is a bug. Any ideas on how to make progress with this?

I'm using Arduino 1.5.2 with an Arduino Due.

Hugo

Any ideas on how to make progress with this?

Besides posting code?
Probably not.

The code is a version of the Arduino camera control library modified to work with usbhost Pulling out the relevant bits, it looks like this:

#define PTP_MAX_RX_BUFFER_LEN   512
#define PTP_MAX_RX_DATA_LEN (PTP_MAX_RX_BUFFER_LEN - PTP_USB_BULK_HDR_LEN)
typedef struct
{
  uint32_t len;
  uint16_t con_type;
  uint16_t opcode;
  uint32_t transaction_id;
  uint8_t data[PTP_MAX_RX_DATA_LEN];
} PTP_DATA_CONTAINER;

  PTP_DATA_CONTAINER data;
  ZeroMemory(sizeof(data), &data);
  uint32_t nbytes = sizeof(data);

  // nbytes is 512, and data is all zeros

  uint32_t rcode = usb->inTransfer(devAddress, epDataIn, &nbytes, (uint8_t*)&data);

  // rcode is zero
  // nbytes is 512, and data is all zeros

No, sorry, that doesn't compile.

I'm having a hard time working out how I can repro this without the USB peripheral I'm using (a canon EOS camera), and putting the whole library code up on github.

I'm guessing that plugging the programming usb into the native usb might allow for a repro case, but I'm not sure how to get any results out in that case.

Excuse my lack of familiarity with the possibilities for this sort of thing - day two with the arduino here.

Turns out this is a bug in the Atmel SAM library. In UHD_Pipe_Read, nb_byte_received is declared uint8_t, whereas it needs to be at least uint16_t. If I recompile the system library using this, then everything works as expected.